aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-15 18:24:29 +0800
committerobscuren <geffobscura@gmail.com>2015-05-15 18:24:29 +0800
commitf6669db0010892d06722ae992baaf4a228d4467a (patch)
tree3f7935bd9dc760310183083b184efea78c1aa5fc /core
parentb71091e337fef7e3cfad56c61c97a42094e87531 (diff)
downloadgo-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.tar
go-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.tar.gz
go-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.tar.bz2
go-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.tar.lz
go-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.tar.xz
go-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.tar.zst
go-tangerine-f6669db0010892d06722ae992baaf4a228d4467a.zip
core: fixed mining strategy
Diffstat (limited to 'core')
-rw-r--r--core/chain_makers.go2
-rw-r--r--core/chain_manager.go24
2 files changed, 16 insertions, 10 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 5cd7ab4ab..acf7b39cc 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -98,7 +98,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db common.Dat
fmt.Println("process with parent failed", err)
panic(err)
}
- block.Td = CalculateTD(block, parent)
+ block.Td = CalcTD(block, parent)
blocks[i] = block
parent = block
}
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 2c96c243c..a0839ad41 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -48,7 +48,7 @@ func CalcDifficulty(block, parent *types.Header) *big.Int {
return diff
}
-func CalculateTD(block, parent *types.Block) *big.Int {
+func CalcTD(block, parent *types.Block) *big.Int {
if parent == nil {
return block.Difficulty()
}
@@ -59,14 +59,20 @@ func CalculateTD(block, parent *types.Block) *big.Int {
}
func CalcGasLimit(parent *types.Block) *big.Int {
- // ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024
- previous := new(big.Int).Mul(big.NewInt(1024-1), parent.GasLimit())
- current := new(big.Rat).Mul(new(big.Rat).SetInt(parent.GasUsed()), big.NewRat(6, 5))
- curInt := new(big.Int).Div(current.Num(), current.Denom())
+ decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
+ contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3))
+ contrib = contrib.Div(contrib, big.NewInt(2))
+ contrib = contrib.Div(contrib, params.GasLimitBoundDivisor)
- result := new(big.Int).Add(previous, curInt)
- result.Div(result, big.NewInt(1024))
- return common.BigMax(params.GenesisGasLimit, result)
+ gl := new(big.Int).Sub(parent.GasLimit(), decay)
+ gl = gl.Add(gl, contrib)
+ gl = common.BigMax(gl, params.MinGasLimit)
+
+ if gl.Cmp(params.GenesisGasLimit) < 0 {
+ gl2 := new(big.Int).Add(parent.GasLimit(), decay)
+ return common.BigMin(params.GenesisGasLimit, gl2)
+ }
+ return gl
}
type ChainManager struct {
@@ -525,7 +531,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
}
// Setting block.Td regardless of error (known for example) prevents errors down the line
// in the protocol handler
- block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
+ block.Td = new(big.Int).Set(CalcTD(block, self.GetBlock(block.ParentHash())))
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).