Skip to content

Commit

Permalink
Added difficulty retrival from Aura config (#11)
Browse files Browse the repository at this point in the history
* Added difficulty retrival from Aura config

* Added default difficulty
  • Loading branch information
ansermino authored and noot committed Sep 8, 2018
1 parent 7250469 commit 12b04ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
26 changes: 2 additions & 24 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var (
Aura: &AuraConfig{
Period: 15,
Epoch: 30000,
Difficulty: 131072,
},
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

0 comments on commit 12b04ad

Please sign in to comment.