consensus/istanbul: set header timestamp in Prepare()

This commit is contained in:
mark.lin 2018-02-26 14:44:39 +08:00
parent f7b063302d
commit 51c5e2cb30
1 changed files with 6 additions and 9 deletions

View File

@ -364,6 +364,12 @@ func (sb *backend) Prepare(chain consensus.ChainReader, header *types.Header) er
return err
}
header.Extra = extra
// set header's timestamp
header.Time = new(big.Int).Add(parent.Time, new(big.Int).SetUint64(sb.config.BlockPeriod))
if header.Time.Int64() < time.Now().Unix() {
header.Time = big.NewInt(time.Now().Unix())
}
return nil
}
@ -445,16 +451,7 @@ func (sb *backend) Seal(chain consensus.ChainReader, block *types.Block, stop <-
// update timestamp and signature of the block based on its number of transactions
func (sb *backend) updateBlock(parent *types.Header, block *types.Block) (*types.Block, error) {
// set block period based the number of tx
period := sb.config.BlockPeriod
// set header timestamp
header := block.Header()
header.Time = new(big.Int).Add(parent.Time, new(big.Int).SetUint64(period))
time := now().Unix()
if header.Time.Int64() < time {
header.Time = big.NewInt(time)
}
// sign the hash
seal, err := sb.Sign(sigHash(header).Bytes())
if err != nil {