Skip to content

Commit

Permalink
Compare types.proto and feature/abci++vef and tip of v0.36.x (c…
Browse files Browse the repository at this point in the history
…ometbft#488)

* CometBFT renaming in types.proto

* AppHash

* Make proto-gen

* Trying 1.20.2 explicitly
  • Loading branch information
sergio-mena authored Mar 13, 2023
1 parent df0a4b7 commit d131ab7
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.20"
go-version: "1.20.2"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This guide provides instructions for upgrading to specific versions of CometBFT.
* The Application's hash (or any data representing the Application's current state)
is known by the time `FinalizeBlock` finishes its execution.
Accordingly, the `app_hash` parameter has been moved from `ResponseCommit`
to `ResponseFinalizeBlock`, and renamed `agreed_app_data`.
to `ResponseFinalizeBlock`.
* For details, please see the updated [specification](spec/abci/README.md)


Expand Down
2 changes: 1 addition & 1 deletion abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func cmdFinalizeBlock(cmd *cobra.Command, args []string) error {
})
}
resps = append(resps, response{
Data: res.AgreedAppData,
Data: res.AppHash,
})
printResponse(cmd, args, resps...)
return nil
Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (app *Application) FinalizeBlock(_ context.Context, req *types.RequestFinal

app.state.Height = req.Height

return &types.ResponseFinalizeBlock{TxResults: respTxs, ValidatorUpdates: app.valUpdates, AgreedAppData: app.state.Hash()}, nil
return &types.ResponseFinalizeBlock{TxResults: respTxs, ValidatorUpdates: app.valUpdates, AppHash: app.state.Hash()}, nil
}

