Skip to content

Commit

Permalink
Elizabeth/aura (#18)
Browse files Browse the repository at this point in the history
* added bootnodes to bootnodes.go and added authorities array to GoerliChainConfig in params/config.go

* Seal() returns errUnauthorized if not authorized to sign block

* verifySeal now checks if signer of block was correct signer at that turn
  • Loading branch information
noot authored Sep 8, 2018
1 parent 2cf98eb commit ba563eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
76 changes: 47 additions & 29 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,27 +454,35 @@ func (a *Aura) verifySeal(chain consensus.ChainReader, header *types.Header, par
return errUnknownBlock
}
// Retrieve the snapshot needed to verify this header and cache it
snap, err := a.snapshot(chain, number-1, header.ParentHash, parents)
if err != nil {
return err
}
// snap, err := a.snapshot(chain, number-1, header.ParentHash, parents)
// if err != nil {
// return err
// }

// Resolve the authorization key and check against signers
signer, err := ecrecover(header, a.signatures)
if err != nil {
return err
}
if _, ok := snap.Signers[signer]; !ok {

ts := header.Time.Uint64()
step := ts % a.config.Period
turn := step % uint64(len(a.config.Authorities))
if signer != a.config.Authorities[turn] {
// not authorized to sign
return errUnauthorized
}
for seen, recent := range snap.Recents {
if recent == signer {
// Signer is among recents, only fail if the current block doesn't shift it out
if limit := uint64(len(snap.Signers)/2 + 1); seen > number-limit {
return errUnauthorized
}
}
}
// if _, ok := snap.Signers[signer]; !ok {
// return errUnauthorized
// }
// for seen, recent := range snap.Recents {
// if recent == signer {
// // Signer is among recents, only fail if the current block doesn't shift it out
// if limit := uint64(len(snap.Signers)/2 + 1); seen > number-limit {
// return errUnauthorized
// }
// }
// }
// 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 {
Expand Down Expand Up @@ -591,24 +599,34 @@ func (a *Aura) Seal(chain consensus.ChainReader, block *types.Block, results cha
signer, signFn := a.signer, a.signFn
a.lock.RUnlock()

// Bail out if we're unauthorized to sign a block
snap, err := a.snapshot(chain, number-1, header.ParentHash, nil)
if err != nil {
return err
}
if _, authorized := snap.Signers[signer]; !authorized {

// check if authorized to sign
step := uint64(time.Now().Unix()) % a.config.Period
turn := step % uint64(len(a.config.Authorities))
if a.signer != a.config.Authorities[turn] {
// not authorized to sign
return errUnauthorized
}
// If we're amongst the recent signers, wait for the next block
for seen, recent := range snap.Recents {
if recent == signer {
// Signer is among recents, only wait if the current block doesn't shift it out
if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit {
log.Info("Signed recently, must wait for others")
return nil
}
}
}

// Bail out if we're unauthorized to sign a block
// snap, err := a.snapshot(chain, number-1, header.ParentHash, nil)
// if err != nil {
// return err
// }
// if _, authorized := snap.Signers[signer]; !authorized {
// return errUnauthorized
// }
// // If we're amongst the recent signers, wait for the next block
// for seen, recent := range snap.Recents {
// if recent == signer {
// // Signer is among recents, only wait if the current block doesn't shift it out
// if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit {
// log.Info("Signed recently, must wait for others")
// return nil
// }
// }
// }

// 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 {
Expand Down
8 changes: 4 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ var (
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: nil,
Aura: &AuraConfig{
Period: 15,
Period: 4,
Epoch: 30000,
Authorities: []string{
"0x540a9fe3d2381016dec8ffba7235c6fb00b0f942",
Authorities: []common.Address{
common.HexToAddress("0x540a9fe3d2381016dec8ffba7235c6fb00b0f942"),
},
Difficulty: big.NewInt(131072),
},
Expand Down Expand Up @@ -166,7 +166,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
Authorities []string `json:"authorities"` // list of addresses of authorities
Authorities []common.Address `json:"authorities"` // list of addresses of authorities
Difficulty *big.Int `json:"difficulty"` // Constant block difficulty
}

Expand Down

0 comments on commit ba563eb

Please sign in to comment.