Skip to content

Commit

Permalink
Fix sequential event nonce check
Browse files Browse the repository at this point in the history
This sneaky inline error caused the attestation to be processed based on
the correct validator address but the event nonce lookup was processed
on the delegate address instead of the validator address.

This didn't matter in the tests becuase events are submitted in batches
and we simply never ended up in a desync situation.

We should carefully inspect the codebase for more casts like this.
  • Loading branch information
jkilpatr committed Feb 13, 2021
1 parent bdaa93b commit bc1076a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions module/x/peggy/keeper/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (

// TODO-JT: carefully look at atomicity of this function
func (k Keeper) Attest(ctx sdk.Context, claim types.EthereumClaim, anyClaim *codectypes.Any) (*types.Attestation, error) {
valAddr := k.GetOrchestratorValidator(ctx, claim.GetClaimer())
if valAddr == nil {
panic("Could not find ValAddr for delegate key, should be checked by now")
}
// Check that the nonce of this event is exactly one higher than the last nonce stored by this validator.
// We check the event nonce in processAttestation as well, but checking it here gives individual eth signers a chance to retry,
// and prevents validators from submitting two claims with the same nonce
lastEventNonce := k.GetLastEventNonceByValidator(ctx, sdk.ValAddress(claim.GetClaimer()))
lastEventNonce := k.GetLastEventNonceByValidator(ctx, valAddr)
if claim.GetEventNonce() != lastEventNonce+1 {
return nil, types.ErrNonContiguousEventNonce
}
valAddr := k.GetOrchestratorValidator(ctx, claim.GetClaimer())
if valAddr == nil {
panic("Could not find ValAddr for delegate key, should be checked by now")
}

// Tries to get an attestation with the same eventNonce and claim as the claim that was submitted.
att := k.GetAttestation(ctx, claim.GetEventNonce(), claim.ClaimHash())
Expand Down

0 comments on commit bc1076a

Please sign in to comment.