block events and tx fixups

This commit is contained in:
William Banfield
2022-03-01 14:42:44 -05:00
parent e3ff082f21
commit 1aa5dda364
21 changed files with 46 additions and 46 deletions
+1 -1
View File
@@ -213,7 +213,7 @@ func eventReIndex(cmd *cobra.Command, args eventReIndexArgs) error {
Height: b.Height,
Index: uint32(i),
Tx: b.Data.Txs[i],
Result: *(r.FinalizeBlock.Txs[i]),
Result: *(r.FinalizeBlock.TxResults[i]),
}
_ = batch.Add(&tr)
@@ -156,7 +156,7 @@ func TestReIndexEvent(t *testing.T) {
dtx := abcitypes.ResponseDeliverTx{}
abciResp := &prototmstate.ABCIResponses{
FinalizeBlock: &abcitypes.ResponseFinalizeBlock{
TxResults: []*abcitypes.ResponseDeliverTx{&dtx},
TxResults: []*abcitypes.ExecTxResult{&dtx},
},
}
+3 -3
View File
@@ -668,8 +668,8 @@ func TestMockProxyApp(t *testing.T) {
assert.NotPanics(t, func() {
abciResWithEmptyDeliverTx := new(tmstate.ABCIResponses)
abciResWithEmptyDeliverTx.FinalizeBlock = new(abci.ResponseFinalizeBlock)
abciResWithEmptyDeliverTx.FinalizeBlock.Txs = make([]*abci.ResponseDeliverTx, 0)
abciResWithEmptyDeliverTx.FinalizeBlock.Txs = append(abciResWithEmptyDeliverTx.FinalizeBlock.Txs, &abci.ResponseDeliverTx{})
abciResWithEmptyDeliverTx.FinalizeBlock.TxResults = make([]*abci.ResponseDeliverTx, 0)
abciResWithEmptyDeliverTx.FinalizeBlock.TxResults = append(abciResWithEmptyDeliverTx.FinalizeTxResults.Txs, &abci.ResponseDeliverTx{})
// called when saveABCIResponses:
bytes, err := proto.Marshal(abciResWithEmptyDeliverTx)
@@ -685,7 +685,7 @@ func TestMockProxyApp(t *testing.T) {
abciRes := new(tmstate.ABCIResponses)
abciRes.FinalizeBlock = new(abci.ResponseFinalizeBlock)
abciRes.FinalizeBlock.Txs = make([]*abci.ResponseDeliverTx, len(loadedAbciRes.FinalizeBlock.Txs))
abciRes.FinalizeBlock.TxResults = make([]*abci.ResponseDeliverTx, len(loadedAbciRes.FinalizeBlock.TxResults))
someTx := []byte("tx")
resp, err := mock.FinalizeBlock(ctx, abci.RequestFinalizeBlock{Txs: [][]byte{someTx}})
+2 -2
View File
@@ -89,7 +89,7 @@ func (b *EventBus) Publish(ctx context.Context, eventValue string, eventData typ
}
func (b *EventBus) PublishEventNewBlock(ctx context.Context, data types.EventDataNewBlock) error {
events := data.ResultFinalizeBlock.Events
events := data.ResultFinalizeBlock.BlockEvents
// add Tendermint-reserved new block event
events = append(events, types.EventNewBlock)
@@ -100,7 +100,7 @@ func (b *EventBus) PublishEventNewBlock(ctx context.Context, data types.EventDat
func (b *EventBus) PublishEventNewBlockHeader(ctx context.Context, data types.EventDataNewBlockHeader) error {
// no explicit deadline for publishing events
events := data.ResultFinalizeBlock.Events
events := data.ResultFinalizeBlock.BlockEvents
// add Tendermint-reserved new block header event
events = append(events, types.EventNewBlockHeader)
+2 -2
View File
@@ -84,7 +84,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
require.NoError(t, err)
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()}
resultFinalizeBlock := abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{
{Key: "baz", Value: "1"},
{Key: "foz", Value: "2"},
@@ -253,7 +253,7 @@ func TestEventBusPublishEventNewBlockHeader(t *testing.T) {
block := types.MakeBlock(0, []types.Tx{}, nil, []types.Evidence{})
resultFinalizeBlock := abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{
{Key: "baz", Value: "1"},
{Key: "foz", Value: "2"},
+1 -1
View File
@@ -265,7 +265,7 @@ func TestBlockResults(t *testing.T) {
// tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
stateStoreMock.On("LoadABCIResponses", testHeight).Return(&state.ABCIResponses{
FinalizeBlock: &abcitypes.ResponseFinalizeBlock{
TxResults: []*abcitypes.ResponseDeliverTx{
TxResults: []*abcitypes.ExecTxResult{
{
GasUsed: testGasUsed,
},
+2 -2
View File
@@ -214,9 +214,9 @@ func (env *Environment) BlockResults(ctx context.Context, heightPtr *int64) (*co
return &coretypes.ResultBlockResults{
Height: height,
TxsResults: results.FinalizeBlock.Txs,
TxsResults: results.FinalizeBlock.TxResults,
TotalGasUsed: totalGasUsed,
FinalizeBlockEvents: results.FinalizeBlock.Events,
FinalizeBlockEvents: results.FinalizeBlock.BlockEvents,
ValidatorUpdates: results.FinalizeBlock.ValidatorUpdates,
ConsensusParamUpdates: results.FinalizeBlock.ConsensusParamUpdates,
}, nil
+3 -3
View File
@@ -72,7 +72,7 @@ func TestBlockchainInfo(t *testing.T) {
func TestBlockResults(t *testing.T) {
results := &tmstate.ABCIResponses{
FinalizeBlock: &abci.ResponseFinalizeBlock{
TxResults: []*abci.ResponseDeliverTx{
TxResults: []*abci.ExecTxResult{
{Code: 0, Data: []byte{0x01}, Log: "ok", GasUsed: 10},
{Code: 0, Data: []byte{0x02}, Log: "ok", GasUsed: 5},
{Code: 1, Log: "not ok", GasUsed: 0},
@@ -99,9 +99,9 @@ func TestBlockResults(t *testing.T) {
{101, true, nil},
{100, false, &coretypes.ResultBlockResults{
Height: 100,
TxsResults: results.FinalizeBlock.Txs,
TxsResults: results.FinalizeBlock.TxResults,
TotalGasUsed: 15,
FinalizeBlockEvents: results.FinalizeBlock.Events,
FinalizeBlockEvents: results.FinalizeBlock.BlockEvents,
ValidatorUpdates: results.FinalizeBlock.ValidatorUpdates,
ConsensusParamUpdates: results.FinalizeBlock.ConsensusParamUpdates,
}},
+5 -5
View File
@@ -253,7 +253,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
}
// Lock mempool, commit app state, update mempoool.
appHash, retainHeight, err := blockExec.Commit(ctx, state, block, abciResponses.FinalizeBlock.Txs)
appHash, retainHeight, err := blockExec.Commit(ctx, state, block, abciResponses.FinalizeBlock.TxResults)
if err != nil {
return state, fmt.Errorf("commit failed for application: %w", err)
}
@@ -383,7 +383,7 @@ func execBlockOnProxyApp(
abciResponses := new(tmstate.ABCIResponses)
abciResponses.FinalizeBlock = &abci.ResponseFinalizeBlock{}
dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs))
abciResponses.FinalizeBlock.Txs = dtxs
abciResponses.FinalizeBlock.TxResults = dtxs
// Begin block
var err error
@@ -583,9 +583,9 @@ func fireEvents(
}
// sanity check
if len(abciResponses.FinalizeBlock.Txs) != len(block.Data.Txs) {
if len(abciResponses.FinalizeBlock.TxResults) != len(block.Data.Txs) {
panic(fmt.Sprintf("number of TXs (%d) and ABCI TX responses (%d) do not match",
len(block.Data.Txs), len(abciResponses.FinalizeBlock.Txs)))
len(block.Data.Txs), len(abciResponses.FinalizeBlock.TxResults)))
}
for i, tx := range block.Data.Txs {
@@ -594,7 +594,7 @@ func fireEvents(
Height: block.Height,
Index: uint32(i),
Tx: tx,
Result: *(abciResponses.FinalizeBlock.Txs[i]),
Result: *(abciResponses.FinalizeBlock.TxResults[i]),
},
}); err != nil {
logger.Error("failed publishing event TX", "err", err)
+2 -2
View File
@@ -315,8 +315,8 @@ func (app *testApp) FinalizeBlock(req abci.RequestFinalizeBlock) abci.ResponseFi
AppVersion: 1,
},
},
Events: []abci.Event{},
TxResults: resTxs,
BlockEvents: []abci.Event{},
TxResults: resTxs,
}
}
+1 -1
View File
@@ -66,7 +66,7 @@ func (idx *BlockerIndexer) Index(bh types.EventDataNewBlockHeader) error {
}
// 2. index BeginBlock events
if err := idx.indexEvents(batch, bh.ResultFinalizeBlock.Events, "finalize_block", height); err != nil {
if err := idx.indexEvents(batch, bh.ResultFinalizeBlock.BlockEvents, "finalize_block", height); err != nil {
return fmt.Errorf("failed to index FinalizeBlock events: %w", err)
}
+2 -2
View File
@@ -21,7 +21,7 @@ func TestBlockIndexer(t *testing.T) {
require.NoError(t, indexer.Index(types.EventDataNewBlockHeader{
Header: types.Header{Height: 1},
ResultFinalizeBlock: abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
{
Type: "finalize_event1",
Attributes: []abci.EventAttribute{
@@ -54,7 +54,7 @@ func TestBlockIndexer(t *testing.T) {
require.NoError(t, indexer.Index(types.EventDataNewBlockHeader{
Header: types.Header{Height: int64(i)},
ResultFinalizeBlock: abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
{
Type: "finalize_event1",
Attributes: []abci.EventAttribute{
+2 -2
View File
@@ -35,7 +35,7 @@ func TestBlockFuncs(t *testing.T) {
require.NoError(t, indexer.IndexBlockEvents(types.EventDataNewBlockHeader{
Header: types.Header{Height: 1},
ResultFinalizeBlock: abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
{
Type: "finalize_eventA",
Attributes: []abci.EventAttribute{
@@ -73,7 +73,7 @@ func TestBlockFuncs(t *testing.T) {
require.NoError(t, indexer.IndexBlockEvents(types.EventDataNewBlockHeader{
Header: types.Header{Height: int64(i)},
ResultFinalizeBlock: abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
{
Type: "finalize_eventA",
Attributes: []abci.EventAttribute{
+1 -1
View File
@@ -170,7 +170,7 @@ INSERT INTO `+tableBlocks+` (height, chain_id, created_at)
return fmt.Errorf("block meta-events: %w", err)
}
// Insert all the block events. Order is important here,
if err := insertEvents(dbtx, blockID, 0, h.ResultFinalizeBlock.Events); err != nil {
if err := insertEvents(dbtx, blockID, 0, h.ResultFinalizeBlock.BlockEvents); err != nil {
return fmt.Errorf("finalize-block events: %w", err)
}
return nil
@@ -222,7 +222,7 @@ func newTestBlockHeader() types.EventDataNewBlockHeader {
return types.EventDataNewBlockHeader{
Header: types.Header{Height: 1},
ResultFinalizeBlock: abci.ResponseFinalizeBlock{
Events: []abci.Event{
BlockEvents: []abci.Event{
makeIndexedEvent("finalize_event.proposer", "FCAA001"),
makeIndexedEvent("thingy.whatzit", "O.O"),
makeIndexedEvent("my_event.foo", "100"),
+3 -3
View File
@@ -109,10 +109,10 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
abciResponses := new(tmstate.ABCIResponses)
dtxs := make([]*abci.ResponseDeliverTx, 2)
abciResponses.FinalizeBlock = new(abci.ResponseFinalizeBlock)
abciResponses.FinalizeBlock.Txs = dtxs
abciResponses.FinalizeBlock.TxResults = dtxs
abciResponses.FinalizeBlock.Txs[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Events: nil}
abciResponses.FinalizeBlock.Txs[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Events: nil}
abciResponses.FinalizeBlock.TxResults[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Events: nil}
abciResponses.FinalizeBlock.TxResults[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Events: nil}
pbpk, err := encoding.PubKeyToProto(ed25519.GenPrivKey().PubKey())
require.NoError(t, err)
abciResponses.FinalizeBlock.ValidatorUpdates = []abci.ValidatorUpdate{{PubKey: pbpk, Power: 10}}
+3 -3
View File
@@ -401,7 +401,7 @@ func (store dbStore) reverseBatchDelete(batch dbm.Batch, start, end []byte) ([]b
//
// See merkle.SimpleHashFromByteSlices
func ABCIResponsesResultsHash(ar *tmstate.ABCIResponses) []byte {
return types.NewResults(ar.FinalizeBlock.Txs).Hash()
return types.NewResults(ar.FinalizeBlock.TxResults).Hash()
}
// LoadABCIResponses loads the ABCIResponses for the given height from the
@@ -444,13 +444,13 @@ func (store dbStore) SaveABCIResponses(height int64, abciResponses *tmstate.ABCI
func (store dbStore) saveABCIResponses(height int64, abciResponses *tmstate.ABCIResponses) error {
var dtxs []*abci.ResponseDeliverTx
// strip nil values,
for _, tx := range abciResponses.FinalizeBlock.Txs {
for _, tx := range abciResponses.FinalizeBlock.TxResults {
if tx != nil {
dtxs = append(dtxs, tx)
}
}
abciResponses.FinalizeBlock.Txs = dtxs
abciResponses.FinalizeBlock.TxResults = dtxs
bz, err := abciResponses.Marshal()
if err != nil {
+3 -3
View File
@@ -239,7 +239,7 @@ func TestPruneStates(t *testing.T) {
err = stateStore.SaveABCIResponses(h, &tmstate.ABCIResponses{
FinalizeBlock: &abci.ResponseFinalizeBlock{
TxResults: []*abci.ResponseDeliverTx{
TxResults: []*abci.ExecTxResult{
{Data: []byte{1}},
{Data: []byte{2}},
{Data: []byte{3}},
@@ -303,7 +303,7 @@ func TestPruneStates(t *testing.T) {
func TestABCIResponsesResultsHash(t *testing.T) {
responses := &tmstate.ABCIResponses{
FinalizeBlock: &abci.ResponseFinalizeBlock{
TxResults: []*abci.ResponseDeliverTx{
TxResults: []*abci.ExecTxResult{
{Code: 32, Data: []byte("Hello"), Log: "Huh?"},
},
},
@@ -312,7 +312,7 @@ func TestABCIResponsesResultsHash(t *testing.T) {
root := sm.ABCIResponsesResultsHash(responses)
// root should be Merkle tree root of FinalizeBlock tx responses
results := types.NewResults(responses.FinalizeBlock.Txs)
results := types.NewResults(responses.FinalizeBlock.TxResults)
assert.Equal(t, root, results.Hash())
// test we can prove first tx in FinalizeBlock
+1 -1
View File
@@ -452,7 +452,7 @@ func (c *Client) BlockResults(ctx context.Context, height *int64) (*coretypes.Re
// proto-encode FinalizeBlock events
bbeBytes, err := proto.Marshal(&abci.ResponseFinalizeBlock{
Events: res.FinalizeBlockEvents,
BlockEvents: res.FinalizeBlockEvents,
})
if err != nil {
return nil, err
+6 -6
View File
@@ -65,12 +65,12 @@ type ResultCommit struct {
// ABCI results from a block
type ResultBlockResults struct {
Height int64 `json:"height,string"`
TxsResults []*abci.ResponseDeliverTx `json:"txs_results"`
TotalGasUsed int64 `json:"total_gas_used,string"`
FinalizeBlockEvents []abci.Event `json:"finalize_block_events"`
ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"`
ConsensusParamUpdates *tmproto.ConsensusParams `json:"consensus_param_updates"`
Height int64 `json:"height,string"`
TxsResults []*abci.ExecTxResult `json:"txs_results"`
TotalGasUsed int64 `json:"total_gas_used,string"`
FinalizeBlockEvents []abci.Event `json:"finalize_block_events"`
ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"`
ConsensusParamUpdates *tmproto.ConsensusParams `json:"consensus_param_updates"`
}
// NewResultCommit is a helper to initialize the ResultCommit with
+1 -1
View File
@@ -178,7 +178,7 @@ func (app *Application) FinalizeBlock(req abci.RequestFinalizeBlock) abci.Respon
return abci.ResponseFinalizeBlock{
TxResults: txs,
ValidatorUpdates: valUpdates,
Events: []abci.Event{
BlockEvents: []abci.Event{
{
Type: "val_updates",
Attributes: []abci.EventAttribute{