Skip to content

Commit

Permalink
fixed type differences and undefined vars (#16)
Browse files Browse the repository at this point in the history
* fixed type differences and undefined vars

* resolved changes
  • Loading branch information
dutterbutter authored and ansermino committed Sep 8, 2018
1 parent 69f2029 commit d7c933a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
52 changes: 25 additions & 27 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import (
"bytes"
"errors"
"math/big"
"math/rand"
"sync"
"time"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state"
Expand Down Expand Up @@ -297,7 +295,7 @@ func (a *Aura) verifyHeader(chain consensus.ChainReader, header *types.Header, p
}
// Ensure that the block's difficulty is correct (it should be constant)
if number > 0 {
if header.Difficulty != chain.Config().Difficulty {
if header.Difficulty != chain.Config().Aura.Difficulty {
return errInvalidDifficulty
}
}
Expand Down Expand Up @@ -478,13 +476,13 @@ func (a *Aura) verifySeal(chain consensus.ChainReader, header *types.Header, par
}
}
// Ensure that the difficulty corresponds to the turn-ness of the signer
inturn := snap.inturn(header.Number.Uint64(), signer)
if inturn && header.Difficulty.Cmp(diffInTurn) != 0 {
return errInvalidDifficulty
}
if !inturn && header.Difficulty.Cmp(diffNoTurn) != 0 {
return errInvalidDifficulty
}
//inturn := snap.inturn(header.Number.Uint64(), signer)
//if inturn && header.Difficulty.Cmp(diffInTurn) != 0 {
// return errInvalidDifficulty
//}
//if !inturn && header.Difficulty.Cmp(diffNoTurn) != 0 {
// return errInvalidDifficulty
//}
return nil
}

Expand Down Expand Up @@ -512,18 +510,18 @@ func (a *Aura) Prepare(chain consensus.ChainReader, header *types.Header) error
}
}
// If there's pending proposals, cast a vote on them
if len(addresses) > 0 {
header.Coinbase = addresses[rand.Intn(len(addresses))]
if a.proposals[header.Coinbase] {
copy(header.Nonce[:], nonceAuthVote)
} else {
copy(header.Nonce[:], nonceDropVote)
}
}
//if len(addresses) > 0 {
// header.Coinbase = addresses[rand.Intn(len(addresses))]
// if a.proposals[header.Coinbase] {
// copy(header.Nonce[:], nonceAuthVote)
// } else {
// copy(header.Nonce[:], nonceDropVote)
// }
//}
a.lock.RUnlock()
}
// Set the correct difficulty
header.Difficulty = CalcDifficulty(snap, a.signer)
header.Difficulty = chain.Config().Aura.Difficulty

// Ensure the extra data has all it's components
if len(header.Extra) < extraVanity {
Expand Down Expand Up @@ -613,13 +611,13 @@ func (a *Aura) Seal(chain consensus.ChainReader, block *types.Block, results cha
}
// Sweet, the protocol permits us to sign the block, wait for our time
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now()) // nolint: gosimple
if header.Difficulty.Cmp(diffNoTurn) == 0 {
// It's not our turn explicitly to sign, delay it a bit
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
delay += time.Duration(rand.Int63n(int64(wiggle)))

log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
}
//if header.Difficulty.Cmp(diffNoTurn) == 0 {
// // It's not our turn explicitly to sign, delay it a bit
// wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
// delay += time.Duration(rand.Int63n(int64(wiggle)))
//
// log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
//}
// Sign all the things!
sighash, err := signFn(accounts.Account{Address: signer}, sigHash(header).Bytes())
if err != nil {
Expand Down Expand Up @@ -647,7 +645,7 @@ func (a *Aura) Seal(chain consensus.ChainReader, block *types.Block, results cha

// Returns difficulty constant from config
func (a *Aura) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
return new(big.Int).SetUint64(chain.Config().Aura.Difficulty)
return chain.Config().Aura.Difficulty
}

// SealHash returns the hash of a block prior to it being sealed.
Expand Down
34 changes: 17 additions & 17 deletions consensus/aura/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,23 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
}
}
// Tally up the new vote from the signer
var authorize bool
switch {
case bytes.Equal(header.Nonce[:], nonceAuthVote):
authorize = true
case bytes.Equal(header.Nonce[:], nonceDropVote):
authorize = false
default:
return nil, errInvalidVote
}
if snap.cast(header.Coinbase, authorize) {
snap.Votes = append(snap.Votes, &Vote{
Signer: signer,
Block: number,
Address: header.Coinbase,
Authorize: authorize,
})
}
//var authorize bool
//switch {
//case bytes.Equal(header.Nonce[:], nonceAuthVote):
// authorize = true
//case bytes.Equal(header.Nonce[:], nonceDropVote):
// authorize = false
//default:
// return nil, errInvalidVote
//}
//if snap.cast(header.Coinbase, authorize) {
// snap.Votes = append(snap.Votes, &Vote{
// Signer: signer,
// Block: number,
// Address: header.Coinbase,
// Authorize: authorize,
// })
//}
// If the vote passed, update the list of signers
if tally := snap.Tally[header.Coinbase]; tally.Votes > len(snap.Signers)/2 {
if tally.Authorize {
Expand Down
9 changes: 2 additions & 7 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var (
Authorities: []string{
"0x540a9fe3d2381016dec8ffba7235c6fb00b0f942",
},
Difficulty: 131072,
Difficulty: big.NewInt(131072),
},
}

Expand Down Expand Up @@ -167,7 +167,7 @@ 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
Authorities []string `json:"authorities"` // list of addresses of authorities
Difficulty uint64 `json:"difficulty"` // Constant block difficulty
Difficulty *big.Int `json:"difficulty"` // Constant block difficulty
}

// String implements the stringer interface, returning the consensus engine details.
Expand Down Expand Up @@ -384,8 +384,3 @@ 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 d7c933a

Please sign in to comment.