Commit 285f0b2c authored by Conner Fromknecht's avatar Conner Fromknecht

fix: disable geth preemptive empty block mining logic

When using PoW, geth begins mining on empty blocks before attempting to
select which transactions to include. This optimization is not needed,
as we require that every L2 block have exactly one transaction. This
commit disables this behavior an modifies the tests accordingly. The
test is also expanded to be stricter wrt to testing number of txs and
uncles on all blocks.
parent 639e5b13
...@@ -352,7 +352,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) { ...@@ -352,7 +352,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
select { select {
case <-w.startCh: case <-w.startCh:
clearPending(w.chain.CurrentBlock().NumberU64()) clearPending(w.chain.CurrentBlock().NumberU64())
commit(false, commitInterruptNewHead) commit(true, commitInterruptNewHead)
// Remove this code for the OVM implementation. It is responsible for // Remove this code for the OVM implementation. It is responsible for
// cleaning up memory with the call to `clearPending`, so be sure to // cleaning up memory with the call to `clearPending`, so be sure to
......
...@@ -328,15 +328,35 @@ func TestStreamUncleBlock(t *testing.T) { ...@@ -328,15 +328,35 @@ func TestStreamUncleBlock(t *testing.T) {
taskIndex := 0 taskIndex := 0
w.newTaskHook = func(task *task) { w.newTaskHook = func(task *task) {
if task.block.NumberU64() == 2 { if task.block.NumberU64() == 2 {
// The first task is an empty task, the second // The first task has 1 pending tx, the second one has 1
// one has 1 pending tx, the third one has 1 tx // tx and 1 uncle.
// and 1 uncle. numTxs := len(task.block.Transactions())
if taskIndex == 2 { numUncles := len(task.block.Uncles())
switch taskIndex {
case 0:
if numTxs != 1 {
t.Errorf("expected 1 tx in first task, got: %d", numTxs)
}
if numUncles != 0 {
t.Errorf("expected no uncles in first task, got: %d", numUncles)
}
case 1:
if numTxs != 1 {
t.Errorf("expected 1 tx in second task, got: %d", numTxs)
}
if numUncles != 1 {
t.Errorf("expected 1 uncle in second task, got: %d", numUncles)
}
have := task.block.Header().UncleHash have := task.block.Header().UncleHash
want := types.CalcUncleHash([]*types.Header{b.uncleBlock.Header()}) want := types.CalcUncleHash([]*types.Header{b.uncleBlock.Header()})
if have != want { if have != want {
t.Errorf("uncle hash mismatch: have %s, want %s", have.Hex(), want.Hex()) t.Errorf("uncle hash mismatch: have %s, want %s", have.Hex(), want.Hex())
} }
default:
t.Errorf("only expected two tasks")
} }
taskCh <- struct{}{} taskCh <- struct{}{}
taskIndex += 1 taskIndex += 1
...@@ -350,12 +370,10 @@ func TestStreamUncleBlock(t *testing.T) { ...@@ -350,12 +370,10 @@ func TestStreamUncleBlock(t *testing.T) {
} }
w.start() w.start()
for i := 0; i < 2; i += 1 { select {
select { case <-taskCh:
case <-taskCh: case <-time.NewTimer(time.Second).C:
case <-time.NewTimer(time.Second).C: t.Error("new task timeout")
t.Error("new task timeout")
}
} }
w.postSideBlock(core.ChainSideEvent{Block: b.uncleBlock}) w.postSideBlock(core.ChainSideEvent{Block: b.uncleBlock})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment