diff --git a/lite/helpers.go b/lite/helpers.go index 01ed4a84a..9c015a08e 100644 --- a/lite/helpers.go +++ b/lite/helpers.go @@ -120,11 +120,11 @@ func genHeader(chainID string, height int64, txs types.Txs, TotalTxs: int64(len(txs)), // LastBlockID // LastCommitHash - ValidatorsHash: vals.Hash(), - DataHash: txs.Hash(), - AppHash: appHash, - ConsensusHash: consHash, - ResultsHash: resHash, + ValidatorsHash: vals.Hash(), + DataHash: txs.Hash(), + AppHash: appHash, + ConsensusHash: consHash, + LastResultsHash: resHash, } } diff --git a/state/execution.go b/state/execution.go index 024c3f469..cba139963 100644 --- a/state/execution.go +++ b/state/execution.go @@ -243,7 +243,7 @@ func (s *State) MakeBlock(height int64, txs []types.Tx, commit *types.Commit) (* block.ValidatorsHash = s.Validators.Hash() block.AppHash = s.AppHash block.ConsensusHash = s.LastConsensusParams.Hash() - block.ResultsHash = s.LastResultHash + block.LastResultsHash = s.LastResultsHash return block, block.MakePartSet(s.ConsensusParams.BlockGossip.BlockPartSizeBytes) } @@ -282,8 +282,8 @@ func (s *State) validateBlock(b *types.Block) error { if !bytes.Equal(b.ConsensusHash, s.LastConsensusParams.Hash()) { return fmt.Errorf("Wrong Block.Header.ConsensusHash. Expected %X, got %v", s.LastConsensusParams.Hash(), b.ConsensusHash) } - if !bytes.Equal(b.ResultsHash, s.LastResultHash) { - return fmt.Errorf("Wrong Block.Header.ResultsHash. Expected %X, got %v", s.LastResultHash, b.ResultsHash) + if !bytes.Equal(b.LastResultsHash, s.LastResultsHash) { + return fmt.Errorf("Wrong Block.Header.LastResultsHash. Expected %X, got %v", s.LastResultsHash, b.LastResultsHash) } // Validate block LastCommit. diff --git a/state/execution_test.go b/state/execution_test.go index 5cddfc7f8..be072bd6c 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -70,7 +70,7 @@ func TestValidateBlock(t *testing.T) { // wrong results hash fails block = makeBlock(state, 1) - block.ResultsHash = []byte("wrong results hash") + block.LastResultsHash = []byte("wrong results hash") err = state.ValidateBlock(block) require.Error(t, err) } diff --git a/state/state.go b/state/state.go index f0f92715e..164718226 100644 --- a/state/state.go +++ b/state/state.go @@ -75,7 +75,7 @@ type State struct { LastHeightConsensusParamsChanged int64 // Merkle root of the results from executing prev block - LastResultHash []byte + LastResultsHash []byte // The latest AppHash we've received from calling abci.Commit() AppHash []byte @@ -151,7 +151,7 @@ func (s *State) Copy() *State { AppHash: s.AppHash, - LastResultHash: s.LastResultHash, + LastResultsHash: s.LastResultsHash, logger: s.logger, } @@ -377,7 +377,7 @@ func (s *State) setBlockAndValidators(height int64, s.LastConsensusParams = s.ConsensusParams s.ConsensusParams = params - s.LastResultHash = resultsHash + s.LastResultsHash = resultsHash } // GetValidators returns the last and current validator sets. @@ -387,9 +387,9 @@ func (s *State) GetValidators() (last *types.ValidatorSet, current *types.Valida //------------------------------------------------------------------------ -// ABCIResponses retains the deterministic components of the responses +// ABCIResponses retains the responses // of the various ABCI calls during block processing. -// It is persisted to disk before calling Commit. +// It is persisted to disk for each height before calling Commit. type ABCIResponses struct { DeliverTx []*abci.ResponseDeliverTx EndBlock *abci.ResponseEndBlock diff --git a/state/state_test.go b/state/state_test.go index bcd2ba119..b1adc0d02 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -422,7 +422,6 @@ func TestLessThanOneThirdOfVotingPowerPerBlockEnforced(t *testing.T) { height := state.LastBlockHeight + 1 block := makeBlock(state, height) abciResponses := &ABCIResponses{ - Height: height, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: tc.valUpdatesFn(state.Validators)}, } err := state.SetBlockAndValidators(block.Header, types.PartSetHeader{}, abciResponses) @@ -512,7 +511,6 @@ func makeHeaderPartsResponsesValPowerChange(state *State, height int64, block := makeBlock(state, height) abciResponses := &ABCIResponses{ - Height: height, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{}}, } diff --git a/types/block.go b/types/block.go index f0ae57c3b..29775466e 100644 --- a/types/block.go +++ b/types/block.go @@ -150,10 +150,10 @@ type Header struct { DataHash data.Bytes `json:"data_hash"` // transactions // hashes from the app output from the prev block - ValidatorsHash data.Bytes `json:"validators_hash"` // validators for the current block - ConsensusHash data.Bytes `json:"consensus_hash"` // consensus params for current block - AppHash data.Bytes `json:"app_hash"` // state after txs from the previous block - ResultsHash data.Bytes `json:"results_hash"` // root hash of all results from the txs from the previous block + ValidatorsHash data.Bytes `json:"validators_hash"` // validators for the current block + ConsensusHash data.Bytes `json:"consensus_hash"` // consensus params for current block + AppHash data.Bytes `json:"app_hash"` // state after txs from the previous block + LastResultsHash data.Bytes `json:"last_results_hash"` // root hash of all results from the txs from the previous block } // Hash returns the hash of the header. @@ -174,7 +174,7 @@ func (h *Header) Hash() data.Bytes { "Validators": h.ValidatorsHash, "App": h.AppHash, "Consensus": h.ConsensusHash, - "Results": h.ResultsHash, + "Results": h.LastResultsHash, }) } @@ -208,7 +208,7 @@ func (h *Header) StringIndented(indent string) string { indent, h.ValidatorsHash, indent, h.AppHash, indent, h.ConsensusHash, - indent, h.ResultsHash, + indent, h.LastResultsHash, indent, h.Hash()) } diff --git a/types/results.go b/types/results.go index 264234515..29420fbc0 100644 --- a/types/results.go +++ b/types/results.go @@ -1,10 +1,6 @@ package types import ( - "fmt" - - "golang.org/x/crypto/ripemd160" - abci "github.com/tendermint/abci/types" wire "github.com/tendermint/go-wire" "github.com/tendermint/go-wire/data" @@ -14,18 +10,15 @@ import ( //----------------------------------------------------------------------------- // ABCIResult is the deterministic component of a ResponseDeliverTx. +// TODO: add Tags type ABCIResult struct { Code uint32 `json:"code"` Data data.Bytes `json:"data"` } -// Hash returns the canonical json hash of the ABCIResult +// Hash returns the canonical hash of the ABCIResult func (a ABCIResult) Hash() []byte { - // stupid canonical json output, easy to check in any language - bs := fmt.Sprintf(`{"code":%d,"data":"%s"}`, a.Code, a.Data) - var hasher = ripemd160.New() - hasher.Write([]byte(bs)) - return hasher.Sum(nil) + return wire.BinaryRipemd160(a) } // ABCIResults wraps the deliver tx results to return a proof