diff options
Diffstat (limited to 'ethchain/block_chain.go')
-rw-r--r-- | ethchain/block_chain.go | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go index 2d88a0f53..5d0d652df 100644 --- a/ethchain/block_chain.go +++ b/ethchain/block_chain.go @@ -58,24 +58,20 @@ func (bc *BlockChain) NewBlock(coinbase []byte) *Block { block.MinGasPrice = big.NewInt(10000000000000) - if bc.CurrentBlock != nil { - var mul *big.Int - if block.Time < lastBlockTime+5 { - mul = big.NewInt(1) + parent := bc.CurrentBlock + if parent != nil { + diff := new(big.Int) + + adjust := new(big.Int).Rsh(parent.Difficulty, 10) + if block.Time >= lastBlockTime+5 { + diff.Sub(parent.Difficulty, adjust) } else { - mul = big.NewInt(-1) + diff.Add(parent.Difficulty, adjust) } - - diff := new(big.Int) - diff.Add(diff, bc.CurrentBlock.Difficulty) - diff.Div(diff, big.NewInt(1024)) - diff.Mul(diff, mul) - diff.Add(diff, bc.CurrentBlock.Difficulty) block.Difficulty = diff - block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1) - block.GasLimit = block.CalcGasLimit(bc.CurrentBlock) + } return block @@ -159,6 +155,9 @@ func (bc *BlockChain) setLastBlock() { bc.LastBlockHash = block.Hash() bc.LastBlockNumber = block.Number.Uint64() + if bc.LastBlockNumber == 0 { + bc.genesisBlock = block + } } else { AddTestNetFunds(bc.genesisBlock) |