Use uint64 on ts in chain_manager, block_processor
This commit is contained in:
parent
b08abe64e4
commit
5d6d40f329
|
@ -386,7 +386,7 @@ func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, check
|
||||||
return BlockEqualTSErr
|
return BlockEqualTSErr
|
||||||
}
|
}
|
||||||
|
|
||||||
expd := CalcDifficulty(int64(block.Time), int64(parent.Time()), parent.Difficulty())
|
expd := CalcDifficulty(block.Time, parent.Time(), parent.Difficulty())
|
||||||
if expd.Cmp(block.Difficulty) != 0 {
|
if expd.Cmp(block.Difficulty) != 0 {
|
||||||
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
|
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
|
||||||
Root: state.Root(),
|
Root: state.Root(),
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
Coinbase: parent.Coinbase(),
|
Coinbase: parent.Coinbase(),
|
||||||
Difficulty: CalcDifficulty(int64(time), int64(parent.Time()), parent.Difficulty()),
|
Difficulty: CalcDifficulty(time, parent.Time(), parent.Difficulty()),
|
||||||
GasLimit: CalcGasLimit(parent),
|
GasLimit: CalcGasLimit(parent),
|
||||||
GasUsed: new(big.Int),
|
GasUsed: new(big.Int),
|
||||||
Number: new(big.Int).Add(parent.Number(), common.Big1),
|
Number: new(big.Int).Add(parent.Number(), common.Big1),
|
||||||
|
|
|
@ -611,7 +611,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
||||||
// Allow up to MaxFuture second in the future blocks. If this limit
|
// Allow up to MaxFuture second in the future blocks. If this limit
|
||||||
// is exceeded the chain is discarded and processed at a later time
|
// is exceeded the chain is discarded and processed at a later time
|
||||||
// if given.
|
// if given.
|
||||||
if max := time.Now().Unix() + maxTimeFutureBlocks; int64(block.Time()) > max {
|
if max := uint64(time.Now().Unix()) + maxTimeFutureBlocks; block.Time() > max {
|
||||||
return i, fmt.Errorf("%v: BlockFutureErr, %v > %v", BlockFutureErr, block.Time(), max)
|
return i, fmt.Errorf("%v: BlockFutureErr, %v > %v", BlockFutureErr, block.Time(), max)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,16 @@ import (
|
||||||
// CalcDifficulty is the difficulty adjustment algorithm. It returns
|
// CalcDifficulty is the difficulty adjustment algorithm. It returns
|
||||||
// the difficulty that a new block b should have when created at time
|
// the difficulty that a new block b should have when created at time
|
||||||
// given the parent block's time and difficulty.
|
// given the parent block's time and difficulty.
|
||||||
func CalcDifficulty(time int64, parentTime int64, parentDiff *big.Int) *big.Int {
|
func CalcDifficulty(time, parentTime uint64, parentDiff *big.Int) *big.Int {
|
||||||
diff := new(big.Int)
|
diff := new(big.Int)
|
||||||
adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
|
adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
|
||||||
if big.NewInt(time-parentTime).Cmp(params.DurationLimit) < 0 {
|
bigTime := new(big.Int)
|
||||||
|
bigParentTime := new(big.Int)
|
||||||
|
|
||||||
|
bigTime.SetUint64(time)
|
||||||
|
bigParentTime.SetUint64(parentTime)
|
||||||
|
|
||||||
|
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
||||||
diff.Add(parentDiff, adjust)
|
diff.Add(parentDiff, adjust)
|
||||||
} else {
|
} else {
|
||||||
diff.Sub(parentDiff, adjust)
|
diff.Sub(parentDiff, adjust)
|
||||||
|
|
|
@ -427,7 +427,7 @@ func (self *worker) commitNewWork() {
|
||||||
header := &types.Header{
|
header := &types.Header{
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
Number: num.Add(num, common.Big1),
|
Number: num.Add(num, common.Big1),
|
||||||
Difficulty: core.CalcDifficulty(int64(tstamp), int64(parent.Time()), parent.Difficulty()),
|
Difficulty: core.CalcDifficulty(uint64(tstamp), parent.Time(), parent.Difficulty()),
|
||||||
GasLimit: core.CalcGasLimit(parent),
|
GasLimit: core.CalcGasLimit(parent),
|
||||||
GasUsed: new(big.Int),
|
GasUsed: new(big.Int),
|
||||||
Coinbase: self.coinbase,
|
Coinbase: self.coinbase,
|
||||||
|
|
Loading…
Reference in New Issue