Skip to content

Commit

Permalink
cmd console, eth, internal/web3ext les miner: changed etherbase to co…
Browse files Browse the repository at this point in the history
…inbase

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

Fixes ethereum#1420
  • Loading branch information
dherbst committed Sep 27, 2017
1 parent 2ab2a9f commit 1ce601e
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 80 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -261,11 +261,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 bocks 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
Expand Down
14 changes: 7 additions & 7 deletions cmd/geth/consolecmd_test.go
Expand Up @@ -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
Expand All @@ -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}}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 })
Expand All @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Expand Up @@ -88,7 +88,7 @@ var (
utils.ListenPortFlag,
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
utils.EtherbaseFlag,
utils.CoinbaseFlag,
utils.GasPriceFlag,
utils.MinerThreadsFlag,
utils.MiningEnabledFlag,
Expand Down
10 changes: 7 additions & 3 deletions cmd/geth/run_test.go
Expand Up @@ -38,8 +38,8 @@ type testgeth struct {
*cmdtest.TestCmd

// template variables for expect
Datadir string
Etherbase string
Datadir string
Coinbase string
}

func init() {
Expand Down Expand Up @@ -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]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/usage.go
Expand Up @@ -163,7 +163,7 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{
utils.MiningEnabledFlag,
utils.MinerThreadsFlag,
utils.EtherbaseFlag,
utils.CoinbaseFlag,
utils.TargetGasLimitFlag,
utils.GasPriceFlag,
utils.ExtraDataFlag,
Expand Down
14 changes: 7 additions & 7 deletions cmd/puppeth/module_node.go
Expand Up @@ -40,7 +40,7 @@ ADD genesis.json /genesis.json
RUN \
echo 'geth 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{{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{{end}}{{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --targetgaslimit {{.GasTarget}} --gasprice {{.GasPrice}}' >> geth.sh
ENTRYPOINT ["/bin/sh", "geth.sh"]
`
Expand All @@ -65,7 +65,7 @@ services:
- TOTAL_PEERS={{.TotalPeers}}
- LIGHT_PEERS={{.LightPeers}}
- STATS_NAME={{.Ethstats}}
- MINER_NAME={{.Etherbase}}
- MINER_NAME={{.Coinbase}}
- GAS_TARGET={{.GasTarget}}
- GAS_PRICE={{.GasPrice}}
logging:
Expand All @@ -81,7 +81,7 @@ services:
// already exists there, it will be overwritten!
func deployNode(client *sshClient, network string, bootv4, bootv5 []string, config *nodeInfos) ([]byte, error) {
kind := "sealnode"
if config.keyJSON == "" && config.etherbase == "" {
if config.keyJSON == "" && config.coinbase == "" {
kind = "bootnode"
bootv4 = make([]string, 0)
bootv5 = make([]string, 0)
Expand All @@ -103,7 +103,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 != "",
Expand All @@ -121,7 +121,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,
})
Expand Down Expand Up @@ -157,7 +157,7 @@ type nodeInfos struct {
enodeLight string
peersTotal int
peersLight int
etherbase string
coinbase string
keyJSON string
keyPass string
gasTarget float64
Expand Down Expand Up @@ -228,7 +228,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,
Expand Down
10 changes: 5 additions & 5 deletions cmd/puppeth/wizard_node.go
Expand Up @@ -92,19 +92,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
Expand Down
24 changes: 12 additions & 12 deletions cmd/utils/flags.go
Expand Up @@ -283,8 +283,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",
}
Expand Down Expand Up @@ -719,23 +719,23 @@ 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
return
}
accounts := ks.Accounts()
if (cfg.Etherbase == common.Address{}) {
if (cfg.Coinbase == common.Address{}) {
if len(accounts) > 0 {
cfg.Etherbase = accounts[0].Address
cfg.Coinbase = accounts[0].Address
} else {
log.Warn("No etherbase set and no accounts found as default")
log.Warn("No coinbase set and no accounts found as default")
}
}
}
Expand Down Expand Up @@ -926,7 +926,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
checkExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag)

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)
Expand Down
6 changes: 3 additions & 3 deletions console/console_test.go
Expand Up @@ -94,9 +94,9 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: core.DevGenesisBlock(),
Etherbase: common.HexToAddress(testAddress),
PowTest: true,
Genesis: core.DevGenesisBlock(),
Coinbase: common.HexToAddress(testAddress),
PowTest: true,
}
if confOverride != nil {
confOverride(ethConf)
Expand Down
14 changes: 7 additions & 7 deletions eth/api.go
Expand Up @@ -56,14 +56,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
Expand Down Expand Up @@ -194,9 +194,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
}

Expand Down
34 changes: 17 additions & 17 deletions eth/backend.go
Expand Up @@ -83,14 +83,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) {
Expand Down Expand Up @@ -128,7 +128,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),
}
Expand Down Expand Up @@ -292,41 +292,41 @@ 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 {
return accounts[0].Address, nil
}
}
return common.Address{}, fmt.Errorf("etherbase address 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("singer missing: %v", err)
}
clique.Authorize(eb, wallet.SignHash)
Expand Down

0 comments on commit 1ce601e

Please sign in to comment.