aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/block_chain.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-09-15 21:42:12 +0800
committerobscuren <geffobscura@gmail.com>2014-09-15 21:42:12 +0800
commit33a0dec8a157b9687ca6038f4deb011f3f1f7bdc (patch)
tree197b792e06dc3952df93957a39fdf6e44582ac96 /ethchain/block_chain.go
parent2f614900e82036e3e8f6f6a714efc43e09aca830 (diff)
downloaddexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.gz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.bz2
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.lz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.xz
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.tar.zst
dexon-33a0dec8a157b9687ca6038f4deb011f3f1f7bdc.zip
Improved catching up and refactored
Diffstat (limited to 'ethchain/block_chain.go')
-rw-r--r--ethchain/block_chain.go25
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)