Skip to content

Commit

Permalink
chore: ignore claims behind last observed nonce
Browse files Browse the repository at this point in the history
If we ever reset the latest skyway nonce ahead of any observed claim, we
don't need nor want pigeons trying to attest to them. So, we can filter
claims that are behind the latest attested claim.
  • Loading branch information
maharifu committed Sep 13, 2024
1 parent d8f2f56 commit b052b1e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
13 changes: 12 additions & 1 deletion x/skyway/keeper/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,11 @@ func (k Keeper) UnobservedBlocksByAddr(
) ([]uint64, error) {
lastCompassID := k.GetLatestCompassID(ctx, chainReferenceID)

var err error
lastObservedNonce, err := k.GetLastObservedSkywayNonce(ctx, chainReferenceID)
if err != nil {
return nil, err
}

var blocks []uint64

iterErr := k.IterateAttestations(ctx, chainReferenceID, false, func(_ []byte, att types.Attestation) bool {
Expand All @@ -602,6 +606,13 @@ func (k Keeper) UnobservedBlocksByAddr(
return false
}

// If we ever reset the latest skyway nonce ahead of any observed claim,
// we don't need nor want pigeons trying to attest to them. So, we can
// filter claims that are behind the latest attested claim.
if claim.GetSkywayNonce() <= lastObservedNonce {
return false
}

blocks = append(blocks, claim.GetEthBlockHeight())

return false
Expand Down
35 changes: 33 additions & 2 deletions x/skyway/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func TestGetUnobservedBlocksByAddr(t *testing.T) {
expected: nil,
},
{
name: "unobserved message already signed by validator",
name: "unobserved messages already signed by validator",
setup: func(ctx context.Context, k Keeper) {
sdkCtx := sdktypes.UnwrapSDKContext(ctx)

Expand All @@ -625,7 +625,7 @@ func TestGetUnobservedBlocksByAddr(t *testing.T) {
require.NoError(t, err)

att := &types.Attestation{
Observed: true,
Observed: false,
Votes: []string{address},
Height: uint64(sdkCtx.BlockHeight()),
Claim: claim,
Expand All @@ -636,6 +636,37 @@ func TestGetUnobservedBlocksByAddr(t *testing.T) {
},
expected: nil,
},
{
name: "unobserved messages behind last observed nonce",
setup: func(ctx context.Context, k Keeper) {
sdkCtx := sdktypes.UnwrapSDKContext(ctx)

err := k.setLastObservedSkywayNonce(ctx, chainReferenceID, 2)
require.NoError(t, err)

for i := 0; i < 3; i++ {
msg := types.MsgLightNodeSaleClaim{
SkywayNonce: uint64(i + 1),
EthBlockHeight: uint64(i + 1),
}
claim, err := codectypes.NewAnyWithValue(&msg)
require.NoError(t, err)

hash, err := msg.ClaimHash()
require.NoError(t, err)

att := &types.Attestation{
Observed: false,
Votes: []string{},
Height: uint64(sdkCtx.BlockHeight()),
Claim: claim,
}

k.SetAttestation(ctx, chainReferenceID, uint64(i+1), hash, att)
}
},
expected: []uint64{3},
},
{
name: "unobserved messages for current and porevious compass",
setup: func(ctx context.Context, k Keeper) {
Expand Down

0 comments on commit b052b1e

Please sign in to comment.