mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
Added difficulty retrival from Aura config (#11)
* Added difficulty retrival from Aura config * Added default difficulty
This commit is contained in:
parent
725046997e
commit
12b04adc97
2 changed files with 9 additions and 24 deletions
|
|
@ -56,13 +56,7 @@ var (
|
||||||
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
|
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
|
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.
|
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
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
|
// Returns difficulty constant from config
|
||||||
// that a new block should have based on the previous blocks in the chain and the
|
|
||||||
// current signer.
|
|
||||||
func (a *Aura) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
|
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)
|
return new(big.Int).SetUint64(chain.Config().Aura.Difficulty)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SealHash returns the hash of a block prior to it being sealed.
|
// SealHash returns the hash of a block prior to it being sealed.
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ var (
|
||||||
Aura: &AuraConfig{
|
Aura: &AuraConfig{
|
||||||
Period: 15,
|
Period: 15,
|
||||||
Epoch: 30000,
|
Epoch: 30000,
|
||||||
|
Difficulty: 131072,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,6 +163,7 @@ type CliqueConfig struct {
|
||||||
type AuraConfig struct {
|
type AuraConfig struct {
|
||||||
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
||||||
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
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.
|
// 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 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)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue