@@ -25,7 +25,6 @@ import (
2525 "time"
2626
2727 "github.com/XinFinOrg/XDPoSChain/common"
28- "github.com/XinFinOrg/XDPoSChain/common/math"
2928 "github.com/XinFinOrg/XDPoSChain/consensus"
3029 "github.com/XinFinOrg/XDPoSChain/consensus/misc"
3130 "github.com/XinFinOrg/XDPoSChain/consensus/misc/eip1559"
@@ -38,18 +37,17 @@ import (
3837
3938// Ethash proof-of-work protocol constants.
4039var (
41- FrontierBlockReward * big.Int = big .NewInt (5e+18 ) // Block reward in wei for successfully mining a block
42- ByzantiumBlockReward * big.Int = big .NewInt (3e+18 ) // Block reward in wei for successfully mining a block upward from Byzantium
43- maxUncles = 2 // Maximum number of uncles allowed in a single block
44- allowedFutureBlockTime = 15 * time . Second // Max time from current time allowed for blocks, before they're considered future blocks
40+ FrontierBlockReward * big.Int = big .NewInt (5e+18 ) // Block reward in wei for successfully mining a block
41+ ByzantiumBlockReward * big.Int = big .NewInt (3e+18 ) // Block reward in wei for successfully mining a block upward from Byzantium
42+ maxUncles = 2 // Maximum number of uncles allowed in a single block
43+ allowedFutureBlockTimeSeconds = int64 ( 15 ) // Max seconds from current time allowed for blocks, before they're considered future blocks
4544)
4645
4746// Various error messages to mark blocks invalid. These should be private to
4847// prevent engine specific errors from being referenced in the remainder of the
4948// codebase, inherently breaking if the engine is swapped out. Please put common
5049// error types into the consensus package.
5150var (
52- errLargeBlockTime = errors .New ("timestamp too big" )
5351 errZeroBlockTime = errors .New ("timestamp equals parent's" )
5452 errTooManyUncles = errors .New ("too many uncles" )
5553 errDuplicateUncle = errors .New ("duplicate uncle" )
@@ -228,20 +226,16 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
228226 return fmt .Errorf ("extra-data too long: %d > %d" , len (header .Extra ), params .MaximumExtraDataSize )
229227 }
230228 // Verify the header's timestamp
231- if uncle {
232- if header .Time .Cmp (math .MaxBig256 ) > 0 {
233- return errLargeBlockTime
234- }
235- } else {
236- if header .Time .Cmp (big .NewInt (time .Now ().Add (allowedFutureBlockTime ).Unix ())) > 0 {
229+ if ! uncle {
230+ if header .Time > uint64 (time .Now ().Unix ()+ allowedFutureBlockTimeSeconds ) {
237231 return consensus .ErrFutureBlock
238232 }
239233 }
240- if header .Time . Cmp ( parent . Time ) <= 0 {
234+ if header .Time <= parent . Time {
241235 return errZeroBlockTime
242236 }
243237 // Verify the block's difficulty based in it's timestamp and parent's difficulty
244- expected := ethash .CalcDifficulty (chain , header .Time . Uint64 () , parent )
238+ expected := ethash .CalcDifficulty (chain , header .Time , parent )
245239
246240 if expected .Cmp (header .Difficulty ) != 0 {
247241 return fmt .Errorf ("invalid difficulty: have %v, want %v" , header .Difficulty , expected )
@@ -331,7 +325,7 @@ func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
331325 // ) + 2^(periodCount - 2)
332326
333327 bigTime := new (big.Int ).SetUint64 (time )
334- bigParentTime := new (big.Int ).Set (parent .Time )
328+ bigParentTime := new (big.Int ).SetUint64 (parent .Time )
335329
336330 // holds intermediate values to make the algo easier to read & audit
337331 x := new (big.Int )
@@ -390,7 +384,7 @@ func calcDifficultyHomestead(time uint64, parent *types.Header) *big.Int {
390384 // ) + 2^(periodCount - 2)
391385
392386 bigTime := new (big.Int ).SetUint64 (time )
393- bigParentTime := new (big.Int ).Set (parent .Time )
387+ bigParentTime := new (big.Int ).SetUint64 (parent .Time )
394388
395389 // holds intermediate values to make the algo easier to read & audit
396390 x := new (big.Int )
@@ -438,7 +432,7 @@ func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int {
438432 bigParentTime := new (big.Int )
439433
440434 bigTime .SetUint64 (time )
441- bigParentTime .Set (parent .Time )
435+ bigParentTime .SetUint64 (parent .Time )
442436
443437 if bigTime .Sub (bigTime , bigParentTime ).Cmp (params .DurationLimit ) < 0 {
444438 diff .Add (parent .Difficulty , adjust )
@@ -512,7 +506,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header)
512506 if parent == nil {
513507 return consensus .ErrUnknownAncestor
514508 }
515- header .Difficulty = ethash .CalcDifficulty (chain , header .Time . Uint64 () , parent )
509+ header .Difficulty = ethash .CalcDifficulty (chain , header .Time , parent )
516510 return nil
517511}
518512
0 commit comments