Skip to content

Commit

Permalink
Elizabeth/aura (#23)
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

* removed snapshots from prepare and added block rewards to finalize

* removed extravanity in Prepare
  • Loading branch information
noot authored and ChainSafeSystems committed Sep 8, 2018
1 parent 6c50892 commit 65ae9c9
Showing 1 changed file with 22 additions and 46 deletions.
68 changes: 22 additions & 46 deletions consensus/aura/aura.go
Expand Up @@ -331,21 +331,21 @@ func (a *Aura) verifyCascadingFields(chain consensus.ChainReader, header *types.
return ErrInvalidTimestamp
}
// 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
}
// If the block is a checkpoint block, verify the signer list
if number%a.config.Epoch == 0 {
signers := make([]byte, len(snap.Signers)*common.AddressLength)
for i, signer := range snap.signers() {
copy(signers[i*common.AddressLength:], signer[:])
}
extraSuffix := len(header.Extra) - extraSeal
if !bytes.Equal(header.Extra[extraVanity:extraSuffix], signers) {
return errInvalidCheckpointSigners
}
}
// snap, err := a.snapshot(chain, number-1, header.ParentHash, parents)
// if err != nil {
// return err
// }
// // If the block is a checkpoint block, verify the signer list
// if number%a.config.Epoch == 0 {
// signers := make([]byte, len(snap.Signers)*common.AddressLength)
// for i, signer := range snap.signers() {
// copy(signers[i*common.AddressLength:], signer[:])
// }
// extraSuffix := len(header.Extra) - extraSeal
// if !bytes.Equal(header.Extra[extraVanity:extraSuffix], signers) {
// return errInvalidCheckpointSigners
// }
// }
// All basic checks passed, verify the seal and return
return a.verifySeal(chain, header, parents)
}
Expand Down Expand Up @@ -501,46 +501,21 @@ func (a *Aura) Prepare(chain consensus.ChainReader, header *types.Header) error
header.Coinbase = common.Address{}
header.Nonce = types.BlockNonce{}

number := header.Number.Uint64()
// Assemble the voting snapshot to check which votes make sense
snap, err := a.snapshot(chain, number-1, header.ParentHash, nil)
if err != nil {
return err
}
if number%a.config.Epoch != 0 {
a.lock.RLock()

// Gather all the proposals that make sense voting on
addresses := make([]common.Address, 0, len(a.proposals))
for address, authorize := range a.proposals {
if snap.validVote(address, authorize) {
addresses = append(addresses, address)
}
}
// 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)
// }
//}
a.lock.RUnlock()
}
// Set the correct difficulty
header.Difficulty = chain.Config().Aura.Difficulty

// Ensure the extra data has all it's components
if len(header.Extra) < extraVanity {
header.Extra = append(header.Extra, bytes.Repeat([]byte{0x00}, extraVanity-len(header.Extra))...)
}
header.Extra = header.Extra[:extraVanity]
//header.Extra = header.Extra[:extraVanity]

number := header.Number.Uint64()

if number%a.config.Epoch == 0 {
for _, signer := range snap.signers() {
header.Extra = append(header.Extra, signer[:]...)
}
//for _, signer := range snap.signers() {
// header.Extra = append(header.Extra, signer[:]...)
//}
}
header.Extra = append(header.Extra, make([]byte, extraSeal)...)

Expand All @@ -562,6 +537,7 @@ func (a *Aura) Prepare(chain consensus.ChainReader, header *types.Header) error
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given, and returns the final block.
func (a *Aura) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
state.AddBalance(a.signer, big.NewInt(5 * (10 ^ 18)))
// No block rewards in PoA, so the state remains as is and uncles are dropped
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
header.UncleHash = types.CalcUncleHash(nil)
Expand Down

0 comments on commit 65ae9c9

Please sign in to comment.