cmd console, eth, internal/web3ext les miner: changed etherbase to coinbase

Changed etherbase to coinbase, leaving the command line flag in place for
now to avoid a hard cutover.

Fixes #1420
This commit is contained in:
Darrel Herbst 2017-09-27 09:54:24 -04:00
parent 5f8888e116
commit 36e5bdf859
17 changed files with 87 additions and 82 deletions

View file

@ -96,7 +96,7 @@ Specifying the `--testnet` flag however will reconfigure your Geth instance a bi
`geth attach <datadir>/testnet/geth.ipc`. Windows users are not affected by this.
* Instead of connecting the main Ethereum network, the client will connect to the test network,
which uses different P2P bootnodes, different network IDs and genesis states.
*Note: Although there are some internal protective measures to prevent transactions from crossing
over between the main network and test network, you should make sure to always use separate accounts
for play-money and real-money. Unless you manually move accounts, Geth will by default correctly
@ -263,11 +263,11 @@ resources (consider running on a single thread, no need for multiple ones either
instance for mining, run it with all your usual flags, extended by:
```
$ geth <usual-flags> --mine --minerthreads=1 --etherbase=0x0000000000000000000000000000000000000000
$ geth <usual-flags> --mine --minerthreads=1 --coinbase=0x0000000000000000000000000000000000000000
```
Which will start mining blocks and transactions on a single CPU thread, crediting all proceedings to
the account specified by `--etherbase`. You can further tune the mining by changing the default gas
the account specified by `--coinbase`. You can further tune the mining by changing the default gas
limit blocks converge to (`--targetgaslimit`) and the price transactions are accepted at (`--gasprice`).
## Contribution

View file

@ -43,7 +43,7 @@ func TestConsoleWelcome(t *testing.T) {
// Start a geth console, make sure it's cleaned up and terminate the console
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh",
"--coinbase", coinbase, "--shh",
"console")
// Gather all the infos the welcome message needs to contain
@ -59,7 +59,7 @@ func TestConsoleWelcome(t *testing.T) {
Welcome to the Geth JavaScript console!
instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
coinbase: {{.Etherbase}}
coinbase: {{.Coinbase}}
at block: 0 ({{niltime}})
datadir: {{.Datadir}}
modules: {{apis}}
@ -85,7 +85,7 @@ func TestIPCAttachWelcome(t *testing.T) {
// list of ipc modules and shh is included there.
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh", "--ipcpath", ipc)
"--coinbase", coinbase, "--shh", "--ipcpath", ipc)
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs)
@ -99,7 +99,7 @@ func TestHTTPAttachWelcome(t *testing.T) {
port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--rpc", "--rpcport", port)
"--coinbase", coinbase, "--rpc", "--rpcport", port)
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "http://localhost:"+port, httpAPIs)
@ -114,7 +114,7 @@ func TestWSAttachWelcome(t *testing.T) {
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--ws", "--wsport", port)
"--coinbase", coinbase, "--ws", "--wsport", port)
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "ws://localhost:"+port, httpAPIs)
@ -134,7 +134,7 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {
attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
attach.SetTemplateFunc("gover", runtime.Version)
attach.SetTemplateFunc("gethver", func() string { return params.Version })
attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase })
attach.SetTemplateFunc("coinbase", func() string { return geth.Coinbase })
attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
attach.SetTemplateFunc("datadir", func() string { return geth.Datadir })
@ -145,7 +145,7 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {
Welcome to the Geth JavaScript console!
instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
coinbase: {{etherbase}}
coinbase: {{coinbase}}
at block: 0 ({{niltime}}){{if ipc}}
datadir: {{datadir}}{{end}}
modules: {{apis}}

View file

@ -93,7 +93,7 @@ var (
utils.ListenPortFlag,
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
utils.EtherbaseFlag,
utils.CoinbaseFlag,
utils.GasPriceFlag,
utils.MinerThreadsFlag,
utils.MiningEnabledFlag,

View file

@ -38,8 +38,8 @@ type testgeth struct {
*cmdtest.TestCmd
// template variables for expect
Datadir string
Etherbase string
Datadir string
Coinbase string
}
func init() {
@ -72,9 +72,13 @@ func runGeth(t *testing.T, args ...string) *testgeth {
if i < len(args)-1 {
tt.Datadir = args[i+1]
}
case arg == "-coinbase" || arg == "--coinbase":
if i < len(args)-1 {
tt.Coinbase = args[i+1]
}
case arg == "-etherbase" || arg == "--etherbase":
if i < len(args)-1 {
tt.Etherbase = args[i+1]
tt.Coinbase = args[i+1]
}
}
}

View file

@ -179,7 +179,7 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{
utils.MiningEnabledFlag,
utils.MinerThreadsFlag,
utils.EtherbaseFlag,
utils.CoinbaseFlag,
utils.TargetGasLimitFlag,
utils.GasPriceFlag,
utils.ExtraDataFlag,

View file

@ -42,7 +42,7 @@ ADD genesis.json /genesis.json
RUN \
echo 'geth --cache 512 init /genesis.json' > geth.sh && \{{if .Unlock}}
echo 'mkdir -p /root/.ethereum/keystore/ && cp /signer.json /root/.ethereum/keystore/' >> geth.sh && \{{end}}
echo $'geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .BootV4}}--bootnodesv4 {{.BootV4}}{{end}} {{if .BootV5}}--bootnodesv5 {{.BootV5}}{{end}} {{if .Etherbase}}--etherbase {{.Etherbase}} --mine --minerthreads 1{{end}} {{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --targetgaslimit {{.GasTarget}} --gasprice {{.GasPrice}}' >> geth.sh
echo $'geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .BootV4}}--bootnodesv4 {{.BootV4}}{{end}} {{if .BootV5}}--bootnodesv5 {{.BootV5}}{{end}} {{if .Coinbase}}--coinbase {{.Coinbase}} --mine --minerthreads 1{{end}} {{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --targetgaslimit {{.GasTarget}} --gasprice {{.GasPrice}}' >> geth.sh
ENTRYPOINT ["/bin/sh", "geth.sh"]
`
@ -68,7 +68,7 @@ services:
- TOTAL_PEERS={{.TotalPeers}}
- LIGHT_PEERS={{.LightPeers}}
- STATS_NAME={{.Ethstats}}
- MINER_NAME={{.Etherbase}}
- MINER_NAME={{.Coinbase}}
- GAS_TARGET={{.GasTarget}}
- GAS_PRICE={{.GasPrice}}
logging:
@ -84,7 +84,7 @@ services:
// already exists there, it will be overwritten!
func deployNode(client *sshClient, network string, bootv4, bootv5 []string, config *nodeInfos, nocache bool) ([]byte, error) {
kind := "sealnode"
if config.keyJSON == "" && config.etherbase == "" {
if config.keyJSON == "" && config.coinbase == "" {
kind = "bootnode"
bootv4 = make([]string, 0)
bootv5 = make([]string, 0)
@ -106,7 +106,7 @@ func deployNode(client *sshClient, network string, bootv4, bootv5 []string, conf
"BootV4": strings.Join(bootv4, ","),
"BootV5": strings.Join(bootv5, ","),
"Ethstats": config.ethstats,
"Etherbase": config.etherbase,
"Coinbase": config.coinbase,
"GasTarget": uint64(1000000 * config.gasTarget),
"GasPrice": uint64(1000000000 * config.gasPrice),
"Unlock": config.keyJSON != "",
@ -125,7 +125,7 @@ func deployNode(client *sshClient, network string, bootv4, bootv5 []string, conf
"LightPort": config.portFull + 1,
"LightPeers": config.peersLight,
"Ethstats": config.ethstats[:strings.Index(config.ethstats, ":")],
"Etherbase": config.etherbase,
"Coinbase": config.coinbase,
"GasTarget": config.gasTarget,
"GasPrice": config.gasPrice,
})
@ -163,7 +163,7 @@ type nodeInfos struct {
enodeLight string
peersTotal int
peersLight int
etherbase string
coinbase string
keyJSON string
keyPass string
gasTarget float64
@ -189,10 +189,10 @@ func (info *nodeInfos) Report() map[string]string {
report["Gas limit (baseline target)"] = fmt.Sprintf("%0.3f MGas", info.gasTarget)
report["Gas price (minimum accepted)"] = fmt.Sprintf("%0.3f GWei", info.gasPrice)
if info.etherbase != "" {
if info.coinbase != "" {
// Ethash proof-of-work miner
report["Ethash directory"] = info.ethashdir
report["Miner account"] = info.etherbase
report["Miner account"] = info.coinbase
}
if info.keyJSON != "" {
// Clique proof-of-authority signer
@ -264,7 +264,7 @@ func checkNode(client *sshClient, network string, boot bool) (*nodeInfos, error)
peersTotal: totalPeers,
peersLight: lightPeers,
ethstats: infos.envvars["STATS_NAME"],
etherbase: infos.envvars["MINER_NAME"],
coinbase: infos.envvars["MINER_NAME"],
keyJSON: keyJSON,
keyPass: keyPass,
gasTarget: gasTarget,

View file

@ -104,19 +104,19 @@ func (w *wizard) deployNode(boot bool) {
// If the node is a miner/signer, load up needed credentials
if !boot {
if w.conf.Genesis.Config.Ethash != nil {
// Ethash based miners only need an etherbase to mine against
// Ethash based miners only need an coinbase to mine against
fmt.Println()
if infos.etherbase == "" {
if infos.coinbase == "" {
fmt.Printf("What address should the miner user?\n")
for {
if address := w.readAddress(); address != nil {
infos.etherbase = address.Hex()
infos.coinbase = address.Hex()
break
}
}
} else {
fmt.Printf("What address should the miner user? (default = %s)\n", infos.etherbase)
infos.etherbase = w.readDefaultAddress(common.HexToAddress(infos.etherbase)).Hex()
fmt.Printf("What address should the miner user? (default = %s)\n", infos.coinbase)
infos.coinbase = w.readDefaultAddress(common.HexToAddress(infos.coinbase)).Hex()
}
} else if w.conf.Genesis.Config.Clique != nil {
// If a previous signer was already set, offer to reuse it

View file

@ -315,8 +315,8 @@ var (
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
Value: params.GenesisGasLimit.Uint64(),
}
EtherbaseFlag = cli.StringFlag{
Name: "etherbase",
CoinbaseFlag = cli.StringFlag{
Name: "coinbase",
Usage: "Public address for block mining rewards (default = first account created)",
Value: "0",
}
@ -759,15 +759,15 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
return accs[index], nil
}
// setEtherbase retrieves the etherbase either from the directly specified
// setCoinbase retrieves the coinbase either from the directly specified
// command line flags or from the keystore if CLI indexed.
func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
if ctx.GlobalIsSet(EtherbaseFlag.Name) {
account, err := MakeAddress(ks, ctx.GlobalString(EtherbaseFlag.Name))
func setCoinbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
if ctx.GlobalIsSet(CoinbaseFlag.Name) {
account, err := MakeAddress(ks, ctx.GlobalString(CoinbaseFlag.Name))
if err != nil {
Fatalf("Option %q: %v", EtherbaseFlag.Name, err)
Fatalf("Option %q: %v", CoinbaseFlag.Name, err)
}
cfg.Etherbase = account.Address
cfg.Coinbase = account.Address
}
}
@ -985,7 +985,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
checkExclusive(ctx, LightServFlag, SyncModeFlag, "light")
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
setEtherbase(ctx, ks, cfg)
setCoinbase(ctx, ks, cfg)
setGPO(ctx, &cfg.GPO)
setTxPool(ctx, &cfg.TxPool)
setEthash(ctx, cfg)

View file

@ -96,8 +96,8 @@ 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{}),
Etherbase: common.HexToAddress(testAddress),
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
Coinbase: common.HexToAddress(testAddress),
Ethash: ethash.Config{
PowMode: ethash.ModeTest,
},

View file

@ -49,14 +49,14 @@ func NewPublicEthereumAPI(e *Ethereum) *PublicEthereumAPI {
return &PublicEthereumAPI{e}
}
// Etherbase is the address that mining rewards will be send to
// Etherbase is the address that mining rewards will be send to (alias for Coinbase)
func (api *PublicEthereumAPI) Etherbase() (common.Address, error) {
return api.e.Etherbase()
return api.Coinbase()
}
// Coinbase is the address that mining rewards will be send to (alias for Etherbase)
// Coinbase is the address that mining rewards will be send to (
func (api *PublicEthereumAPI) Coinbase() (common.Address, error) {
return api.Etherbase()
return api.e.Coinbase()
}
// Hashrate returns the POW hashrate
@ -187,9 +187,9 @@ func (api *PrivateMinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
return true
}
// SetEtherbase sets the etherbase of the miner
func (api *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
api.e.SetEtherbase(etherbase)
// SetCoinbase sets the coinbase of the miner
func (api *PrivateMinerAPI) SetCoinbase(coinbase common.Address) bool {
api.e.SetCoinbase(coinbase)
return true
}

View file

@ -84,14 +84,14 @@ type Ethereum struct {
ApiBackend *EthApiBackend
miner *miner.Miner
gasPrice *big.Int
etherbase common.Address
miner *miner.Miner
gasPrice *big.Int
coinbase common.Address
networkId uint64
netRPCService *ethapi.PublicNetAPI
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and coinbase)
}
func (s *Ethereum) AddLesServer(ls LesServer) {
@ -130,7 +130,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
stopDbUpgrade: stopDbUpgrade,
networkId: config.NetworkId,
gasPrice: config.GasPrice,
etherbase: config.Etherbase,
coinbase: config.Coinbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks),
}
@ -300,48 +300,49 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb)
}
func (s *Ethereum) Etherbase() (eb common.Address, err error) {
func (s *Ethereum) Coinbase() (eb common.Address, err error) {
s.lock.RLock()
etherbase := s.etherbase
coinbase := s.coinbase
s.lock.RUnlock()
if etherbase != (common.Address{}) {
return etherbase, nil
if coinbase != (common.Address{}) {
return coinbase, nil
}
if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
etherbase := accounts[0].Address
coinbase := accounts[0].Address
s.lock.Lock()
s.etherbase = etherbase
s.coinbase = coinbase
s.lock.Unlock()
log.Info("Etherbase automatically configured", "address", etherbase)
return etherbase, nil
log.Info("Coinbase automatically configured", "address", coinbase)
return coinbase, nil
}
}
return common.Address{}, fmt.Errorf("etherbase must be explicitly specified")
return common.Address{}, fmt.Errorf("coinbase address must be explicitly specified")
}
// set in js console via admin interface or wrapper from cli flags
func (self *Ethereum) SetEtherbase(etherbase common.Address) {
func (self *Ethereum) SetCoinbase(coinbase common.Address) {
self.lock.Lock()
self.etherbase = etherbase
self.coinbase = coinbase
self.lock.Unlock()
self.miner.SetEtherbase(etherbase)
self.miner.SetCoinbase(coinbase)
}
func (s *Ethereum) StartMining(local bool) error {
eb, err := s.Etherbase()
eb, err := s.Coinbase()
if err != nil {
log.Error("Cannot start mining without etherbase", "err", err)
return fmt.Errorf("etherbase missing: %v", err)
log.Error("Cannot start mining without coinbase", "err", err)
return fmt.Errorf("coinbase missing: %v", err)
}
if clique, ok := s.engine.(*clique.Clique); ok {
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
if wallet == nil || err != nil {
log.Error("Etherbase account unavailable locally", "err", err)
log.Error("Coinbase account unavailable locally", "err", err)
return fmt.Errorf("signer missing: %v", err)
}
clique.Authorize(eb, wallet.SignHash)

View file

@ -89,7 +89,7 @@ type Config struct {
DatabaseCache int
// Mining-related options
Etherbase common.Address `toml:",omitempty"`
Coinbase common.Address `toml:",omitempty"`
MinerThreads int `toml:",omitempty"`
ExtraData []byte `toml:",omitempty"`
GasPrice *big.Int

View file

@ -24,7 +24,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
SkipBcVersionCheck bool `toml:"-"`
DatabaseHandles int `toml:"-"`
DatabaseCache int
Etherbase common.Address `toml:",omitempty"`
Coinbase common.Address `toml:",omitempty"`
MinerThreads int `toml:",omitempty"`
ExtraData hexutil.Bytes `toml:",omitempty"`
GasPrice *big.Int
@ -49,7 +49,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.SkipBcVersionCheck = c.SkipBcVersionCheck
enc.DatabaseHandles = c.DatabaseHandles
enc.DatabaseCache = c.DatabaseCache
enc.Etherbase = c.Etherbase
enc.Coinbase = c.Coinbase
enc.MinerThreads = c.MinerThreads
enc.ExtraData = c.ExtraData
enc.GasPrice = c.GasPrice
@ -78,7 +78,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
SkipBcVersionCheck *bool `toml:"-"`
DatabaseHandles *int `toml:"-"`
DatabaseCache *int
Etherbase *common.Address `toml:",omitempty"`
Coinbase *common.Address `toml:",omitempty"`
MinerThreads *int `toml:",omitempty"`
ExtraData hexutil.Bytes `toml:",omitempty"`
GasPrice *big.Int
@ -122,8 +122,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.DatabaseCache != nil {
c.DatabaseCache = *dec.DatabaseCache
}
if dec.Etherbase != nil {
c.Etherbase = *dec.Etherbase
if dec.Coinbase != nil {
c.Coinbase = *dec.Coinbase
}
if dec.MinerThreads != nil {
c.MinerThreads = *dec.MinerThreads

View file

@ -449,8 +449,8 @@ web3._extend({
call: 'miner_stop'
}),
new web3._extend.Method({
name: 'setEtherbase',
call: 'miner_setEtherbase',
name: 'setCoinbase',
call: 'miner_setCoinbase',
params: 1,
inputFormatter: [web3._extend.formatters.inputAddressFormatter]
}),

View file

@ -150,12 +150,12 @@ func lesTopic(genesisHash common.Hash, protocolVersion uint) discv5.Topic {
type LightDummyAPI struct{}
// Etherbase is the address that mining rewards will be send to
// Etherbase is the address that mining rewards will be send to (alias for Coinbase)
func (s *LightDummyAPI) Etherbase() (common.Address, error) {
return common.Address{}, fmt.Errorf("not supported")
}
// Coinbase is the address that mining rewards will be send to (alias for Etherbase)
// Coinbase is the address that mining rewards will be send to
func (s *LightDummyAPI) Coinbase() (common.Address, error) {
return common.Address{}, fmt.Errorf("not supported")
}

View file

@ -105,7 +105,7 @@ out:
func (self *Miner) Start(coinbase common.Address) {
atomic.StoreInt32(&self.shouldStart, 1)
self.worker.setEtherbase(coinbase)
self.worker.setCoinbase(coinbase)
self.coinbase = coinbase
if atomic.LoadInt32(&self.canStart) == 0 {
@ -177,7 +177,7 @@ func (self *Miner) PendingBlock() *types.Block {
return self.worker.pendingBlock()
}
func (self *Miner) SetEtherbase(addr common.Address) {
func (self *Miner) SetCoinbase(addr common.Address) {
self.coinbase = addr
self.worker.setEtherbase(addr)
self.worker.setCoinbase(addr)
}

View file

@ -158,7 +158,7 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase com
return worker
}
func (self *worker) setEtherbase(addr common.Address) {
func (self *worker) setCoinbase(addr common.Address) {
self.mu.Lock()
defer self.mu.Unlock()
self.coinbase = addr