Skip to content

Commit c23345b

Browse files
feat(rpc): update tx status to return logs (#1459)
## Description Part of #1454
1 parent 9563209 commit c23345b

File tree

8 files changed

+37
-34
lines changed

8 files changed

+37
-34
lines changed

proto/tendermint/store/types.pb.go

Lines changed: 17 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/tendermint/store/types.proto

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ message BlockStoreState {
99
}
1010

1111
// TxInfo describes the location of a tx inside a committed block
12-
// as well as the result of executing the transaction and the raw log output.
12+
// as well as the result of executing the transaction and the error log output.
1313
message TxInfo {
1414
int64 height = 1;
1515
uint32 index = 2;
1616
// The response code of executing the tx. 0 means
1717
// successfully executed, all others are error codes.
1818
uint32 code = 3;
19-
// The log output generated during the execution of a transaction.
20-
// Note: this is empty if the transaction succeeded.
21-
string log = 4;
19+
// The error log output generated if the transaction execution fails.
20+
string error = 4;
2221
}

rpc/client/rpc_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ func TestTxStatus(t *testing.T) {
584584
require.EqualValues(bres.Height, result.Height)
585585
require.EqualValues(0, result.Index)
586586
require.Equal("COMMITTED", result.Status)
587+
require.Equal(abci.CodeTypeOK, result.ExecutionCode)
588+
require.Equal("", result.Error)
587589
}
588590

589591
func TestTxSearch(t *testing.T) {

rpc/core/tx.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,16 @@ func ProveShares(
220220
return shareProof, nil
221221
}
222222

223-
// TxStatus retrieves the status of a transaction given its hash. It returns a ResultTxStatus
224-
// containing the height and index of the transaction within the block(if committed)
225-
// or whether the transaction is pending, evicted from the mempool, or otherwise unknown.
223+
// TxStatus retrieves the status of a transaction by its hash. It returns a ResultTxStatus
224+
// with the transaction's height and index if committed, or its pending, evicted, or unknown status.
225+
// It also includes the execution code and log for failed txs.
226226
func TxStatus(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultTxStatus, error) {
227227
env := GetEnvironment()
228228

229229
// Check if the tx has been committed
230230
txInfo := env.BlockStore.LoadTxInfo(hash)
231231
if txInfo != nil {
232-
return &ctypes.ResultTxStatus{Height: txInfo.Height, Index: txInfo.Index, ExecutionCode: txInfo.Code, Status: TxStatusCommitted}, nil
232+
return &ctypes.ResultTxStatus{Height: txInfo.Height, Index: txInfo.Index, ExecutionCode: txInfo.Code, Error: txInfo.Error, Status: TxStatusCommitted}, nil
233233
}
234234

235235
// Get the tx key from the hash

rpc/core/tx_status_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func TestTxStatus(t *testing.T) {
126126
assert.Equal(t, height, txStatus.Height)
127127
assert.Equal(t, uint32(i), txStatus.Index)
128128
assert.Equal(t, uint32(0), txStatus.ExecutionCode)
129+
assert.Equal(t, "", txStatus.Error)
129130
}
130131
}
131132

rpc/core/types/responses.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ type ResultCommit struct {
6161
}
6262

6363
// ResultTxStatus represents the status of a transaction during its life cycle.
64-
// It contains info to locate a tx in a committed block as well as its execution code and status.
64+
// It contains info to locate a tx in a committed block as well as its execution code, log if it fails and status.
6565
type ResultTxStatus struct {
6666
Height int64 `json:"height"`
6767
Index uint32 `json:"index"`
6868
ExecutionCode uint32 `json:"execution_code"`
69+
Error string `json:"error"`
6970
Status string `json:"status"`
7071
}
7172

store/store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err
452452
}
453453

454454
// SaveTxInfo indexes the txs from the block with the given response codes and logs from execution.
455-
// The logs are only saved for failed transactions.
455+
// Only the error logs are saved for failed transactions.
456456
func (bs *BlockStore) SaveTxInfo(block *types.Block, txResponseCodes []uint32, logs []string) error {
457457
if len(txResponseCodes) != len(block.Txs) {
458458
return fmt.Errorf("txResponseCodes length mismatch with block txs length")
@@ -471,9 +471,9 @@ func (bs *BlockStore) SaveTxInfo(block *types.Block, txResponseCodes []uint32, l
471471
Index: uint32(i),
472472
Code: txResponseCodes[i],
473473
}
474-
// Only save Logs for failed transactions
474+
// Set error log for failed txs
475475
if txResponseCodes[i] != abci.CodeTypeOK {
476-
txInfo.Log = logs[i]
476+
txInfo.Error = logs[i]
477477
}
478478
txInfoBytes, err := proto.Marshal(&txInfo)
479479
if err != nil {

store/store_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
1717

18+
abci "github.com/tendermint/tendermint/abci/types"
1819
cfg "github.com/tendermint/tendermint/config"
1920
"github.com/tendermint/tendermint/crypto"
2021
"github.com/tendermint/tendermint/libs/log"
@@ -418,10 +419,10 @@ func TestSaveTxInfo(t *testing.T) {
418419
require.Equal(t, uint32(i), txInfo.Index)
419420
require.Equal(t, txResponseCodes[i], txInfo.Code)
420421
// We don't save the logs for successful transactions
421-
if txResponseCodes[i] == 0 {
422-
require.Equal(t, "", txInfo.Log)
422+
if txResponseCodes[i] == abci.CodeTypeOK {
423+
require.Equal(t, "", txInfo.Error)
423424
} else {
424-
require.Equal(t, logs[i], txInfo.Log)
425+
require.Equal(t, logs[i], txInfo.Error)
425426
}
426427
}
427428
}
@@ -435,7 +436,7 @@ func TestSaveTxInfo(t *testing.T) {
435436
require.Equal(t, txInfo.Height, int64(777))
436437
require.Equal(t, uint32(1), txInfo.Code)
437438
require.Equal(t, uint32(5), txInfo.Index)
438-
require.Equal(t, "failure", txInfo.Log)
439+
require.Equal(t, "failure", txInfo.Error)
439440
}
440441

441442
func TestLoadBaseMeta(t *testing.T) {

0 commit comments

Comments
 (0)