Merge branch 'aura-dev' of github.com:goerli/go-ethereum-aura into aura-dev

This commit is contained in:
priom 2018-09-08 13:18:07 -04:00
commit 4eacd1dc7b
3 changed files with 61 additions and 39 deletions

View file

@ -120,6 +120,7 @@ var (
utils.DeveloperPeriodFlag, utils.DeveloperPeriodFlag,
utils.TestnetFlag, utils.TestnetFlag,
utils.RinkebyFlag, utils.RinkebyFlag,
utils.GoerliFlag,
utils.VMEnableDebugFlag, utils.VMEnableDebugFlag,
utils.NetworkIdFlag, utils.NetworkIdFlag,
utils.RPCCORSDomainFlag, utils.RPCCORSDomainFlag,

View file

@ -454,27 +454,35 @@ func (a *Aura) verifySeal(chain consensus.ChainReader, header *types.Header, par
return errUnknownBlock return errUnknownBlock
} }
// Retrieve the snapshot needed to verify this header and cache it // Retrieve the snapshot needed to verify this header and cache it
snap, err := a.snapshot(chain, number-1, header.ParentHash, parents) // snap, err := a.snapshot(chain, number-1, header.ParentHash, parents)
if err != nil { // if err != nil {
return err // return err
} // }
// Resolve the authorization key and check against signers // Resolve the authorization key and check against signers
signer, err := ecrecover(header, a.signatures) signer, err := ecrecover(header, a.signatures)
if err != nil { if err != nil {
return err 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 return errUnauthorized
} }
for seen, recent := range snap.Recents { // if _, ok := snap.Signers[signer]; !ok {
if recent == signer { // return errUnauthorized
// 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 { // for seen, recent := range snap.Recents {
return errUnauthorized // 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 // Ensure that the difficulty corresponds to the turn-ness of the signer
//inturn := snap.inturn(header.Number.Uint64(), signer) //inturn := snap.inturn(header.Number.Uint64(), signer)
//if inturn && header.Difficulty.Cmp(diffInTurn) != 0 { //if inturn && header.Difficulty.Cmp(diffInTurn) != 0 {
@ -591,24 +599,34 @@ func (a *Aura) Seal(chain consensus.ChainReader, block *types.Block, results cha
signer, signFn := a.signer, a.signFn signer, signFn := a.signer, a.signFn
a.lock.RUnlock() a.lock.RUnlock()
// Bail out if we're unauthorized to sign a block
snap, err := a.snapshot(chain, number-1, header.ParentHash, nil) // check if authorized to sign
if err != nil { step := uint64(time.Now().Unix()) % a.config.Period
return err turn := step % uint64(len(a.config.Authorities))
} if a.signer != a.config.Authorities[turn] {
if _, authorized := snap.Signers[signer]; !authorized { // not authorized to sign
return errUnauthorized return errUnauthorized
} }
// If we're amongst the recent signers, wait for the next block
for seen, recent := range snap.Recents { // Bail out if we're unauthorized to sign a block
if recent == signer { // snap, err := a.snapshot(chain, number-1, header.ParentHash, nil)
// Signer is among recents, only wait if the current block doesn't shift it out // if err != nil {
if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit { // return err
log.Info("Signed recently, must wait for others") // }
return nil // 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 // 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 delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now()) // nolint: gosimple
//if header.Difficulty.Cmp(diffNoTurn) == 0 { //if header.Difficulty.Cmp(diffNoTurn) == 0 {

View file

@ -28,6 +28,7 @@ var (
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177") RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
GoerliGenesisHash = common.HexToHash("0X0000000000000000000000000000000000000000000000000000000000000000")
) )
var ( var (
@ -81,21 +82,21 @@ var (
// GoerliChainConfig contains the chain parameters to run a node on the Goerli test network. // GoerliChainConfig contains the chain parameters to run a node on the Goerli test network.
GoerliChainConfig = &ChainConfig{ GoerliChainConfig = &ChainConfig{
ChainID: big.NewInt(6283), ChainID: big.NewInt(5),
HomesteadBlock: big.NewInt(0), HomesteadBlock: big.NewInt(2),
DAOForkBlock: nil, DAOForkBlock: nil,
DAOForkSupport: true, DAOForkSupport: true,
EIP150Block: big.NewInt(0), EIP150Block: big.NewInt(2),
EIP150Hash: common.HexToHash("0X0000000000000000000000000000000000000000000000000000000000000000"), EIP150Hash: common.HexToHash("0X0000000000000000000000000000000000000000000000000000000000000000"),
EIP155Block: big.NewInt(0), EIP155Block: big.NewInt(3),
EIP158Block: big.NewInt(0), EIP158Block: big.NewInt(3),
ByzantiumBlock: big.NewInt(0), ByzantiumBlock: big.NewInt(1035301),
ConstantinopleBlock: nil, ConstantinopleBlock: nil,
Aura: &AuraConfig{ Aura: &AuraConfig{
Period: 15, Period: 4,
Epoch: 30000, Epoch: 30000,
Authorities: []string{ Authorities: []common.Address{
"0x540a9fe3d2381016dec8ffba7235c6fb00b0f942", common.HexToAddress("0x540a9fe3d2381016dec8ffba7235c6fb00b0f942"),
}, },
Difficulty: big.NewInt(131072), Difficulty: big.NewInt(131072),
}, },
@ -115,6 +116,8 @@ var (
// adding flags to the config to also have to set these fields. // adding flags to the config to also have to set these fields.
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil} AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
AuraProtocolChanges = &ChainConfig{big.NewInt(5), big.NewInt(2), nil, false, big.NewInt(2), common.Hash{}, big.NewInt(3), big.NewInt(3), big.NewInt(1035301), nil, nil, nil, &AuraConfig{Period: 15, Epoch: 30000, Authorities: []string{"0x540a9fe3d2381016dec8ffba7235c6fb00b0f942"}, Difficulty: big.NewInt(131072)}}
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil}
TestRules = TestChainConfig.Rules(new(big.Int)) TestRules = TestChainConfig.Rules(new(big.Int))
) )
@ -166,7 +169,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
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 Difficulty *big.Int `json:"difficulty"` // Constant block difficulty
} }