Browse Source

Store LastConsensusHash in State as well

Update all BlockValidation that it matches the last state
pull/972/head
Ethan Frey 7 years ago
committed by Ethan Buchman
parent
commit
960b25408f
6 changed files with 9 additions and 8 deletions
  1. +1
    -1
      blockchain/reactor_test.go
  2. +1
    -1
      consensus/state.go
  3. +1
    -1
      state/execution.go
  4. +1
    -1
      state/execution_test.go
  5. +5
    -0
      state/state.go
  6. +0
    -4
      types/block.go

+ 1
- 1
blockchain/reactor_test.go View File

@ -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
}


+ 1
- 1
consensus/state.go View File

@ -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)
}


+ 1
- 1
state/execution.go View File

@ -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
}


+ 1
- 1
state/execution_test.go View File

@ -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
}


+ 5
- 0
state/state.go View File

@ -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
}

+ 0
- 4
types/block.go View File

@ -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…
Cancel
Save