diff --git a/consensus/aura/aura.go b/consensus/aura/aura.go index 0d41e2e514..080fa8aac7 100644 --- a/consensus/aura/aura.go +++ b/consensus/aura/aura.go @@ -56,13 +56,7 @@ var ( extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity extraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal - nonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer - nonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer. - uncleHash = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW. - - diffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures - diffNoTurn = big.NewInt(1) // Block difficulty for out-of-turn signatures ) // Various error messages to mark blocks invalid. These should be private to @@ -658,25 +652,9 @@ func (a *Aura) Seal(chain consensus.ChainReader, block *types.Block, results cha return nil } -// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty -// that a new block should have based on the previous blocks in the chain and the -// current signer. +// Returns difficulty constant from config func (a *Aura) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int { - snap, err := a.snapshot(chain, parent.Number.Uint64(), parent.Hash(), nil) - if err != nil { - return nil - } - return CalcDifficulty(snap, a.signer) -} - -// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty -// that a new block should have based on the previous blocks in the chain and the -// current signer. -func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int { - if snap.inturn(snap.Number+1, signer) { - return new(big.Int).Set(diffInTurn) - } - return new(big.Int).Set(diffNoTurn) + return new(big.Int).SetUint64(chain.Config().Aura.Difficulty) } // SealHash returns the hash of a block prior to it being sealed. diff --git a/params/config.go b/params/config.go index ee586ae22e..e97ba65b81 100644 --- a/params/config.go +++ b/params/config.go @@ -94,6 +94,7 @@ var ( Aura: &AuraConfig{ Period: 15, Epoch: 30000, + Difficulty: 131072, }, } @@ -162,6 +163,7 @@ type CliqueConfig struct { type AuraConfig struct { Period uint64 `json:"period"` // Number of seconds between blocks to enforce Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint + Difficulty uint64 `json:"difficulty"` // Constant block difficulty } // String implements the stringer interface, returning the consensus engine details. @@ -378,3 +380,8 @@ func (c *ChainConfig) Rules(num *big.Int) Rules { } return Rules{ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num)} } + +// Return diffulty rate for Aura concensus +func (c *AuraConfig) GetDifficulty() (num *big.Int) { + return new(big.Int).SetUint64(c.Difficulty) +}