Skip to content

Commit 4eb01b2

Browse files
authored
miner: set etherbase even if mining isn't possible at the moment (#21707)
1 parent bdc7554 commit 4eb01b2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

miner/miner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func (miner *Miner) update() {
128128
events.Unsubscribe()
129129
}
130130
case addr := <-miner.startCh:
131+
miner.SetEtherbase(addr)
131132
if canStart {
132-
miner.SetEtherbase(addr)
133133
miner.worker.start()
134134
}
135135
shouldStart = true

miner/miner_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@ func TestCloseMiner(t *testing.T) {
192192
waitForMiningState(t, miner, false)
193193
}
194194

195+
// TestMinerSetEtherbase checks that etherbase becomes set even if mining isn't
196+
// possible at the moment
197+
func TestMinerSetEtherbase(t *testing.T) {
198+
miner, mux := createMiner(t)
199+
// Start with a 'bad' mining address
200+
miner.Start(common.HexToAddress("0xdead"))
201+
waitForMiningState(t, miner, true)
202+
// Start the downloader
203+
mux.Post(downloader.StartEvent{})
204+
waitForMiningState(t, miner, false)
205+
// Now user tries to configure proper mining address
206+
miner.Start(common.HexToAddress("0x1337"))
207+
// Stop the downloader and wait for the update loop to run
208+
mux.Post(downloader.DoneEvent{})
209+
210+
waitForMiningState(t, miner, true)
211+
// The miner should now be using the good address
212+
if got, exp := miner.coinbase, common.HexToAddress("0x1337"); got != exp {
213+
t.Fatalf("Wrong coinbase, got %x expected %x", got, exp)
214+
}
215+
}
216+
195217
// waitForMiningState waits until either
196218
// * the desired mining state was reached
197219
// * a timeout was reached which fails the test

0 commit comments

Comments
 (0)