Skip to content

Revert "Separate Etherbase flag by responsibility (#807)" #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var (
utils.UltraLightFractionFlag,
utils.UltraLightOnlyAnnounceFlag,
utils.WhitelistFlag,
utils.TxFeeRecipientFlag,
utils.EtherbaseFlag,
utils.BLSbaseFlag,
utils.CacheFlag,
utils.CacheDatabaseFlag,
Expand All @@ -104,10 +104,7 @@ var (
utils.ListenPortFlag,
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
utils.MinerEtherbaseFlag,
utils.MinerLegacyEtherbaseFlag,
utils.MiningEnabledFlag,
utils.MinerValidatorFlag,
utils.MinerThreadsFlag,
utils.MinerLegacyThreadsFlag,
utils.MinerNotifyFlag,
Expand Down
5 changes: 1 addition & 4 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.IdentityFlag,
utils.LightKDFFlag,
utils.WhitelistFlag,
utils.TxFeeRecipientFlag,
utils.EtherbaseFlag,
},
},
{
Expand Down Expand Up @@ -189,7 +189,6 @@ var AppHelpFlagGroups = []flagGroup{
Name: "MINER",
Flags: []cli.Flag{
utils.MiningEnabledFlag,
utils.MinerValidatorFlag,
utils.MinerThreadsFlag,
utils.MinerNotifyFlag,
utils.MinerGasPriceFlag,
Expand Down Expand Up @@ -253,8 +252,6 @@ var AppHelpFlagGroups = []flagGroup{
{
Name: "DEPRECATED",
Flags: []cli.Flag{
utils.MinerEtherbaseFlag,
utils.MinerLegacyEtherbaseFlag,
utils.MinerLegacyThreadsFlag,
utils.MinerLegacyGasTargetFlag,
utils.MinerLegacyGasPriceFlag,
Expand Down
84 changes: 23 additions & 61 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ var (
Name: "whitelist",
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
}
TxFeeRecipientFlag = cli.StringFlag{
Name: "tx-fee-recipient",
Usage: "Public address for block transaction fees and gateway fees (default = first account)",
EtherbaseFlag = cli.StringFlag{
Name: "etherbase",
Usage: "Public address for transaction broadcasting and block mining rewards (default = first account)",
Value: "0",
}
BLSbaseFlag = cli.StringFlag{
Expand Down Expand Up @@ -361,11 +361,6 @@ var (
Name: "mine",
Usage: "Enable mining",
}
MinerValidatorFlag = cli.StringFlag{
Name: "miner.validator",
Usage: "Public address for participation in consensus (default = first account)",
Value: "0",
}
MinerThreadsFlag = cli.IntFlag{
Name: "miner.threads",
Usage: "Number of CPU threads to use for mining",
Expand Down Expand Up @@ -1082,73 +1077,41 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
return accs[index], nil
}

// setValidator retrieves the validator address either from the directly specified
// setEtherbase retrieves the etherbase either from the directly specified
// command line flags or from the keystore if CLI indexed.
// `Validator` is the address used to sign consensus messages.
func setValidator(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
// Extract the current validator, new flag overriding legacy etherbase
var validator string
func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
// Extract the current etherbase, new flag overriding legacy one
var etherbase string
if ctx.GlobalIsSet(MinerLegacyEtherbaseFlag.Name) {
validator = ctx.GlobalString(MinerLegacyEtherbaseFlag.Name)
etherbase = ctx.GlobalString(MinerLegacyEtherbaseFlag.Name)
}
if ctx.GlobalIsSet(MinerEtherbaseFlag.Name) {
validator = ctx.GlobalString(MinerEtherbaseFlag.Name)
etherbase = ctx.GlobalString(MinerEtherbaseFlag.Name)
}
if ctx.GlobalIsSet(MinerValidatorFlag.Name) {
if validator != "" {
Fatalf("`etherbase` and `miner.validator` flag should not be used together. `miner.validator` and `tx-fee-recipient` constitute both of `etherbase`' functions")
}
validator = ctx.GlobalString(MinerValidatorFlag.Name)
}
// Convert the validator into an address and configure it
if validator != "" {
account, err := MakeAddress(ks, validator)
if err != nil {
Fatalf("Invalid validator: %v", err)
}
cfg.Miner.Validator = account.Address
}
}

// setTxFeeRecipient retrieves the txFeeRecipient address either from the directly specified
// command line flags or from the keystore if CLI indexed.
// `TxFeeRecipient` is the address earned block transaction fees are sent to.
func setTxFeeRecipient(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
// Extract the current txFeeRecipient, new flag overriding legacy etherbase
var txFeeRecipient string
if ctx.GlobalIsSet(MinerLegacyEtherbaseFlag.Name) {
txFeeRecipient = ctx.GlobalString(MinerLegacyEtherbaseFlag.Name)
}
if ctx.GlobalIsSet(MinerEtherbaseFlag.Name) {
txFeeRecipient = ctx.GlobalString(MinerEtherbaseFlag.Name)
}
if ctx.GlobalIsSet(TxFeeRecipientFlag.Name) {
if txFeeRecipient != "" {
Fatalf("`etherbase` and `tx-fee-recipient` flag should not be used together. `miner.validator` and `tx-fee-recipient` constitute both of `etherbase`' functions")
}
txFeeRecipient = ctx.GlobalString(TxFeeRecipientFlag.Name)
}
// Convert the txFeeRecipient into an address and configure it
if txFeeRecipient != "" {
account, err := MakeAddress(ks, txFeeRecipient)
if err != nil {
Fatalf("Invalid txFeeRecipient: %v", err)
// Convert the etherbase into an address and configure it
if etherbase != "" {
if ks != nil {
account, err := MakeAddress(ks, etherbase)
if err != nil {
Fatalf("Invalid miner etherbase: %v", err)
}
cfg.Miner.Etherbase = account.Address
cfg.Etherbase = account.Address
} else {
Fatalf("No etherbase configured")
}
cfg.TxFeeRecipient = account.Address
}
}

// setBLSbase retrieves the blsbase either from the directly specified
// command line flags or from the keystore if CLI indexed.
// `BLSbase` is the ethereum address which identifies an ECDSA key
// from which the BLS private key used for block finalization in consensus.
func setBLSbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
// Extract the current blsbase, new flag overriding legacy one
// Extract the current etherbase, new flag overriding legacy one
var blsbase string
if ctx.GlobalIsSet(BLSbaseFlag.Name) {
blsbase = ctx.GlobalString(BLSbaseFlag.Name)
}
// Convert the blsbase into an address and configure it
// Convert the etherbase into an address and configure it
if blsbase != "" {
account, err := MakeAddress(ks, blsbase)
if err != nil {
Expand Down Expand Up @@ -1603,8 +1566,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 {
ks = keystores[0].(*keystore.KeyStore)
}
setValidator(ctx, ks, cfg)
setTxFeeRecipient(ctx, ks, cfg)
setEtherbase(ctx, ks, cfg)
setBLSbase(ctx, ks, cfg)
setTxPool(ctx, &cfg.TxPool)
setMiner(ctx, &cfg.Miner)
Expand Down
25 changes: 7 additions & 18 deletions consensus/istanbul/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/consensus/istanbul/backend/internal/enodes"
istanbulCore "github.com/ethereum/go-ethereum/consensus/istanbul/core"
"github.com/ethereum/go-ethereum/consensus/istanbul/validator"
"github.com/ethereum/go-ethereum/contract_comm/blockchain_parameters"
"github.com/ethereum/go-ethereum/contract_comm/election"
comm_errors "github.com/ethereum/go-ethereum/contract_comm/errors"
"github.com/ethereum/go-ethereum/contract_comm/random"
Expand All @@ -47,7 +46,6 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
lru "github.com/hashicorp/golang-lru"
)
Expand Down Expand Up @@ -491,23 +489,14 @@ func (sb *Backend) Verify(proposal istanbul.Proposal) (time.Duration, error) {
return 0, errMismatchTxhashes
}

// Introduced support for setting `header.Coinbase` != `Author(header)` in `1.1.0`
isSupported, isOk, err := blockchain_parameters.IsMinimumVersionAtLeast(1, 1, 0)
// The author should be the first person to propose the block to ensure that randomness matches up.
addr, err := sb.Author(block.Header())
if err != nil {
return 0, err
}
version := &params.VersionInfo{Major: 1, Minor: 1, Patch: 0}
// If we were unable to check the minimum version (ex: BlockchainParameters contract not yet published)
// then fallback to checking our client's version.
if !isSupported || (!isOk && params.CurrentVersionInfo.Cmp(version) == -1) {
addr, err := sb.Author(block.Header())
if err != nil {
sb.logger.Error("Could not recover orignal author of the block to verify against the header's coinbase", "err", err, "func", "Verify")
return 0, errInvalidProposal
} else if addr != block.Header().Coinbase {
sb.logger.Error("Block proposal author and coinbase must be the same when the minimum client version is less than or equal to 1.1.0")
return 0, errInvalidCoinbase
}
sb.logger.Error("Could not recover orignal author of the block to verify the randomness", "err", err, "func", "Verify")
return 0, errInvalidProposal
} else if addr != block.Header().Coinbase {
sb.logger.Error("Original author of the block does not match the coinbase", "addr", addr, "coinbase", block.Header().Coinbase, "func", "Verify")
return 0, errInvalidCoinbase
}

err = sb.VerifyHeader(sb.chain, block.Header(), false)
Expand Down
6 changes: 2 additions & 4 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ func (sb *Backend) VerifySeal(chain consensus.ChainReader, header *types.Header)
// Prepare initializes the consensus fields of a block header according to the
// rules of a particular engine. The changes are executed inline.
func (sb *Backend) Prepare(chain consensus.ChainReader, header *types.Header) error {
// If proposer has not set the `Coinbase` via the `tx-fee-recipient` flag, default to the backend address.
if header.Coinbase == (common.Address{}) {
header.Coinbase = sb.address
}
// unused fields, force to set to empty
header.Coinbase = sb.address

// copy the parent extra data as the header extra data
number := header.Number.Uint64()
Expand Down
5 changes: 2 additions & 3 deletions console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
TxFeeRecipient: common.HexToAddress(testAddress),
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
Miner: miner.Config{
Validator: common.HexToAddress(testAddress),
Etherbase: common.HexToAddress(testAddress),
},
}
if confOverride != nil {
Expand Down
18 changes: 0 additions & 18 deletions contract_comm/blockchain_parameters/blockchain_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,6 @@ func GetMinimumVersion(header *types.Header, state vm.StateDB) (*params.VersionI
return &params.VersionInfo{Major: version[0].Uint64(), Minor: version[1].Uint64(), Patch: version[2].Uint64()}, nil
}

// Returns a triplet (gte, ok, error)
// `gte` is false if the minimum version is less than the input, or if a serious error is caught.
// `ok` is false if something prevented the minimum version check.
// This allows the function to give the caller more information and
// is currently only used to signal the `ContractNotDeployed` errors.
func IsMinimumVersionAtLeast(major uint64, minor uint64, patch uint64) (bool, bool, error) {
desiredVersion := &params.VersionInfo{Major: major, Minor: minor, Patch: patch}
minVersion, err := GetMinimumVersion(nil, nil)
if err != nil {
if err != errors.ErrRegistryContractNotDeployed && err != errors.ErrSmartContractNotDeployed {
log.Debug("Error checking client version", "err", err, "contract", hexutil.Encode(params.BlockchainParametersRegistryId[:]))
return false, false, err
}
return true, false, nil
}
return minVersion.Cmp(desiredVersion) >= 0, true, nil
}

func GetGasCost(header *types.Header, state vm.StateDB, defaultGas uint64, method string) uint64 {
var gas *big.Int
var err error
Expand Down
11 changes: 3 additions & 8 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
}

if random.IsRunning() {
author, err := p.bc.Engine().Author(header)
if err != nil {
return nil, nil, 0, err
}

err = random.RevealAndCommit(block.Randomness().Revealed, block.Randomness().Committed, author, header, statedb)
err := random.RevealAndCommit(block.Randomness().Revealed, block.Randomness().Committed, header.Coinbase, header, statedb)
if err != nil {
return nil, nil, 0, err
}
Expand Down Expand Up @@ -111,14 +106,14 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// and uses the input parameters for its environment. It returns the receipt
// for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc vm.ChainContext, txFeeRecipient *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
func ApplyTransaction(config *params.ChainConfig, bc vm.ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
if err != nil {
return nil, err
}

// Create a new context to be used in the EVM environment
context := vm.NewEVMContext(msg, header, bc, txFeeRecipient)
context := vm.NewEVMContext(msg, header, bc, author)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(context, statedb, config, cfg)
Expand Down
10 changes: 5 additions & 5 deletions core/vm/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ type ChainContext interface {
}

// NewEVMContext creates a new context for use in the EVM.
func NewEVMContext(msg Message, header *types.Header, chain ChainContext, txFeeRecipient *common.Address) Context {
// If we don't have an explicit txFeeRecipient (i.e. not mining), extract from the header
func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author *common.Address) Context {
// If we don't have an explicit author (i.e. not mining), extract from the header
var beneficiary common.Address
if txFeeRecipient == nil {
beneficiary = header.Coinbase
if author == nil {
beneficiary, _ = chain.Engine().Author(header) // Ignore error, we're past header validation
} else {
beneficiary = *txFeeRecipient
beneficiary = *author
}

var engine consensus.Engine
Expand Down
21 changes: 5 additions & 16 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,14 @@ func NewPublicEthereumAPI(e *Ethereum) *PublicEthereumAPI {
return &PublicEthereumAPI{e}
}

// Validator is the address that will sign messages
func (api *PublicEthereumAPI) Validator() (common.Address, error) {
return api.e.Validator()
}

// TxFeeRecipient is the address that mining rewards will be sent to
func (api *PublicEthereumAPI) TxFeeRecipient() (common.Address, error) {
return api.e.TxFeeRecipient()
}

// Etherbase is the address that mining rewards will be sent to (alias for TxFeeRecipient)
// Etherbase is the address that mining rewards will be send to
func (api *PublicEthereumAPI) Etherbase() (common.Address, error) {
return api.TxFeeRecipient()
return api.e.Etherbase()
}

// Coinbase is the address that mining rewards will be sent to (alias for TxFeeRecipient)
// Coinbase is the address that mining rewards will be send to (alias for Etherbase)
func (api *PublicEthereumAPI) Coinbase() (common.Address, error) {
return api.TxFeeRecipient()
return api.Etherbase()
}

// Hashrate returns the POW hashrate
Expand Down Expand Up @@ -154,8 +144,7 @@ func (api *PrivateMinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {

// SetEtherbase sets the etherbase of the miner
func (api *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
api.e.SetValidator(etherbase)
api.e.SetTxFeeRecipient(etherbase)
api.e.SetEtherbase(etherbase)
return true
}

Expand Down
Loading