From 51cf3fe7dbd9bfd47fecf9baadc3b1efe464c5c9 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Mon, 14 Mar 2022 17:32:56 -0400 Subject: [PATCH] rename to MarshalTxResults --- abci/types/types.go | 4 ++-- abci/types/types_test.go | 6 +++--- internal/state/execution.go | 2 +- internal/state/state_test.go | 40 ++++++++++++++++++------------------ light/rpc/client.go | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/abci/types/types.go b/abci/types/types.go index 195df6f9b..4240301b5 100644 --- a/abci/types/types.go +++ b/abci/types/types.go @@ -179,11 +179,11 @@ func deterministicExecTxResult(response *ExecTxResult) *ExecTxResult { } } -// TxResultsToByteSlices encodes the the TxResults as a list of byte +// MarshalTxResults encodes the the TxResults as a list of byte // slices. It strips off the non-deterministic pieces of the TxResults // so that the resulting data can be used for hash comparisons and used // in Merkle proofs. -func TxResultsToByteSlices(r []*ExecTxResult) ([][]byte, error) { +func MarshalTxResults(r []*ExecTxResult) ([][]byte, error) { s := make([][]byte, len(r)) for i, e := range r { d := deterministicExecTxResult(e) diff --git a/abci/types/types_test.go b/abci/types/types_test.go index 27f2fb9bd..4417ffe7d 100644 --- a/abci/types/types_test.go +++ b/abci/types/types_test.go @@ -28,7 +28,7 @@ func TestHashAndProveResults(t *testing.T) { require.Equal(t, bz0, bz1) // Make sure that we can get a root hash from results and verify proofs. - rs, err := abci.TxResultsToByteSlices(trs) + rs, err := abci.MarshalTxResults(trs) require.NoError(t, err) root := merkle.HashFromByteSlices(rs) assert.NotEmpty(t, root) @@ -64,9 +64,9 @@ func TestHashDeterministicFieldsOnly(t *testing.T) { Events: []abci.Event{}, Codespace: "nondeterministic.data.def", } - r1, err := abci.TxResultsToByteSlices([]*abci.ExecTxResult{&tr1}) + r1, err := abci.MarshalTxResults([]*abci.ExecTxResult{&tr1}) require.NoError(t, err) - r2, err := abci.TxResultsToByteSlices([]*abci.ExecTxResult{&tr2}) + r2, err := abci.MarshalTxResults([]*abci.ExecTxResult{&tr2}) require.NoError(t, err) require.Equal(t, merkle.HashFromByteSlices(r1), merkle.HashFromByteSlices(r2)) } diff --git a/internal/state/execution.go b/internal/state/execution.go index 547b74ce4..e71fc24d8 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -265,7 +265,7 @@ func (blockExec *BlockExecutor) ApplyBlock( } // Update the state with the block and responses. - rs, err := abci.TxResultsToByteSlices(finalizeBlockResponse.TxResults) + rs, err := abci.MarshalTxResults(finalizeBlockResponse.TxResults) if err != nil { return state, fmt.Errorf("marshaling TxResults: %w", err) } diff --git a/internal/state/state_test.go b/internal/state/state_test.go index 592d79161..18c419e4f 100644 --- a/internal/state/state_test.go +++ b/internal/state/state_test.go @@ -205,10 +205,10 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { res, err := stateStore.LoadABCIResponses(h) if assert.NoError(t, err, "%d", i) { t.Log(res) - e, err := abci.TxResultsToByteSlices(tc.expected) + e, err := abci.MarshalTxResults(tc.expected) require.NoError(t, err) he := merkle.HashFromByteSlices(e) - rs, err := abci.TxResultsToByteSlices(res.FinalizeBlock.TxResults) + rs, err := abci.MarshalTxResults(res.FinalizeBlock.TxResults) hrs := merkle.HashFromByteSlices(rs) require.NoError(t, err) assert.Equal(t, he, hrs, "%d", i) @@ -277,7 +277,7 @@ func TestOneValidatorChangesSaveLoad(t *testing.T) { header, blockID, responses := makeHeaderPartsResponsesValPowerChange(t, state, power) validatorUpdates, err = types.PB2TM.ValidatorUpdates(responses.FinalizeBlock.ValidatorUpdates) require.NoError(t, err) - rs, err := abci.TxResultsToByteSlices(responses.FinalizeBlock.TxResults) + rs, err := abci.MarshalTxResults(responses.FinalizeBlock.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) state, err = state.Update(blockID, &header, h, responses.FinalizeBlock.ConsensusParamUpdates, validatorUpdates) @@ -462,7 +462,7 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) { } validatorUpdates, err := types.PB2TM.ValidatorUpdates(fb.ValidatorUpdates) require.NoError(t, err) - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedState, err := state.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -480,7 +480,7 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) { updateAddVal := abci.ValidatorUpdate{PubKey: fvp, Power: val2VotingPower} validatorUpdates, err = types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{updateAddVal}) assert.NoError(t, err) - rs, err = abci.TxResultsToByteSlices(fb.TxResults) + rs, err = abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h = merkle.HashFromByteSlices(rs) updatedState2, err := updatedState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -522,7 +522,7 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) { // this will cause the diff of priorities (77) // to be larger than threshold == 2*totalVotingPower (22): - rs, err = abci.TxResultsToByteSlices(fb.TxResults) + rs, err = abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h = merkle.HashFromByteSlices(rs) updatedState3, err := updatedState2.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -588,7 +588,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { validatorUpdates, err := types.PB2TM.ValidatorUpdates(fb.ValidatorUpdates) require.NoError(t, err) - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedState, err := state.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -608,7 +608,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { validatorUpdates, err = types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{updateAddVal}) assert.NoError(t, err) - rs, err = abci.TxResultsToByteSlices(fb.TxResults) + rs, err = abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h = merkle.HashFromByteSlices(rs) updatedState2, err := updatedState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -654,7 +654,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { validatorUpdates, err = types.PB2TM.ValidatorUpdates(fb.ValidatorUpdates) require.NoError(t, err) - rs, err = abci.TxResultsToByteSlices(fb.TxResults) + rs, err = abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h = merkle.HashFromByteSlices(rs) updatedState3, err := updatedState2.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -699,7 +699,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { validatorUpdates, err = types.PB2TM.ValidatorUpdates(fb.ValidatorUpdates) require.NoError(t, err) - rs, err = abci.TxResultsToByteSlices(fb.TxResults) + rs, err = abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h = merkle.HashFromByteSlices(rs) oldState, err = oldState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -717,7 +717,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { validatorUpdates, err = types.PB2TM.ValidatorUpdates(fb.ValidatorUpdates) require.NoError(t, err) - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedState, err := oldState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -782,7 +782,7 @@ func TestLargeGenesisValidator(t *testing.T) { require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedState, err := oldState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -816,7 +816,7 @@ func TestLargeGenesisValidator(t *testing.T) { require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedState, err := oldState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -838,7 +838,7 @@ func TestLargeGenesisValidator(t *testing.T) { blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedStateInner, err := lastState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -875,7 +875,7 @@ func TestLargeGenesisValidator(t *testing.T) { require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) state, err = state.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -900,7 +900,7 @@ func TestLargeGenesisValidator(t *testing.T) { blockID = types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} validatorUpdates, err = types.PB2TM.ValidatorUpdates(fb.ValidatorUpdates) require.NoError(t, err) - rs, err = abci.TxResultsToByteSlices(fb.TxResults) + rs, err = abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h = merkle.HashFromByteSlices(rs) updatedState, err = state.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -925,7 +925,7 @@ func TestLargeGenesisValidator(t *testing.T) { require.NoError(t, err) blockID = types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) curState, err = curState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -957,7 +957,7 @@ func TestLargeGenesisValidator(t *testing.T) { blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - rs, err := abci.TxResultsToByteSlices(fb.TxResults) + rs, err := abci.MarshalTxResults(fb.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) updatedState, err = updatedState.Update(blockID, &block.Header, h, fb.ConsensusParamUpdates, validatorUpdates) @@ -1019,7 +1019,7 @@ func TestManyValidatorChangesSaveLoad(t *testing.T) { var validatorUpdates []*types.Validator validatorUpdates, err = types.PB2TM.ValidatorUpdates(responses.FinalizeBlock.ValidatorUpdates) require.NoError(t, err) - rs, err := abci.TxResultsToByteSlices(responses.FinalizeBlock.TxResults) + rs, err := abci.MarshalTxResults(responses.FinalizeBlock.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) state, err = state.Update(blockID, &header, h, responses.FinalizeBlock.ConsensusParamUpdates, validatorUpdates) @@ -1099,7 +1099,7 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) { header, blockID, responses := makeHeaderPartsResponsesParams(t, state, &cp) validatorUpdates, err = types.PB2TM.ValidatorUpdates(responses.FinalizeBlock.ValidatorUpdates) require.NoError(t, err) - rs, err := abci.TxResultsToByteSlices(responses.FinalizeBlock.TxResults) + rs, err := abci.MarshalTxResults(responses.FinalizeBlock.TxResults) require.NoError(t, err) h := merkle.HashFromByteSlices(rs) state, err = state.Update(blockID, &header, h, responses.FinalizeBlock.ConsensusParamUpdates, validatorUpdates) diff --git a/light/rpc/client.go b/light/rpc/client.go index de6168e3b..94fd43b0a 100644 --- a/light/rpc/client.go +++ b/light/rpc/client.go @@ -459,7 +459,7 @@ func (c *Client) BlockResults(ctx context.Context, height *int64) (*coretypes.Re } // Build a Merkle tree out of the slice. - rs, err := abci.TxResultsToByteSlices(res.TxsResults) + rs, err := abci.MarshalTxResults(res.TxsResults) if err != nil { return nil, err }