go-ethereum/consensus/aura/api.go
Dustin Brickwood 50eb9d1527
cmd, consensus, core, eth, mobile, params: Aura proof-of-authority consensus engine implementation
added aura dir and made aura in config.go

changed name of Clique struct to Aura and updated interface functions

go modules added; preparing to write aura consensus

adding goerli flag

goerli flag added

adding configs

Changed signaturs to match aura namespace (#7)

fix errors relating to referencing clique (#9)

configuring genesis

removing duplicate imports

Configuring Aura config, genesis, bytecodes (#10)

* go modules added; preparing to write aura consensus

* adding goerli flag

* goerli flag added

* adding configs

* configuring genesis

* removing duplicate imports

adding configs for aura api

Engine/create (#12)

* added aura to createConsensusEngine

* consensus engine create

Added difficulty retrival from Aura config (#11)

* Added difficulty retrival from Aura config

* Added default difficulty

added bootnodes to bootnodes.go and added authorities array to GoerliChainConfig in params/config.go (#15)

David/verify headers (#13)

* Updated verifyheader logic for Aura

* Fixed errors returned and comments

configuring goerli cli flag

fixed type differences and undefined vars (#16)

* fixed type differences and undefined vars

* resolved changes

flag function fix

Priom/gorli cli flag (#17)

* go modules added; preparing to write aura consensus

* adding goerli flag

* goerli flag added

* adding configs

* core/vm: Hide read only flag from Interpreter interface (#17461) (#6)

Makes Interface interface a bit more stateless and abstract.

Obviously this change is dictated by EVMC design. The EVMC tries to keep the responsibility for EVM features totally inside the VMs, if feasible. This makes VM "stateless" because VM does not need to pass any information between executions, all information is included in parameters of the execute function.

* configuring genesis

* removing duplicate imports

* adding configs for aura api

* configuring goerli cli flag

* flag function fix

* typo fix

Elizabeth/aura (#18)

* 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

Goerli flag keeps connecting to Mainnet (#20)

* go modules added; preparing to write aura consensus

* adding goerli flag

* goerli flag added

* adding configs

* core/vm: Hide read only flag from Interpreter interface (#17461) (#6)

Makes Interface interface a bit more stateless and abstract.

Obviously this change is dictated by EVMC design. The EVMC tries to keep the responsibility for EVM features totally inside the VMs, if feasible. This makes VM "stateless" because VM does not need to pass any information between executions, all information is included in parameters of the execute function.

* configuring genesis

* removing duplicate imports

* adding configs for aura api

* configuring goerli cli flag

* flag function fix

* typo fix

* goerli flag finalized

* config mod

Alternating config for Aura consensus mechanism (#21)

* go modules added; preparing to write aura consensus

* adding goerli flag

* goerli flag added

* adding configs

* core/vm: Hide read only flag from Interpreter interface (#17461) (#6)

Makes Interface interface a bit more stateless and abstract.

Obviously this change is dictated by EVMC design. The EVMC tries to keep the responsibility for EVM features totally inside the VMs, if feasible. This makes VM "stateless" because VM does not need to pass any information between executions, all information is included in parameters of the execute function.

* configuring genesis

* removing duplicate imports

* adding configs for aura api

* configuring goerli cli flag

* flag function fix

* modifying configs

type fix (#22)

--goerli connects to Aura engine by default (#24)

* type fix

* goerli picks up aura by default

goerli networkid changed to 6382

Elizabeth/aura (#23)

* 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

Fix Goerli Params and Genesis (#25)

* params: fix goerli aura params

* params: remove period and epoch from aura config

* core: fix goerli genesis

* cmd/utils: fix goerli flags

Fixes (#26)

* aura: genesis + init-script

* aura genesis

Fixes (#27)

* aura: genesis + init-script

* aura genesis

* core, params: wip on aura, still not working

cmd/utils, consensus/aura, core, eth, params: gofmt

Cleanup temporary files
2018-09-13 23:29:24 +09:00

119 lines
4 KiB
Go

// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package aura
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
)
// API is a user facing RPC API to allow controlling the signer and voting
// mechanisms of the proof-of-authority scheme.
type API struct {
chain consensus.ChainReader
aura *Aura
}
// GetSnapshot retrieves the state snapshot at a given block.
func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
// Retrieve the requested block number (or current if none requested)
var header *types.Header
if number == nil || *number == rpc.LatestBlockNumber {
header = api.chain.CurrentHeader()
} else {
header = api.chain.GetHeaderByNumber(uint64(number.Int64()))
}
// Ensure we have an actually valid block and return its snapshot
if header == nil {
return nil, errUnknownBlock
}
return api.aura.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
}
// GetSnapshotAtHash retrieves the state snapshot at a given block.
func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error) {
header := api.chain.GetHeaderByHash(hash)
if header == nil {
return nil, errUnknownBlock
}
return api.aura.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
}
// GetSigners retrieves the list of authorized signers at the specified block.
func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error) {
// Retrieve the requested block number (or current if none requested)
var header *types.Header
if number == nil || *number == rpc.LatestBlockNumber {
header = api.chain.CurrentHeader()
} else {
header = api.chain.GetHeaderByNumber(uint64(number.Int64()))
}
// Ensure we have an actually valid block and return the signers from its snapshot
if header == nil {
return nil, errUnknownBlock
}
snap, err := api.aura.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
if err != nil {
return nil, err
}
return snap.signers(), nil
}
// GetSignersAtHash retrieves the list of authorized signers at the specified block.
func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) {
header := api.chain.GetHeaderByHash(hash)
if header == nil {
return nil, errUnknownBlock
}
snap, err := api.aura.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
if err != nil {
return nil, err
}
return snap.signers(), nil
}
// Proposals returns the current proposals the node tries to uphold and vote on.
func (api *API) Proposals() map[common.Address]bool {
api.aura.lock.RLock()
defer api.aura.lock.RUnlock()
proposals := make(map[common.Address]bool)
for address, auth := range api.aura.proposals {
proposals[address] = auth
}
return proposals
}
// Propose injects a new authorization proposal that the signer will attempt to
// push through.
func (api *API) Propose(address common.Address, auth bool) {
api.aura.lock.Lock()
defer api.aura.lock.Unlock()
api.aura.proposals[address] = auth
}
// Discard drops a currently running proposal, stopping the signer from casting
// further votes (either for or against).
func (api *API) Discard(address common.Address) {
api.aura.lock.Lock()
defer api.aura.lock.Unlock()
delete(api.aura.proposals, address)
}