mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 10:41:41 +00:00
Store LastConsensusHash in State as well
Update all BlockValidation that it matches the last state
This commit is contained in:
committed by
Ethan Buchman
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),
|
block, _ := types.MakeBlock(height, "test_chain", makeTxs(height),
|
||||||
state.LastBlockTotalTx, new(types.Commit),
|
state.LastBlockTotalTx, new(types.Commit),
|
||||||
prevBlockID, valHash, state.AppHash,
|
prevBlockID, valHash, state.AppHash,
|
||||||
state.Params.Hash(),
|
state.LastConsensusHash,
|
||||||
state.Params.BlockGossipParams.BlockPartSizeBytes)
|
state.Params.BlockGossipParams.BlockPartSizeBytes)
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
@ -866,7 +866,7 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
|
|||||||
return types.MakeBlock(cs.Height, cs.state.ChainID, txs,
|
return types.MakeBlock(cs.Height, cs.state.ChainID, txs,
|
||||||
cs.state.LastBlockTotalTx, commit,
|
cs.state.LastBlockTotalTx, commit,
|
||||||
cs.state.LastBlockID, cs.state.Validators.Hash(),
|
cs.state.LastBlockID, cs.state.Validators.Hash(),
|
||||||
cs.state.AppHash, cs.state.Params.Hash(),
|
cs.state.AppHash, cs.state.LastConsensusHash,
|
||||||
cs.state.Params.BlockPartSizeBytes)
|
cs.state.Params.BlockPartSizeBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ func (s *State) ValidateBlock(block *types.Block) error {
|
|||||||
func (s *State) validateBlock(block *types.Block) error {
|
func (s *State) validateBlock(block *types.Block) error {
|
||||||
// Basic block validation.
|
// Basic block validation.
|
||||||
err := block.ValidateBasic(s.ChainID, s.LastBlockHeight,
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func makeBlock(height int64, state *State) *types.Block {
|
|||||||
block, _ := types.MakeBlock(height, chainID,
|
block, _ := types.MakeBlock(height, chainID,
|
||||||
makeTxs(height), state.LastBlockTotalTx,
|
makeTxs(height), state.LastBlockTotalTx,
|
||||||
new(types.Commit), prevBlockID, valHash,
|
new(types.Commit), prevBlockID, valHash,
|
||||||
state.AppHash, state.Params.Hash(), testPartSize)
|
state.AppHash, state.LastConsensusHash, testPartSize)
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,8 @@ type State struct {
|
|||||||
|
|
||||||
// AppHash is updated after Commit
|
// AppHash is updated after Commit
|
||||||
AppHash []byte
|
AppHash []byte
|
||||||
|
// LastConsensusHash is updated after Commit
|
||||||
|
LastConsensusHash []byte
|
||||||
|
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
@ -120,6 +122,7 @@ func (s *State) Copy() *State {
|
|||||||
Validators: s.Validators.Copy(),
|
Validators: s.Validators.Copy(),
|
||||||
LastValidators: s.LastValidators.Copy(),
|
LastValidators: s.LastValidators.Copy(),
|
||||||
AppHash: s.AppHash,
|
AppHash: s.AppHash,
|
||||||
|
LastConsensusHash: s.LastConsensusHash,
|
||||||
LastHeightValidatorsChanged: s.LastHeightValidatorsChanged,
|
LastHeightValidatorsChanged: s.LastHeightValidatorsChanged,
|
||||||
logger: s.logger,
|
logger: s.logger,
|
||||||
ChainID: s.ChainID,
|
ChainID: s.ChainID,
|
||||||
@ -319,6 +322,7 @@ func (s *State) setBlockAndValidators(height int64,
|
|||||||
s.LastBlockTime = blockTime
|
s.LastBlockTime = blockTime
|
||||||
s.Validators = nextValSet
|
s.Validators = nextValSet
|
||||||
s.LastValidators = prevValSet
|
s.LastValidators = prevValSet
|
||||||
|
s.LastConsensusHash = s.Params.Hash()
|
||||||
s.Params = nextParams
|
s.Params = nextParams
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,6 +432,7 @@ func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) (*State, error) {
|
|||||||
Validators: types.NewValidatorSet(validators),
|
Validators: types.NewValidatorSet(validators),
|
||||||
LastValidators: types.NewValidatorSet(nil),
|
LastValidators: types.NewValidatorSet(nil),
|
||||||
AppHash: genDoc.AppHash,
|
AppHash: genDoc.AppHash,
|
||||||
|
LastConsensusHash: genDoc.ConsensusParams.Hash(),
|
||||||
LastHeightValidatorsChanged: 1,
|
LastHeightValidatorsChanged: 1,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -92,10 +92,6 @@ func (b *Block) ValidateBasic(chainID string, lastBlockHeight int64,
|
|||||||
if !bytes.Equal(b.AppHash, appHash) {
|
if !bytes.Equal(b.AppHash, appHash) {
|
||||||
return errors.New(cmn.Fmt("Wrong Block.Header.AppHash. Expected %X, got %v", appHash, b.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) {
|
if !bytes.Equal(b.ConsensusHash, consensusHash) {
|
||||||
return errors.New(cmn.Fmt("Wrong Block.Header.ConsensusHash. Expected %X, got %v", consensusHash, b.ConsensusHash))
|
return errors.New(cmn.Fmt("Wrong Block.Header.ConsensusHash. Expected %X, got %v", consensusHash, b.ConsensusHash))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user