From 778e2e89085aa2373f3af4f89c323168d1d5f021 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Mon, 7 Mar 2022 18:50:33 -0500 Subject: [PATCH] add tx conversions to get consensus tests to pass --- abci/types/types.go | 12 ++++++++++++ internal/state/execution.go | 2 +- types/tx.go | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/abci/types/types.go b/abci/types/types.go index 12c21e2da..c3bb7109f 100644 --- a/abci/types/types.go +++ b/abci/types/types.go @@ -202,3 +202,15 @@ func mustResultsToByteSlices(r []*ExecTxResult) [][]byte { } return s } + +// IncludedTxs returns all of the TxRecords that are marked for inclusion in the +// proposed block. +func (rpp *ResponsePrepareProposal) IncludedTxs() []*TxRecord { + trs := []*TxRecord{} + for _, tr := range rpp.TxRecords { + if tr.Action == TxRecord_ADDED || tr.Action == TxRecord_UNMODIFIED { + trs = append(trs, tr) + } + } + return trs +} diff --git a/internal/state/execution.go b/internal/state/execution.go index ced7d7b27..e72a42dd4 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -144,7 +144,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( panic(fmt.Sprintf("application returned invalid ResponsePrepareProposal: %s", err)) } - return state.BlockFromResponsePrepareProposal(height, preparedProposal) + return state.MakeBlock(height, types.TxRecordsToTxs(preparedProposal.IncludedTxs()), commit, evidence, proposerAddr) } func (blockExec *BlockExecutor) ProcessProposal( diff --git a/types/tx.go b/types/tx.go index 746252238..0d2e78e4d 100644 --- a/types/tx.go +++ b/types/tx.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" tmbytes "github.com/tendermint/tendermint/libs/bytes" @@ -102,6 +103,15 @@ func ToTxs(txs [][]byte) Txs { return txBzs } +// TxRecordsToTxs coverts from the abci Tx type to the a Txs type. +func TxRecordsToTxs(trs []*abci.TxRecord) Txs { + txs := make([]Tx, len(trs)) + for i, tr := range trs { + txs[i] = Tx(tr.Tx) + } + return txs +} + // TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree. type TxProof struct { RootHash tmbytes.HexBytes `json:"root_hash"`