// Commit is called after FinalizeBlock and after Tendermint state which includes the updates to
Expand Down Expand Up @@ -459,7 +459,7 @@ func saveState(state State) {
// as the size or number of transactions processed within the state. Note that this isn't
// a strong guarantee of state machine replication because states could
// have different kv values but still have the same size.
// This function is used as the "AgreedAppData"
// This function is used as the "AppHash"
func (s State) Hash() []byte {
appHash := make([]byte, 8)
binary.PutVarint(appHash, s.Size)
Expand Down
2 changes: 1 addition & 1 deletion abci/tests/server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Commit(ctx context.Context, client abcicli.Client) error {

func FinalizeBlock(ctx context.Context, client abcicli.Client, txBytes [][]byte, codeExp []uint32, dataExp []byte, hashExp []byte) error {
res, _ := client.FinalizeBlock(ctx, &types.RequestFinalizeBlock{Txs: txBytes})
appHash := res.AgreedAppData
appHash := res.AppHash
for i, tx := range res.TxResults {
code, data, log := tx.Code, tx.Data, tx.Log
if code != codeExp[i] {
Expand Down
423 changes: 211 additions & 212 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestMempoolRmBadTx(t *testing.T) {
res, err := app.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{Txs: [][]byte{txBytes}})
require.NoError(t, err)
assert.False(t, res.TxResults[0].IsErr())
assert.True(t, len(res.AgreedAppData) > 0)
assert.True(t, len(res.AppHash) > 0)

_, err = app.Commit(context.Background(), &abci.RequestCommit{})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ func (h *Handshaker) ReplayBlocks(
// v0.37 with endblock to v0.38 with finalize block and thus
// does not have the app hash saved from the previous height
// here we take the appHash provided from the Info handshake
if len(finalizeBlockResponse.AgreedAppData) == 0 {
finalizeBlockResponse.AgreedAppData = appHash
if len(finalizeBlockResponse.AppHash) == 0 {
finalizeBlockResponse.AppHash = appHash
}
mockApp := newMockProxyApp(finalizeBlockResponse)
h.logger.Info("Replay last block using mock app")
Expand Down
6 changes: 3 additions & 3 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ func (app *badApp) FinalizeBlock(_ context.Context, req *abci.RequestFinalizeBlo
app.height++
if app.onlyLastHashIsWrong {
if app.height == app.numBlocks {
return &abci.ResponseFinalizeBlock{AgreedAppData: cmtrand.Bytes(8)}, nil
return &abci.ResponseFinalizeBlock{AppHash: cmtrand.Bytes(8)}, nil
}
return &abci.ResponseFinalizeBlock{AgreedAppData: []byte{app.height}}, nil
return &abci.ResponseFinalizeBlock{AppHash: []byte{app.height}}, nil
} else if app.allHashesAreWrong {
return &abci.ResponseFinalizeBlock{AgreedAppData: cmtrand.Bytes(8)}, nil
return &abci.ResponseFinalizeBlock{AppHash: cmtrand.Bytes(8)}, nil
}

panic("either allHashesAreWrong or onlyLastHashIsWrong must be set")
Expand Down
2 changes: 1 addition & 1 deletion consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ func TestFinalizeBlockCalled(t *testing.T) {
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
}, nil)
}
r := &abci.ResponseFinalizeBlock{AgreedAppData: []byte("the_hash")}
r := &abci.ResponseFinalizeBlock{AppHash: []byte("the_hash")}
m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(r, nil).Maybe()
m.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe()

Expand Down
6 changes: 3 additions & 3 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ func TestSerialReap(t *testing.T) {
txResult.Code, txResult.Data, txResult.Log)
}
}
if len(res.AgreedAppData) != 8 {
t.Errorf("error committing. Hash:%X", res.AgreedAppData)
if len(res.AppHash) != 8 {
t.Errorf("error committing. Hash:%X", res.AppHash)
}

_, err = appConnCon.Commit(context.Background(), &abci.RequestCommit{})
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestMempoolTxsBytes(t *testing.T) {
res, err := appConnCon.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{Txs: [][]byte{txBytes}})
require.NoError(t, err)
require.EqualValues(t, 0, res.TxResults[0].Code)
require.NotEmpty(t, res.AgreedAppData)
require.NotEmpty(t, res.AppHash)

_, err = appConnCon.Commit(context.Background(), &abci.RequestCommit{})
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ message ResponseVerifyVoteExtension {
ACCEPT = 1;
// Rejecting the vote extension will reject the entire precommit by the sender.
// Incorrectly implementing this thus has liveness implications as it may affect
// tendermint's ability to receive 2/3+ valid votes to finalize the block.
// CometBFT's ability to receive 2/3+ valid votes to finalize the block.
// Honest nodes should never be rejected.
REJECT = 2;
}
Expand All @@ -352,8 +352,8 @@ message ResponseFinalizeBlock {
repeated ValidatorUpdate validator_updates = 3 [(gogoproto.nullable) = false];
// updates to the consensus params, if any.
tendermint.types.ConsensusParams consensus_param_updates = 4;
// agreed_app_data is the bytes that all nodes reach consensus upon in the following height. It is often the hash of the applications' state which can be used to confirm that execution of the transactions was deterministic.
bytes agreed_app_data = 5;
// app_hash is the hash of the applications' state which is used to confirm that execution of the transactions was deterministic. It is up to the application to decide which algorithm to use.
bytes app_hash = 5;
}

//----------------------------------------
Expand All @@ -365,7 +365,7 @@ message CommitInfo {
}

// ExtendedCommitInfo is similar to CommitInfo except that it is only used in
// the PrepareProposal request such that Tendermint can provide vote extensions
// the PrepareProposal request such that CometBFT can provide vote extensions
// to the application.
message ExtendedCommitInfo {
// The round at which the block proposer decided in the previous height.
Expand Down
2 changes: 1 addition & 1 deletion rpc/core/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ResultBlockResults struct {
FinalizeBlockEvents []abci.Event `json:"finalize_block_events"`
ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"`
ConsensusParamUpdates *cmtproto.ConsensusParams `json:"consensus_param_updates"`
AgreedAppData []byte `json:"agreed_app_data"`
AppHash []byte `json:"app_hash"`
}

// NewResultCommit is a helper to initialize the ResultCommit with
Expand Down
10 changes: 5 additions & 5 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ func (blockExec *BlockExecutor) ApplyBlock(
"height", block.Height,
"num_txs_res", len(abciResponse.TxResults),
"num_val_updates", len(abciResponse.ValidatorUpdates),
"block_app_hash", fmt.Sprintf("%X", abciResponse.AgreedAppData),
"block_app_hash", fmt.Sprintf("%X", abciResponse.AppHash),
)

// Assert that the application correctly returned tx results for each of the transactions provided in the block
if len(block.Data.Txs) != len(abciResponse.TxResults) {
return state, fmt.Errorf("expected tx results length to match size of transactions in block. Expected %d, got %d", len(block.Data.Txs), len(abciResponse.TxResults))
}

blockExec.logger.Info("executed block", "height", block.Height, "agreed_app_data", abciResponse.AgreedAppData)
blockExec.logger.Info("executed block", "height", block.Height, "app_hash", abciResponse.AppHash)

fail.Fail() // XXX

Expand Down Expand Up @@ -278,7 +278,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
fail.Fail() // XXX

// Update the app hash and save the state.
state.AppHash = abciResponse.AgreedAppData
state.AppHash = abciResponse.AppHash
if err := blockExec.store.Save(state); err != nil {
return state, err
}
Expand Down Expand Up @@ -694,7 +694,7 @@ func ExecCommitBlock(
return nil, fmt.Errorf("expected tx results length to match size of transactions in block. Expected %d, got %d", len(block.Data.Txs), len(resp.TxResults))
}

logger.Info("executed block", "height", block.Height, "agreed_app_data", resp.AgreedAppData)
logger.Info("executed block", "height", block.Height, "app_hash", resp.AppHash)

// Commit block
_, err = appConnConsensus.Commit(context.TODO())
Expand All @@ -704,7 +704,7 @@ func ExecCommitBlock(
}

// ResponseCommit has no error or log
return resp.AgreedAppData, nil
return resp.AppHash, nil
}

func (blockExec *BlockExecutor) pruneBlocks(retainHeight int64, state State) (uint64, error) {
Expand Down
6 changes: 3 additions & 3 deletions state/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ type testApp struct {
CommitVotes []abci.VoteInfo
Misbehavior []abci.Misbehavior
ValidatorUpdates []abci.ValidatorUpdate
AgreedAppData []byte
AppHash []byte
}

var _ abci.Application = (*testApp)(nil)
Expand All @@ -265,8 +265,8 @@ func (app *testApp) FinalizeBlock(_ context.Context, req *abci.RequestFinalizeBl
App: 1,
},
},
TxResults: txResults,
AgreedAppData: app.AgreedAppData,
TxResults: txResults,
AppHash: app.AppHash,
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func TestFinalizeBlockResponsesSaveLoad2(t *testing.T) {
for i, tc := range cases {
h := int64(i + 1) // last block height, one below what we save
responses := &abci.ResponseFinalizeBlock{
TxResults: tc.added,
AgreedAppData: []byte(fmt.Sprintf("%d", h)),
TxResults: tc.added,
AppHash: []byte(fmt.Sprintf("%d", h)),
}
err := stateStore.SaveFinalizeBlockResponse(h, responses)
require.NoError(t, err)
Expand All @@ -206,8 +206,8 @@ func TestFinalizeBlockResponsesSaveLoad2(t *testing.T) {
if assert.NoError(err, "%d", i) {
t.Log(res)
responses := &abci.ResponseFinalizeBlock{
TxResults: tc.expected,
AgreedAppData: []byte(fmt.Sprintf("%d", h)),
TxResults: tc.expected,
AppHash: []byte(fmt.Sprintf("%d", h)),
}
assert.Equal(sm.TxResultsHash(responses.TxResults), sm.TxResultsHash(res.TxResults), "%d", i)
}
Expand Down
6 changes: 3 additions & 3 deletions state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (store dbStore) LoadFinalizeBlockResponse(height int64) (*abci.ResponseFina
}
// The state store contains the old format. Migrate to
// the new ResponseFinalizeBlock format. Note that the
// new struct expects the AgreedAppData which we don't have.
// new struct expects the AppHash which we don't have.
return responseFinalizeBlockFromLegacy(legacyResp), nil
}

Expand Down Expand Up @@ -695,14 +695,14 @@ func min(a int64, b int64) int64 {
}

// responseFinalizeBlockFromLegacy is a convenience function that takes the old abci responses and morphs
// it to the finalize block response. Note that the agreed app data is missing
// it to the finalize block response. Note that the app hash is missing
func responseFinalizeBlockFromLegacy(legacyResp *cmtstate.LegacyABCIResponses) *abci.ResponseFinalizeBlock {
return &abci.ResponseFinalizeBlock{
TxResults: legacyResp.DeliverTxs,
ValidatorUpdates: legacyResp.EndBlock.ValidatorUpdates,
ConsensusParamUpdates: legacyResp.EndBlock.ConsensusParamUpdates,
Events: append(legacyResp.BeginBlock.Events, legacyResp.EndBlock.Events...),
// NOTE: AgreedAppData is missing in the response but will
// NOTE: AppHash is missing in the response but will
// be caught and filled in consensus/replay.go
}
}
2 changes: 1 addition & 1 deletion test/e2e/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (app *Application) FinalizeBlock(_ context.Context, req *abci.RequestFinali
return &abci.ResponseFinalizeBlock{
TxResults: txs,
ValidatorUpdates: valUpdates,
AgreedAppData: app.state.Finalize(),
AppHash: app.state.Finalize(),
Events: []abci.Event{
{
Type: "val_updates",
Expand Down

0 comments on commit d131ab7

Please sign in to comment.