Skip to content

Commit

Permalink
feat(store): add rawlog in txstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Aug 15, 2024
1 parent 6333e56 commit 52ef621
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 18 deletions.
2 changes: 1 addition & 1 deletion consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ func (bs *mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
func (bs *mockBlockStore) LoadBlockPart(height int64, index int) *types.Part { return nil }
func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
}
func (bs *mockBlockStore) SaveTxInfo(block *types.Block, txResponseCode []uint32) error {
func (bs *mockBlockStore) SaveTxInfo(block *types.Block, txResponseCode []uint32, logs []string) error {
return nil
}
func (bs *mockBlockStore) LoadTxInfo(hash []byte) *cmtstore.TxInfo { return &cmtstore.TxInfo{} }
Expand Down
68 changes: 61 additions & 7 deletions proto/tendermint/store/types.pb.go

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

3 changes: 3 additions & 0 deletions proto/tendermint/store/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ message TxInfo {
// The response code of executing the tx. 0 means
// successfully executed, all others are error codes.
uint32 code = 3;
// The unprocessed log output generated during
// the execution of a transaction.
string rawLog = 4;

Check failure on line 21 in proto/tendermint/store/types.proto

View workflow job for this annotation

GitHub Actions / lint

Field name "rawLog" should be lower_snake_case, such as "raw_log".
}
2 changes: 1 addition & 1 deletion rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (mockBlockStore) LoadSeenCommit(height int64) *types.Commit { retur
func (mockBlockStore) PruneBlocks(height int64) (uint64, error) { return 0, nil }
func (mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
}
func (mockBlockStore) SaveTxInfo(block *types.Block, txResponseCode []uint32) error {
func (mockBlockStore) SaveTxInfo(block *types.Block, txResponseCodes []uint32, logs []string) error {
return nil
}

Expand Down
12 changes: 11 additions & 1 deletion state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ func (blockExec *BlockExecutor) ApplyBlock(
// for correct crash recovery
if blockExec.blockStore != nil {
respCodes := getResponseCodes(abciResponses.DeliverTxs)
if err := blockExec.blockStore.SaveTxInfo(block, respCodes); err != nil {
logs := getLogs(abciResponses.DeliverTxs)
if err := blockExec.blockStore.SaveTxInfo(block, respCodes, logs); err != nil {
return state, 0, err
}
}
Expand Down Expand Up @@ -684,3 +685,12 @@ func getResponseCodes(responses []*abci.ResponseDeliverTx) []uint32 {
}
return responseCodes
}

// getLogs gets logs from a list of ResponseDeliverTx.
func getLogs(responses []*abci.ResponseDeliverTx) []string {
logs := make([]string, len(responses))
for i, response := range responses {
logs[i] = response.Log
}
return logs
}
8 changes: 4 additions & 4 deletions state/mocks/block_store.go

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

2 changes: 1 addition & 1 deletion state/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type BlockStore interface {
LoadBlock(height int64) *types.Block

SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
SaveTxInfo(block *types.Block, txResponseCode []uint32) error
SaveTxInfo(block *types.Block, txResponseCodes []uint32, logs []string) error

PruneBlocks(height int64) (uint64, error)

Expand Down
6 changes: 5 additions & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,13 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err
}

// SaveTxInfo indexes the txs from the block with the given response codes from execution.
func (bs *BlockStore) SaveTxInfo(block *types.Block, txResponseCodes []uint32) error {
func (bs *BlockStore) SaveTxInfo(block *types.Block, txResponseCodes []uint32, logs []string) error {
if len(txResponseCodes) != len(block.Txs) {
return fmt.Errorf("txResponseCodes length mismatch with block txs length")
}
if len(logs) != len(block.Txs) {
return fmt.Errorf("logs length mismatch with block txs length")
}

// Create a new batch
batch := bs.db.NewBatch()
Expand All @@ -465,6 +468,7 @@ func (bs *BlockStore) SaveTxInfo(block *types.Block, txResponseCodes []uint32) e
Height: block.Height,
Index: uint32(i),
Code: txResponseCodes[i],
RawLog: logs[i],
}
txInfoBytes, err := proto.Marshal(&txInfo)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func TestSaveTxInfo(t *testing.T) {

// Create 1000 blocks
txResponseCodes := make([]uint32, len(block.Txs))
logs := make([]string, len(block.Txs))
for h := int64(1); h <= 1000; h++ {
block := makeBlock(h, state, new(types.Commit))
partSet := block.MakePartSet(2)
Expand All @@ -395,13 +396,15 @@ func TestSaveTxInfo(t *testing.T) {
// If even set it to 0
if i%2 == 0 {
txResponseCodes[i] = 0
logs[i] = "success"
} else {
txResponseCodes[i] = 1
logs[i] = "failure"
}
}

// Save the tx info
err := blockStore.SaveTxInfo(block, txResponseCodes)
err := blockStore.SaveTxInfo(block, txResponseCodes, logs)
require.NoError(t, err)
}

Expand All @@ -414,6 +417,7 @@ func TestSaveTxInfo(t *testing.T) {
require.Equal(t, block.Height, txInfo.Height)
require.Equal(t, uint32(i), txInfo.Index)
require.Equal(t, txResponseCodes[i], txInfo.Code)
require.Equal(t, logs[i], txInfo.RawLog)
}
}

Expand All @@ -426,6 +430,7 @@ func TestSaveTxInfo(t *testing.T) {
require.Equal(t, txInfo.Height, int64(777))
require.Equal(t, uint32(1), txInfo.Code)
require.Equal(t, uint32(5), txInfo.Index)
require.Equal(t, "failure", txInfo.RawLog)
}

func TestLoadBaseMeta(t *testing.T) {
Expand Down Expand Up @@ -597,7 +602,7 @@ func TestPruneBlocksPrunesTxs(t *testing.T) {
partSet := block.MakePartSet(2)
seenCommit := makeTestCommit(h, cmttime.Now())
blockStore.SaveBlock(block, partSet, seenCommit)
err := blockStore.SaveTxInfo(block, make([]uint32, len(block.Txs)))
err := blockStore.SaveTxInfo(block, make([]uint32, len(block.Txs)), make([]string, len(block.Txs)))
require.NoError(t, err)
for _, tx := range block.Txs {
indexedTxHashes = append(indexedTxHashes, tx.Hash())
Expand Down

0 comments on commit 52ef621

Please sign in to comment.