Skip to content

Commit

Permalink
refactor(abci)!: move Events from FinalizeBlock to ResponseProcessPro…
Browse files Browse the repository at this point in the history
…posal (#770)

* workaround(state): save ABCI responses in ProcessProposal

* refactor: move Events to from ResponseFinalizeBlock to ResponseProcessProposal

* chore(state): save ResponseProcessProposal before calling FinalizeBlock

* revert: change rpc api

* test(abci-cli): fix abci-cli test

* chore: bump abci version to 0.26.2

* chore: make proto
  • Loading branch information
lklimek authored Mar 27, 2024
1 parent 95ead19 commit bc91645
Show file tree
Hide file tree
Showing 29 changed files with 442 additions and 525 deletions.
7 changes: 3 additions & 4 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ func (app *Application) ProcessProposal(_ context.Context, req *abci.RequestProc
Status: abci.ResponseProcessProposal_REJECT,
}, err
}

resp := &abci.ResponseProcessProposal{
Status: abci.ResponseProcessProposal_ACCEPT,
AppHash: roundState.GetAppHash(),
TxResults: txResults,
ConsensusParamUpdates: app.getConsensusParamsUpdate(req.Height),
ValidatorSetUpdate: app.getValidatorSetUpdate(req.Height),
Events: []abci.Event{app.eventValUpdate(req.Height)},
}

if app.cfg.ProcessProposalDelayMS != 0 {
Expand Down Expand Up @@ -425,10 +427,7 @@ func (app *Application) FinalizeBlock(_ context.Context, req *abci.RequestFinali
return nil, err
}
}
events := []abci.Event{app.eventValUpdate(req.Height)}
resp := &abci.ResponseFinalizeBlock{
Events: events,
}
resp := &abci.ResponseFinalizeBlock{}
if app.RetainBlocks > 0 && app.LastCommittedState.GetHeight() >= app.RetainBlocks {
resp.RetainHeight = app.LastCommittedState.GetHeight() - app.RetainBlocks + 1
}
Expand Down
8 changes: 4 additions & 4 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ func testKVStore(ctx context.Context, t *testing.T, app types.Application, tx []
require.NoError(t, err)
require.Len(t, respProcess.TxResults, 1)
require.False(t, respProcess.TxResults[0].IsErr(), respProcess.TxResults[0].Log)
require.Len(t, respProcess.Events, 1)

// Duplicate ProcessProposal calls should return error
_, err = app.ProcessProposal(ctx, reqProcess)
require.ErrorContains(t, err, "duplicate ProcessProposal call")

reqFin := &types.RequestFinalizeBlock{Height: height}
reqFin.Block, reqFin.BlockID = makeBlock(t, height, [][]byte{tx}, respPrep.AppHash)
respFin, err := app.FinalizeBlock(ctx, reqFin)
_, err = app.FinalizeBlock(ctx, reqFin)
require.NoError(t, err)
require.Equal(t, 1, len(respFin.Events))

// repeating tx raises an error
_, err = app.FinalizeBlock(ctx, reqFin)
Expand Down Expand Up @@ -290,12 +290,12 @@ func makeApplyBlock(
require.NoError(t, err)
require.NotZero(t, respProcessProposal)
require.Equal(t, types.ResponseProcessProposal_ACCEPT, respProcessProposal.Status)
require.Len(t, respProcessProposal.Events, 1)

rfb := &types.RequestFinalizeBlock{Hash: hash, Height: height}
rfb.Block, rfb.BlockID = makeBlock(t, height, txs, respProcessProposal.AppHash)
resFinalizeBlock, err := kvstore.FinalizeBlock(ctx, rfb)
require.NoError(t, err)
require.Len(t, resFinalizeBlock.Events, 1)

return respProcessProposal, resFinalizeBlock
}
Expand Down Expand Up @@ -413,13 +413,13 @@ func testClient(ctx context.Context, t *testing.T, app abciclient.Client, height
require.NotZero(t, rpp)
require.Equal(t, 1, len(rpp.TxResults))
require.False(t, rpp.TxResults[0].IsErr())
require.Len(t, rpp.Events, 1)

rfb := &types.RequestFinalizeBlock{Height: height}
rfb.Block, rfb.BlockID = makeBlock(t, height, [][]byte{tx}, rpp.AppHash)
ar, err := app.FinalizeBlock(ctx, rfb)
require.NoError(t, err)
require.Zero(t, ar.RetainHeight)
require.Len(t, ar.Events, 1)

info, err := app.Info(ctx, &types.RequestInfo{})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestVerifyBlockCommit(t *testing.T) {
assert.Len(t, respPrep.TxRecords, 1)
require.Equal(t, 1, len(respPrep.TxResults))
require.False(t, respPrep.TxResults[0].IsErr(), respPrep.TxResults[0].Log)

pbBlock, err := block.ToProto()
require.NoError(t, err)
blockID := block.BlockID(nil)
Expand All @@ -70,9 +71,8 @@ func TestVerifyBlockCommit(t *testing.T) {
Block: pbBlock,
BlockID: &pbBlockID,
}
respFb, err := kvstore.FinalizeBlock(ctx, reqFb)
_, err = kvstore.FinalizeBlock(ctx, reqFb)
require.NoError(t, err)
require.Equal(t, 1, len(respFb.Events))
}

type blockExecutor struct {
Expand Down
3 changes: 0 additions & 3 deletions abci/tests/test_cli/ex1.abci.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

> finalize_block 1 0000000000000000000000000000000000000000000000000000000000000000 "abc"
-> code: OK
-> data.hex: 0x6576656E74733A3C747970653A2276616C5F757064617465732220617474726962757465733A3C6B65793A2273697A65222076616C75653A223022203E20617474726962757465733A3C6B65793A22686569676874222076616C75653A223122203E203E20

> info
-> code: OK
Expand Down Expand Up @@ -56,7 +55,6 @@

> finalize_block 2 3C868EF29ED961094EE2C48BDD78CDC83C7AA426E763024985AF9F0F569EEFBE "def=xyz" "ghi=123"
-> code: OK
-> data.hex: 0x6576656E74733A3C747970653A2276616C5F757064617465732220617474726962757465733A3C6B65793A2273697A65222076616C75653A223022203E20617474726962757465733A3C6B65793A22686569676874222076616C75653A223222203E203E20

> query "def"
-> code: OK
Expand Down Expand Up @@ -101,5 +99,4 @@

> finalize_block 3 243BA0AC2622E2E7ACFEF366E85E503ACEBA1C950357436B554CA253492420AB
-> code: OK
-> data.hex: 0x6576656E74733A3C747970653A2276616C5F757064617465732220617474726962757465733A3C6B65793A2273697A65222076616C75653A223022203E20617474726962757465733A3C6B65793A22686569676874222076616C75653A223322203E203E20

Loading

0 comments on commit bc91645

Please sign in to comment.