Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ignore claims behind last observed nonce #1291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading