Store LastConsensusHash in State as well
Update all BlockValidation that it matches the last state
This commit is contained in:
parent
45bc106de7
commit
960b25408f
|
@ -112,7 +112,7 @@ func makeBlock(height int64, state *sm.State) *types.Block {
|
|||
block, _ := types.MakeBlock(height, "test_chain", makeTxs(height),
|
||||
state.LastBlockTotalTx, new(types.Commit),
|
||||
prevBlockID, valHash, state.AppHash,
|
||||
state.Params.Hash(),
|
||||
state.LastConsensusHash,
|
||||
state.Params.BlockGossipParams.BlockPartSizeBytes)
|
||||
return block
|
||||
}
|
||||
|
|
|
@ -866,7 +866,7 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
|
|||
return types.MakeBlock(cs.Height, cs.state.ChainID, txs,
|
||||
cs.state.LastBlockTotalTx, commit,
|
||||
cs.state.LastBlockID, cs.state.Validators.Hash(),
|
||||
cs.state.AppHash, cs.state.Params.Hash(),
|
||||
cs.state.AppHash, cs.state.LastConsensusHash,
|
||||
cs.state.Params.BlockPartSizeBytes)
|
||||
}
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ func (s *State) ValidateBlock(block *types.Block) error {
|
|||
func (s *State) validateBlock(block *types.Block) error {
|
||||
// Basic block validation.
|
||||
err := block.ValidateBasic(s.ChainID, s.LastBlockHeight,
|
||||
s.LastBlockTotalTx, s.LastBlockID, s.LastBlockTime, s.AppHash, s.Params.Hash())
|
||||
s.LastBlockTotalTx, s.LastBlockID, s.LastBlockTime, s.AppHash, s.LastConsensusHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func makeBlock(height int64, state *State) *types.Block {
|
|||
block, _ := types.MakeBlock(height, chainID,
|
||||
makeTxs(height), state.LastBlockTotalTx,
|
||||
new(types.Commit), prevBlockID, valHash,
|
||||
state.AppHash, state.Params.Hash(), testPartSize)
|
||||
state.AppHash, state.LastConsensusHash, testPartSize)
|
||||
return block
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ type State struct {
|
|||
|
||||
// AppHash is updated after Commit
|
||||
AppHash []byte
|
||||
// LastConsensusHash is updated after Commit
|
||||
LastConsensusHash []byte
|
||||
|
||||
logger log.Logger
|
||||
}
|
||||
|
@ -120,6 +122,7 @@ func (s *State) Copy() *State {
|
|||
Validators: s.Validators.Copy(),
|
||||
LastValidators: s.LastValidators.Copy(),
|
||||
AppHash: s.AppHash,
|
||||
LastConsensusHash: s.LastConsensusHash,
|
||||
LastHeightValidatorsChanged: s.LastHeightValidatorsChanged,
|
||||
logger: s.logger,
|
||||
ChainID: s.ChainID,
|
||||
|
@ -319,6 +322,7 @@ func (s *State) setBlockAndValidators(height int64,
|
|||
s.LastBlockTime = blockTime
|
||||
s.Validators = nextValSet
|
||||
s.LastValidators = prevValSet
|
||||
s.LastConsensusHash = s.Params.Hash()
|
||||
s.Params = nextParams
|
||||
}
|
||||
|
||||
|
@ -428,6 +432,7 @@ func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) (*State, error) {
|
|||
Validators: types.NewValidatorSet(validators),
|
||||
LastValidators: types.NewValidatorSet(nil),
|
||||
AppHash: genDoc.AppHash,
|
||||
LastConsensusHash: genDoc.ConsensusParams.Hash(),
|
||||
LastHeightValidatorsChanged: 1,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -92,10 +92,6 @@ func (b *Block) ValidateBasic(chainID string, lastBlockHeight int64,
|
|||
if !bytes.Equal(b.AppHash, appHash) {
|
||||
return errors.New(cmn.Fmt("Wrong Block.Header.AppHash. Expected %X, got %v", appHash, b.AppHash))
|
||||
}
|
||||
// TODO: make testing easier
|
||||
if len(consensusHash) == 0 {
|
||||
panic("food")
|
||||
}
|
||||
if !bytes.Equal(b.ConsensusHash, consensusHash) {
|
||||
return errors.New(cmn.Fmt("Wrong Block.Header.ConsensusHash. Expected %X, got %v", consensusHash, b.ConsensusHash))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue