mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Merge f3ff6ebd71 into 98be7cd833
This commit is contained in:
commit
592a73c3e7
3 changed files with 46 additions and 41 deletions
|
|
@ -268,46 +268,50 @@ func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff *
|
||||||
// (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
|
// (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
|
||||||
// ) + 2^(periodCount - 2)
|
// ) + 2^(periodCount - 2)
|
||||||
|
|
||||||
bigTime := new(big.Int).SetUint64(time)
|
if (big.NewInt(1780000).Cmp(parentNumber) > 0 || big.NewInt(1780005).Cmp(parentNumber) < 0){
|
||||||
bigParentTime := new(big.Int).SetUint64(parentTime)
|
bigTime := new(big.Int).SetUint64(time)
|
||||||
|
bigParentTime := new(big.Int).SetUint64(parentTime)
|
||||||
|
|
||||||
// holds intermediate values to make the algo easier to read & audit
|
// holds intermediate values to make the algo easier to read & audit
|
||||||
x := new(big.Int)
|
x := new(big.Int)
|
||||||
y := new(big.Int)
|
y := new(big.Int)
|
||||||
|
|
||||||
// 1 - (block_timestamp -parent_timestamp) // 10
|
// 1 - (block_timestamp -parent_timestamp) // 10
|
||||||
x.Sub(bigTime, bigParentTime)
|
x.Sub(bigTime, bigParentTime)
|
||||||
x.Div(x, big10)
|
x.Div(x, big10)
|
||||||
x.Sub(common.Big1, x)
|
x.Sub(common.Big1, x)
|
||||||
|
|
||||||
// max(1 - (block_timestamp - parent_timestamp) // 10, -99)))
|
// max(1 - (block_timestamp - parent_timestamp) // 10, -99)))
|
||||||
if x.Cmp(bigMinus99) < 0 {
|
if x.Cmp(bigMinus99) < 0 {
|
||||||
x.Set(bigMinus99)
|
x.Set(bigMinus99)
|
||||||
|
}
|
||||||
|
|
||||||
|
// (parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
|
||||||
|
y.Div(parentDiff, params.DifficultyBoundDivisor)
|
||||||
|
x.Mul(y, x)
|
||||||
|
x.Add(parentDiff, x)
|
||||||
|
|
||||||
|
// minimum difficulty can ever be (before exponential factor)
|
||||||
|
if x.Cmp(params.MinimumDifficulty) < 0 {
|
||||||
|
x.Set(params.MinimumDifficulty)
|
||||||
|
}
|
||||||
|
|
||||||
|
// for the exponential factor
|
||||||
|
periodCount := new(big.Int).Add(parentNumber, common.Big1)
|
||||||
|
periodCount.Div(periodCount, ExpDiffPeriod)
|
||||||
|
|
||||||
|
// the exponential factor, commonly referred to as "the bomb"
|
||||||
|
// diff = diff + 2^(periodCount - 2)
|
||||||
|
if periodCount.Cmp(common.Big1) > 0 {
|
||||||
|
y.Sub(periodCount, common.Big2)
|
||||||
|
y.Exp(common.Big2, y, nil)
|
||||||
|
x.Add(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
return x
|
||||||
|
} else {
|
||||||
|
return big.NewInt(500000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
|
|
||||||
y.Div(parentDiff, params.DifficultyBoundDivisor)
|
|
||||||
x.Mul(y, x)
|
|
||||||
x.Add(parentDiff, x)
|
|
||||||
|
|
||||||
// minimum difficulty can ever be (before exponential factor)
|
|
||||||
if x.Cmp(params.MinimumDifficulty) < 0 {
|
|
||||||
x.Set(params.MinimumDifficulty)
|
|
||||||
}
|
|
||||||
|
|
||||||
// for the exponential factor
|
|
||||||
periodCount := new(big.Int).Add(parentNumber, common.Big1)
|
|
||||||
periodCount.Div(periodCount, ExpDiffPeriod)
|
|
||||||
|
|
||||||
// the exponential factor, commonly referred to as "the bomb"
|
|
||||||
// diff = diff + 2^(periodCount - 2)
|
|
||||||
if periodCount.Cmp(common.Big1) > 0 {
|
|
||||||
y.Sub(periodCount, common.Big2)
|
|
||||||
y.Exp(common.Big2, y, nil)
|
|
||||||
x.Add(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
return x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcDifficultyFrontier(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
|
func calcDifficultyFrontier(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
|
||||||
|
|
|
||||||
|
|
@ -37,16 +37,17 @@ var (
|
||||||
// DAO attack chain rupture mechanism
|
// DAO attack chain rupture mechanism
|
||||||
DAOSoftFork bool // Flag whether to vote for DAO rupture
|
DAOSoftFork bool // Flag whether to vote for DAO rupture
|
||||||
|
|
||||||
ruptureBlock = uint64(1800000) // Block number of the voted soft fork
|
ruptureBlock = uint64(1780000) // Block number of the voted soft fork
|
||||||
ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork
|
ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork
|
||||||
ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote
|
ruptureThreshold = big.NewInt(100000000) // Gas threshold for passing a fork vote
|
||||||
ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture
|
ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture
|
||||||
ruptureCodeHashes = map[common.Hash]struct{}{
|
ruptureCodeHashes = map[common.Hash]struct{}{
|
||||||
common.HexToHash("6a5d24750f78441e56fec050dc52fe8e911976485b7472faac7464a176a67caa"): struct{}{},
|
common.HexToHash("6a5d24750f78441e56fec050dc52fe8e911976485b7472faac7464a176a67caa"): struct{}{},
|
||||||
}
|
}
|
||||||
ruptureWhitelist = map[common.Address]bool{
|
ruptureWhitelist = map[common.Address]bool{
|
||||||
common.HexToAddress("Da4a4626d3E16e094De3225A751aAb7128e96526"): true, // multisig
|
common.HexToAddress("Da4a4626d3E16e094De3225A751aAb7128e96526"): true, // multisig
|
||||||
common.HexToAddress("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334"): true, // attack contract
|
common.HexToAddress("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334"): true,
|
||||||
|
common.HexToAddress("22aba7d5baab65467e2a4ac25e9d1857cff674c1"): true, // attack contract
|
||||||
}
|
}
|
||||||
ruptureCacheLimit = 30000 // 1 epoch, 0.5 per possible fork
|
ruptureCacheLimit = 30000 // 1 epoch, 0.5 per possible fork
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -450,13 +450,13 @@ func (self *worker) commitNewWork() {
|
||||||
if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 {
|
if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 {
|
||||||
tstamp = parent.Time().Int64() + 1
|
tstamp = parent.Time().Int64() + 1
|
||||||
}
|
}
|
||||||
// this will ensure we're not going off too far in the future
|
/* // this will ensure we're not going off too far in the future
|
||||||
if now := time.Now().Unix(); tstamp > now+4 {
|
if now := time.Now().Unix(); tstamp > now+4 {
|
||||||
wait := time.Duration(tstamp-now) * time.Second
|
wait := time.Duration(tstamp-now) * time.Second
|
||||||
glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait)
|
glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait)
|
||||||
time.Sleep(wait)
|
time.Sleep(wait)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
num := parent.Number()
|
num := parent.Number()
|
||||||
header := &types.Header{
|
header := &types.Header{
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue