@@ -25,7 +25,6 @@ import (
2525 "fmt"
2626 "io/ioutil"
2727 "math/big"
28- "reflect"
2928 "time"
3029
3130 pbftconsensus "github.com/QuarkChain/go-minimal-pbft/consensus"
@@ -111,7 +110,7 @@ func (c *Tendermint) SetBlockChain(chain *core.BlockChain) {
111110 c .chain = chain
112111}
113112
114- func (c * Tendermint ) Init (makeBlock func (parent common.Hash , timestamp uint64 ) (* types.Block , error )) (err error ) {
113+ func (c * Tendermint ) Init (makeBlock func (parent common.Hash , coinbase common. Address , timestamp uint64 ) (* types.Block , error )) (err error ) {
115114 chain := c .chain
116115 // Outbound gossip message queue
117116 sendC := make (chan pbftconsensus.Message , 1000 )
@@ -124,9 +123,9 @@ func (c *Tendermint) Init(makeBlock func(parent common.Hash, timestamp uint64) (
124123 c .rootCtxCancel = rootCtxCancel
125124 c .rootCtx = rootCtx
126125
127- makeFullBlock := func (parentHash common.Hash , timestamp uint64 ) * types.FullBlock {
128-
129- block , err := makeBlock (parentHash , timestamp )
126+ makeFullBlock := func (parentHash common.Hash , coinbase common. Address , timestamp uint64 ) * types.FullBlock {
127+ log . Info ( "Making a block" , "parent" , parentHash )
128+ block , err := makeBlock (parentHash , coinbase , timestamp )
130129 if err != nil {
131130 log .Warn ("makeBlock" , "err" , err )
132131 return nil
@@ -181,11 +180,12 @@ func (c *Tendermint) Init(makeBlock func(parent common.Hash, timestamp uint64) (
181180 c .config .Epoch ,
182181 int64 (c .config .ProposerRepetition ),
183182 )
183+ gcs .LastBlockID = genesis .Hash ()
184184
185185 // consensus
186186 consensusState := pbftconsensus .NewConsensusState (
187187 rootCtx ,
188- pbftconsensus . NewDefaultConsesusConfig () ,
188+ & c . config . ConsensusConfig ,
189189 * gcs ,
190190 store ,
191191 store ,
@@ -280,15 +280,12 @@ func (c *Tendermint) verifyHeader(chain consensus.ChainHeaderReader, header *typ
280280 if header .Time > uint64 (time .Now ().Unix ()) {
281281 return consensus .ErrFutureBlock
282282 }
283- // Checkpoint blocks need to enforce zero beneficiary
284- checkpoint := (number % c .config .Epoch ) == 0
285- if checkpoint && header .Coinbase != (common.Address {}) {
286- return errInvalidCheckpointBeneficiary
287- }
288283
289- nextValidators := c .governance .NextValidators (number )
290- if ! reflect .DeepEqual (nextValidators , header .NextValidators ) {
291- return errors .New ("invalid NextValidators" )
284+ if number % c .config .Epoch != 0 && len (header .NextValidators ) != 0 {
285+ return errors .New ("NextValidators must be empty for non-epoch block" )
286+ }
287+ if len (header .NextValidatorPowers ) != len (header .NextValidators ) {
288+ return errors .New ("NextValidators must have the same len as powers" )
292289 }
293290 if ! bytes .Equal (header .Nonce [:], nonceDefault ) {
294291 return errors .New ("invalid nonce" )
@@ -303,7 +300,7 @@ func (c *Tendermint) verifyHeader(chain consensus.ChainHeaderReader, header *typ
303300 }
304301 // Ensure that the block's difficulty is meaningful (may not be correct at this point)
305302 if number > 0 {
306- if header .Difficulty == nil || (header .Difficulty .Cmp (big .NewInt (0 )) != 0 ) {
303+ if header .Difficulty == nil || (header .Difficulty .Cmp (big .NewInt (1 )) != 0 ) {
307304 return errInvalidDifficulty
308305 }
309306 }
@@ -377,8 +374,15 @@ func (c *Tendermint) Prepare(chain consensus.ChainHeaderReader, header *types.He
377374
378375 header .TimeMs = timestamp
379376 header .Time = timestamp / 1000
377+ header .Difficulty = big .NewInt (1 )
378+
379+ if (number % c .config .Epoch ) != 0 {
380+ header .NextValidators = []common.Address {}
381+ header .NextValidatorPowers = []uint64 {}
382+ } else {
383+ header .NextValidators = c .governance .NextValidators (number )
384+ }
380385
381- header .NextValidators = c .governance .NextValidators (number )
382386 return nil
383387}
384388
0 commit comments