Skip to content

Commit

Permalink
chore: review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Jun 26, 2024
1 parent bfa1d34 commit dea1133
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
8 changes: 4 additions & 4 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ type SharedQueryClient interface {
// GetClaimWindowOpenHeight returns the block height at which the claim window of
// the session that includes queryHeight opens.
GetClaimWindowOpenHeight(ctx context.Context, queryHeight int64) (int64, error)
// GetEarliestClaimCommitHeight returns the earliest block height at which a claim
// GetEarliestSupplierClaimCommitHeight returns the earliest block height at which a claim
// for the session that includes queryHeight can be committed for a given supplier.
GetEarliestClaimCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error)
GetEarliestSupplierClaimCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error)
// GetProofWindowOpenHeight returns the block height at which the proof window of
// the session that includes queryHeight opens.
GetProofWindowOpenHeight(ctx context.Context, queryHeight int64) (int64, error)
// GetEarliestProofCommitHeight returns the earliest block height at which a proof
// GetEarliestSupplierProofCommitHeight returns the earliest block height at which a proof
// for the session that includes queryHeight can be committed for a given supplier.
GetEarliestProofCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error)
GetEarliestSupplierProofCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error)
}

// BlockQueryClient defines an interface that enables the querying of
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/query/sharedquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (sq *sharedQuerier) GetSessionGracePeriodEndHeight(
// to get the most recently (asynchronously) observed (and cached) value.
// TODO_BLOCKER(@bryanchriswhite, #543): We also don't really want to use the current value of the params.
// Instead, we should be using the value that the params had for the session which includes queryHeight.
func (sq *sharedQuerier) GetEarliestClaimCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error) {
func (sq *sharedQuerier) GetEarliestSupplierClaimCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error) {
sharedParams, err := sq.GetParams(ctx)
if err != nil {
return 0, err
Expand All @@ -134,7 +134,7 @@ func (sq *sharedQuerier) GetEarliestClaimCommitHeight(ctx context.Context, query
// NB: Byte slice representation of block hashes don't need to be normalized.
claimWindowOpenBlockHash := claimWindowOpenBlock.BlockID.Hash.Bytes()

return shared.GetEarliestClaimCommitHeight(
return shared.GetEarliestSupplierClaimCommitHeight(
sharedParams,
queryHeight,
claimWindowOpenBlockHash,
Expand All @@ -150,7 +150,7 @@ func (sq *sharedQuerier) GetEarliestClaimCommitHeight(ctx context.Context, query
// to get the most recently (asynchronously) observed (and cached) value.
// TODO_BLOCKER(@bryanchriswhite, #543): We also don't really want to use the current value of the params.
// Instead, we should be using the value that the params had for the session which includes queryHeight.
func (sq *sharedQuerier) GetEarliestProofCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error) {
func (sq *sharedQuerier) GetEarliestSupplierProofCommitHeight(ctx context.Context, queryHeight int64, supplierAddr string) (int64, error) {
sharedParams, err := sq.GetParams(ctx)
if err != nil {
return 0, err
Expand All @@ -164,7 +164,7 @@ func (sq *sharedQuerier) GetEarliestProofCommitHeight(ctx context.Context, query
return 0, err
}

return shared.GetEarliestProofCommitHeight(
return shared.GetEarliestSupplierProofCommitHeight(
sharedParams,
queryHeight,
proofWindowOpenBlock.BlockID.Hash,
Expand Down
2 changes: 1 addition & 1 deletion pkg/relayer/session/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (rs *relayerSessionsManager) waitForEarliestCreateClaimsHeight(

// Get the earliestClaimsCommitHeight.
supplierAddr := sessionTrees[0].GetSupplierAddress().String()
earliestClaimsCommitHeight, err := rs.sharedQueryClient.GetEarliestClaimCommitHeight(ctx, sessionEndHeight, supplierAddr)
earliestClaimsCommitHeight, err := rs.sharedQueryClient.GetEarliestSupplierClaimCommitHeight(ctx, sessionEndHeight, supplierAddr)
if err != nil {
failedCreateClaimsSessionsCh <- sessionTrees
return nil
Expand Down
7 changes: 3 additions & 4 deletions pkg/relayer/session/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ func (rs *relayerSessionsManager) waitForEarliestSubmitProofsHeightAndGeneratePr
logger = logger.With("proof_window_open_height", proofWindowOpenHeight)
logger.Info().Msg("waiting & blocking for proof path seed block height")

// proofPathSeedBlock is the block that will have its hash used as the
// proofWindowOpenHeight - 1 is the block that will have its hash used as the
// source of entropy for all the session trees in that batch, waiting for it to
// be received before proceeding.
proofPathSeedBlockHeight := shared.GetSessionGracePeriodEndHeight(sharedParams, sessionEndHeight)
proofPathSeedBlock := rs.waitForBlock(ctx, proofPathSeedBlockHeight)
proofPathSeedBlock := rs.waitForBlock(ctx, proofWindowOpenHeight-1)
_ = rs.waitForBlock(ctx, proofWindowOpenHeight)

logger = logger.With("proof_path_bock_hash", fmt.Sprintf("%x", proofPathSeedBlock.Hash()))
Expand All @@ -123,7 +122,7 @@ func (rs *relayerSessionsManager) waitForEarliestSubmitProofsHeightAndGeneratePr

// Get the earliestProofsCommitHeight.
supplierAddr := sessionTrees[0].GetSupplierAddress()
earliestProofsCommitHeight, err := rs.sharedQueryClient.GetEarliestProofCommitHeight(ctx, sessionEndHeight, supplierAddr.String())
earliestProofsCommitHeight, err := rs.sharedQueryClient.GetEarliestSupplierProofCommitHeight(ctx, sessionEndHeight, supplierAddr.String())
if err != nil {
failedSubmitProofsSessionsCh <- sessionTrees
return nil
Expand Down
12 changes: 8 additions & 4 deletions x/proof/keeper/msg_server_submit_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,21 @@ func (k msgServer) validateClosestPath(
//
// Since smt.ProveClosest is defined in terms of submitProofWindowStartHeight,
// this block's hash needs to be used for validation too.
sessionGracePeriodEndHeight, err := k.sharedQuerier.GetSessionGracePeriodEndHeight(ctx, sessionHeader.GetSessionEndBlockHeight())
proofWindowOpenHeight, err := k.sharedQuerier.GetProofWindowOpenHeight(ctx, sessionHeader.GetSessionEndBlockHeight())
if err != nil {
return err
}
blockHash := k.sessionKeeper.GetBlockHash(ctx, sessionGracePeriodEndHeight)

// proofWindowOpenHeight - 1 is the block that will have its hash used as the
// source of entropy for all the session trees in that batch, waiting for it to
// be received before proceeding.
proofPathSeedBlockHash := k.sessionKeeper.GetBlockHash(ctx, proofWindowOpenHeight-1)

// TODO_BETA: Investigate "proof for the path provided does not match one expected by the on-chain protocol"
// error that may occur due to block height differing from the off-chain part.
fmt.Println("E2E_DEBUG: height for block hash when verifying the proof", sessionGracePeriodEndHeight, sessionHeader.GetSessionId())
k.logger.Info("E2E_DEBUG: height for block hash when verifying the proof", proofWindowOpenHeight, sessionHeader.GetSessionId())

expectedProofPath := GetPathForProof(blockHash, sessionHeader.GetSessionId())
expectedProofPath := GetPathForProof(proofPathSeedBlockHash, sessionHeader.GetSessionId())
if !bytes.Equal(proof.Path, expectedProofPath) {
return types.ErrProofInvalidProof.Wrapf(
"the proof for the path provided (%x) does not match one expected by the on-chain protocol (%x)",
Expand Down
12 changes: 6 additions & 6 deletions x/proof/types/shared_query_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func (sqc *SharedKeeperQueryClient) GetProofWindowOpenHeight(
return shared.GetProofWindowOpenHeight(&sharedParams, queryHeight), nil
}

// GetEarliestClaimCommitHeight returns the earliest block height at which a claim
// GetEarliestSupplierClaimCommitHeight returns the earliest block height at which a claim
// for the session that includes queryHeight can be committed for a given supplier.
func (sqc *SharedKeeperQueryClient) GetEarliestClaimCommitHeight(
func (sqc *SharedKeeperQueryClient) GetEarliestSupplierClaimCommitHeight(
ctx context.Context,
queryHeight int64,
supplierAddr string,
Expand All @@ -93,17 +93,17 @@ func (sqc *SharedKeeperQueryClient) GetEarliestClaimCommitHeight(
claimWindowOpenBlockHashBz := sqc.sessionKeeper.GetBlockHash(ctx, claimWindowOpenHeight)

// Get the earliest claim commit height for the given supplier.
return shared.GetEarliestClaimCommitHeight(
return shared.GetEarliestSupplierClaimCommitHeight(
&sharedParams,
queryHeight,
claimWindowOpenBlockHashBz,
supplierAddr,
), nil
}

// GetEarliestProofCommitHeight returns the earliest block height at which a proof
// GetEarliestSupplierProofCommitHeight returns the earliest block height at which a proof
// for the session that includes queryHeight can be committed for a given supplier.
func (sqc *SharedKeeperQueryClient) GetEarliestProofCommitHeight(
func (sqc *SharedKeeperQueryClient) GetEarliestSupplierProofCommitHeight(
ctx context.Context,
queryHeight int64,
supplierAddr string,
Expand All @@ -117,7 +117,7 @@ func (sqc *SharedKeeperQueryClient) GetEarliestProofCommitHeight(
proofWindowOpenBlockHash := sqc.sessionKeeper.GetBlockHash(ctx, proofWindowOpenHeight)

// Get the earliest proof commit height for the given supplier.
return shared.GetEarliestProofCommitHeight(
return shared.GetEarliestSupplierProofCommitHeight(
&sharedParams,
queryHeight,
proofWindowOpenBlockHash,
Expand Down
8 changes: 4 additions & 4 deletions x/shared/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func GetProofWindowCloseHeight(sharedParams *sharedtypes.Params, queryHeight int
int64(sharedParams.GetProofWindowCloseOffsetBlocks())
}

// GetEarliestClaimCommitHeight returns the earliest block height at which a claim
// GetEarliestSupplierClaimCommitHeight returns the earliest block height at which a claim
// for the session that includes queryHeight can be committed for a given supplier
// and the passed sharedParams.
func GetEarliestClaimCommitHeight(
func GetEarliestSupplierClaimCommitHeight(
sharedParams *sharedtypes.Params,
queryHeight int64,
claimWindowOpenBlockHash []byte,
Expand Down Expand Up @@ -148,10 +148,10 @@ func GetClaimWindowSizeBlocks(sharedParams *sharedtypes.Params) uint64 {
return windowSizeBlocks
}

// GetEarliestProofCommitHeight returns the earliest block height at which a proof
// GetEarliestSupplierProofCommitHeight returns the earliest block height at which a proof
// for the session that includes queryHeight can be committed for a given supplier
// and the passed sharedParams.
func GetEarliestProofCommitHeight(
func GetEarliestSupplierProofCommitHeight(
sharedParams *sharedtypes.Params,
queryHeight int64,
proofWindowOpenBlockHash []byte,
Expand Down
8 changes: 4 additions & 4 deletions x/shared/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGetEarliestClaimCommitHeight_IsDeterministic(t *testing.T) {
)

test := func() int64 {
return GetEarliestClaimCommitHeight(
return GetEarliestSupplierClaimCommitHeight(
&sharedParams,
queryHeight,
claimWindowOpenBlockHash[:],
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestGetEarliestProofCommitHeight_IsDeterministic(t *testing.T) {
)

test := func() int64 {
return GetEarliestProofCommitHeight(
return GetEarliestSupplierProofCommitHeight(
&sharedParams,
queryHeight,
proofWindowOpenBlockHash[:],
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestClaimProofWindows(t *testing.T) {
require.GreaterOrEqual(t, proofWindowOpenHeight, claimWindowCloseHeight)
require.Greater(t, proofWindowCloseHeight, proofWindowOpenHeight)

earliestClaimCommitHeight := GetEarliestClaimCommitHeight(
earliestClaimCommitHeight := GetEarliestSupplierClaimCommitHeight(
&test.sharedParams,
test.queryHeight,
blockHash,
Expand All @@ -136,7 +136,7 @@ func TestClaimProofWindows(t *testing.T) {

require.Greater(t, claimWindowCloseHeight, earliestClaimCommitHeight)

earliestProofCommitHeight := GetEarliestProofCommitHeight(
earliestProofCommitHeight := GetEarliestSupplierProofCommitHeight(
&test.sharedParams,
test.queryHeight,
blockHash,
Expand Down

0 comments on commit dea1133

Please sign in to comment.