Skip to content

Commit

Permalink
chore: apply code rabbit comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Jan 20, 2025
1 parent e84e0be commit af79697
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,13 @@ func (app *Application) FinalizeSnapshot(_ctx context.Context, req *abci.Request

// we verify snapshot height and app hash, as there is no additional logic to be called here
if app.LastCommittedState.GetHeight() != req.LightBlock.SignedHeader.Header.Height {
return &abci.ResponseFinalizeSnapshot{}, fmt.Errorf("snapshot height mismatch")
return &abci.ResponseFinalizeSnapshot{}, fmt.Errorf("snapshot height mismatch: expected %d, got %d",
app.LastCommittedState.GetHeight(), req.LightBlock.SignedHeader.Header.Height)
}

if !app.LastCommittedState.GetAppHash().Equal(req.LightBlock.SignedHeader.Header.AppHash) {
return &abci.ResponseFinalizeSnapshot{}, fmt.Errorf("snapshot apphash mismatch")
return &abci.ResponseFinalizeSnapshot{}, fmt.Errorf("snapshot apphash mismatch: expected %x, got %x",
app.LastCommittedState.GetAppHash(), req.LightBlock.SignedHeader.Header.AppHash)
}

app.logger.Debug("FinalizeSnapshot finished successfully", "req", req)
Expand Down
1 change: 1 addition & 0 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (BaseApplication) ApplySnapshotChunk(_ context.Context, _req *RequestApplyS
return &ResponseApplySnapshotChunk{}, nil
}

// FinalizeSnapshot provides a no-op implementation for the StateSyncer interface
func (BaseApplication) FinalizeSnapshot(_ context.Context, _req *RequestFinalizeSnapshot) (*ResponseFinalizeSnapshot, error) {
return &ResponseFinalizeSnapshot{}, nil
}
Expand Down
10 changes: 7 additions & 3 deletions abci/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,13 @@ message RequestApplySnapshotChunk {
bytes chunk = 2; // The binary chunk contents, as returned by LoadSnapshotChunk.
string sender = 3; // The P2P ID of the node who sent this chunk.
}

// After snapshot sync, Tenderdash calls this to finalize the snapshot sync.
// It includes the light block committed at the synced height, which Tenderdash uses
// to reconstruct its own state.
// RequestFinalizeSnapshot is called by Tenderdash after successfully applying all snapshot chunks, eg.
// when the ABCI application returned `ResponseApplySnapshotChunk` with `Result = ACCEPT`.
// It includes the light block committed at the synced height, which Tenderdash uses to reconstruct its own state.
// The application should validate the light block against its restored state.
//
// If the application fails to validate the light block, it should return error in the response.
// This is considered fatal, non-recoverable consensus failure and will cause Tenderdash to restart.
message RequestFinalizeSnapshot {
// light block committed at the synced height
tendermint.types.LightBlock light_block = 1;
Expand Down
10 changes: 7 additions & 3 deletions spec/abci++/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,13 @@ Finalize newly decided block.
<a name="tendermint-abci-RequestFinalizeSnapshot"></a>

### RequestFinalizeSnapshot
After snapshot sync, Tenderdash calls this to finalize the snapshot sync.
It includes the light block committed at the synced height, which Tenderdash uses
to reconstruct its own state.
RequestFinalizeSnapshot is called by Tenderdash after successfully applying all snapshot chunks, eg.
when the ABCI application returned `ResponseApplySnapshotChunk` with `Result = ACCEPT`.
It includes the light block committed at the synced height, which Tenderdash uses to reconstruct its own state.
The application should validate the light block against its restored state.

If the application fails to validate the light block, it should return error in the response.
This is considered fatal, non-recoverable consensus failure and will cause Tenderdash to restart.


| Field | Type | Label | Description |
Expand Down

0 comments on commit af79697

Please sign in to comment.