Skip to content

Commit e7e35c1

Browse files
committed
fix miner tests; exposes AddLocal errs to make debuging easier
1 parent 5622c65 commit e7e35c1

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

consensus/ethash/consensus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
281281
slackCoefficient = chain.Config().EIP1559.EIP1559SlackCoefficient
282282
}
283283
if header.GasUsed > header.GasLimit*slackCoefficient {
284-
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d, slack coefficient %d", header.GasUsed, header.GasLimit, chain.Config().EIP1559.EIP1559SlackCoefficient)
284+
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d, slack coefficient %d", header.GasUsed, header.GasLimit, slackCoefficient)
285285
}
286286

287287
// Verify that the gas limit remains within allowed bounds

core/state_transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
var (
3030
errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
31-
ErrEIP1559GasPriceLessThanBaseFee = errors.New("EIP11559 GasPrice is less than the current BaseFee")
31+
ErrEIP1559GasPriceLessThanBaseFee = errors.New("EIP1559 GasPrice is less than the current BaseFee")
3232
)
3333

3434
/*

miner/worker_test.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ func init() {
107107
tx, _ = types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, new(big.Int), nil, nil, nil), types.HomesteadSigner{}, testBankKey)
108108
newTxs = append(newTxs, tx)
109109
newLegacyAndEIP1559Txs = append(newLegacyAndEIP1559Txs, tx)
110-
tx, _ = types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, new(big.Int), new(big.Int)), types.HomesteadSigner{}, testBankKey)
110+
tx, _ = types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, new(big.Int), new(big.Int).SetUint64(params.EIP1559InitialBaseFee*2)), types.HomesteadSigner{}, testBankKey)
111111
pendingEIP1559Txs = append(pendingEIP1559Txs, tx)
112-
tx, _ = types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, new(big.Int), new(big.Int)), types.HomesteadSigner{}, testBankKey)
112+
tx, _ = types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, new(big.Int), new(big.Int).SetUint64(params.EIP1559InitialBaseFee*2)), types.HomesteadSigner{}, testBankKey)
113113
newEIP1559Txs = append(newEIP1559Txs, tx)
114114
rand.Seed(time.Now().UnixNano())
115115
}
@@ -196,13 +196,13 @@ func (b *testWorkerBackend) newRandomTx(creation, eip1559 bool) *types.Transacti
196196
var tx *types.Transaction
197197
if creation {
198198
if eip1559 {
199-
tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode), new(big.Int), new(big.Int)), types.HomesteadSigner{}, testBankKey)
199+
tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode), new(big.Int), new(big.Int).SetUint64(params.EIP1559InitialBaseFee*2)), types.HomesteadSigner{}, testBankKey)
200200
} else {
201201
tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, new(big.Int), common.FromHex(testCode), nil, nil), types.HomesteadSigner{}, testBankKey)
202202
}
203203
} else {
204204
if eip1559 {
205-
tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, new(big.Int), new(big.Int)), types.HomesteadSigner{}, testBankKey)
205+
tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, new(big.Int), new(big.Int).SetUint64(params.EIP1559InitialBaseFee*2)), types.HomesteadSigner{}, testBankKey)
206206
} else {
207207
tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, new(big.Int), nil, nil, nil), types.HomesteadSigner{}, testBankKey)
208208
}
@@ -212,7 +212,12 @@ func (b *testWorkerBackend) newRandomTx(creation, eip1559 bool) *types.Transacti
212212

213213
func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, blocks int, baseFee *big.Int, txs []*types.Transaction) (*worker, *testWorkerBackend) {
214214
backend := newTestWorkerBackend(t, chainConfig, engine, db, blocks, baseFee)
215-
backend.txPool.AddLocals(txs)
215+
errs := backend.txPool.AddLocals(txs)
216+
for _, err := range errs {
217+
if err != nil {
218+
t.Fatal(err.Error())
219+
}
220+
}
216221
w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil, false)
217222
w.setEtherbase(testBankAddress)
218223
return w, backend
@@ -225,16 +230,16 @@ func TestGenerateBlockAndImportClique(t *testing.T) {
225230
testGenerateBlockAndImport(t, true, params.AllCliqueProtocolChanges, nil, pendingTxs, false, false)
226231
}
227232
func TestGenerateBlockAndImportEthashEIP1559(t *testing.T) {
228-
testGenerateBlockAndImport(t, false, params.EIP1559ChainConfig, new(big.Int), pendingLegacyAndEIP1559Txs, true, false)
233+
testGenerateBlockAndImport(t, false, params.EIP1559ChainConfig, new(big.Int).SetUint64(params.EIP1559InitialBaseFee), pendingLegacyAndEIP1559Txs, true, false)
229234
}
230235
func TestGenerateBlockAndImportCliqueEIP1559(t *testing.T) {
231-
testGenerateBlockAndImport(t, true, params.EIP1559ChainConfig, new(big.Int), pendingLegacyAndEIP1559Txs, true, false)
236+
testGenerateBlockAndImport(t, true, params.EIP1559ChainConfig, new(big.Int).SetUint64(params.EIP1559InitialBaseFee), pendingLegacyAndEIP1559Txs, true, false)
232237
}
233238
func TestGenerateBlockAndImportEthashEIP1559Finalized(t *testing.T) {
234-
testGenerateBlockAndImport(t, false, params.EIP1559FinalizedChainConfig, new(big.Int), pendingEIP1559Txs, true, true)
239+
testGenerateBlockAndImport(t, false, params.EIP1559FinalizedChainConfig, new(big.Int).SetUint64(params.EIP1559InitialBaseFee), pendingEIP1559Txs, true, true)
235240
}
236241
func TestGenerateBlockAndImportCliqueEIP1559Finalized(t *testing.T) {
237-
testGenerateBlockAndImport(t, true, params.EIP1559FinalizedChainConfig, new(big.Int), pendingEIP1559Txs, true, true)
242+
testGenerateBlockAndImport(t, true, params.EIP1559FinalizedChainConfig, new(big.Int).SetUint64(params.EIP1559InitialBaseFee), pendingEIP1559Txs, true, true)
238243
}
239244

240245
func testGenerateBlockAndImport(t *testing.T, isClique bool, c *params.ChainConfig, baseFee *big.Int, pTxs []*types.Transaction, eip1559, eip1559Finalized bool) {
@@ -271,8 +276,12 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool, c *params.ChainConf
271276
w.start()
272277

273278
for i := 0; i < 5; i++ {
274-
b.txPool.AddLocal(b.newRandomTx(true, eip1559))
275-
b.txPool.AddLocal(b.newRandomTx(false, eip1559Finalized))
279+
if err := b.txPool.AddLocal(b.newRandomTx(true, eip1559)); err != nil {
280+
t.Fatal(err.Error())
281+
}
282+
if err := b.txPool.AddLocal(b.newRandomTx(false, eip1559Finalized)); err != nil {
283+
t.Fatal(err.Error())
284+
}
276285
w.postSideBlock(core.ChainSideEvent{Block: b.newRandomUncle()})
277286
w.postSideBlock(core.ChainSideEvent{Block: b.newRandomUncle()})
278287

@@ -295,16 +304,16 @@ func TestEmptyWorkClique(t *testing.T) {
295304
testEmptyWork(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingTxs, nil)
296305
}
297306
func TestEmptyWorkEthashEIP1559(t *testing.T) {
298-
testEmptyWork(t, eip1559ChainConfig, ethash.NewFaker(), pendingLegacyAndEIP1559Txs, new(big.Int))
307+
testEmptyWork(t, eip1559ChainConfig, ethash.NewFaker(), pendingLegacyAndEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
299308
}
300309
func TestEmptyWorkCliqueEIP1559(t *testing.T) {
301-
testEmptyWork(t, eip1559CliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingLegacyAndEIP1559Txs, new(big.Int))
310+
testEmptyWork(t, eip1559CliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingLegacyAndEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
302311
}
303312
func TestEmptyWorkEthashEIP1559Finalized(t *testing.T) {
304-
testEmptyWork(t, eip1559FinalizedChainConfig, ethash.NewFaker(), pendingEIP1559Txs, new(big.Int))
313+
testEmptyWork(t, eip1559FinalizedChainConfig, ethash.NewFaker(), pendingEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
305314
}
306315
func TestEmptyWorkCliqueEIP1559Finalized(t *testing.T) {
307-
testEmptyWork(t, eip1559FinalizedCliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingEIP1559Txs, new(big.Int))
316+
testEmptyWork(t, eip1559FinalizedCliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
308317
}
309318

310319
func testEmptyWork(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, pTxs []*types.Transaction, baseFee *big.Int) {
@@ -424,19 +433,19 @@ func TestRegenerateMiningBlockClique(t *testing.T) {
424433
}
425434

426435
func TestRegenerateMiningBlockEthashEIP1559(t *testing.T) {
427-
testRegenerateMiningBlock(t, eip1559ChainConfig, ethash.NewFaker(), pendingLegacyAndEIP1559Txs, newLegacyAndEIP1559Txs, new(big.Int))
436+
testRegenerateMiningBlock(t, eip1559ChainConfig, ethash.NewFaker(), pendingLegacyAndEIP1559Txs, newLegacyAndEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
428437
}
429438

430439
func TestRegenerateMiningBlockCliqueEIP1559(t *testing.T) {
431-
testRegenerateMiningBlock(t, eip1559CliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingLegacyAndEIP1559Txs, newLegacyAndEIP1559Txs, new(big.Int))
440+
testRegenerateMiningBlock(t, eip1559CliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingLegacyAndEIP1559Txs, newLegacyAndEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
432441
}
433442

434443
func TestRegenerateMiningBlockEthashEIP1559Finalized(t *testing.T) {
435-
testRegenerateMiningBlock(t, eip1559FinalizedChainConfig, ethash.NewFaker(), pendingEIP1559Txs, newEIP1559Txs, new(big.Int))
444+
testRegenerateMiningBlock(t, eip1559FinalizedChainConfig, ethash.NewFaker(), pendingEIP1559Txs, newEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
436445
}
437446

438447
func TestRegenerateMiningBlockCliqueEIP1559Finalized(t *testing.T) {
439-
testRegenerateMiningBlock(t, eip1559FinalizedCliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingEIP1559Txs, newEIP1559Txs, new(big.Int))
448+
testRegenerateMiningBlock(t, eip1559FinalizedCliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()), pendingEIP1559Txs, newEIP1559Txs, new(big.Int).SetUint64(params.EIP1559InitialBaseFee))
440449
}
441450

442451
func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, pTxs, nTxs []*types.Transaction, baseFee *big.Int) {
@@ -481,7 +490,12 @@ func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, en
481490
t.Error("new task timeout")
482491
}
483492
}
484-
b.txPool.AddLocals(nTxs)
493+
errs := b.txPool.AddLocals(nTxs)
494+
for _, err := range errs {
495+
if err != nil {
496+
t.Fatal(err.Error())
497+
}
498+
}
485499
time.Sleep(time.Second)
486500

487501
select {

0 commit comments

Comments
 (0)