Skip to content

Commit 36e5c9d

Browse files
authored
fix(block): validate block after applying instead of before during sync (#2579)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview We validate after during execution, but before during syncing, but the signature verifier provided by ev-abci needs some data that is saved after applying. <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> -->
1 parent 1d286d1 commit 36e5c9d

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

block/sync.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,17 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
149149
// set the custom verifier to ensure proper signature validation
150150
h.SetCustomVerifier(m.signaturePayloadProvider)
151151

152-
// validate the received block before applying
153-
if err := m.Validate(ctx, h, d); err != nil {
154-
return fmt.Errorf("failed to validate block: %w", err)
155-
}
156-
157152
newState, err := m.applyBlock(ctx, h.Header, d)
158153
if err != nil {
159154
return fmt.Errorf("failed to apply block: %w", err)
160155
}
161156

157+
// validate the received block after applying
158+
// a custom verification function can depend on the state of the blockchain
159+
if err := m.Validate(ctx, h, d); err != nil {
160+
return fmt.Errorf("failed to validate block: %w", err)
161+
}
162+
162163
if err = m.updateState(ctx, newState); err != nil {
163164
return fmt.Errorf("failed to save updated state: %w", err)
164165
}

0 commit comments

Comments
 (0)