Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: delete needless error check #29127

Merged
merged 9 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) {
}
}
} else {
inserter = func(blocks []*types.Block, receipts []types.Receipts) error {
inserter = func(blocks []*types.Block, _ []types.Receipts) error {
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
_, err := chain.InsertChain(blocks)
return err
}
Expand Down Expand Up @@ -2519,7 +2519,7 @@ func testInsertKnownChainDataWithMerging(t *testing.T, typ string, mergeHeight i
}
}
} else {
inserter = func(blocks []*types.Block, receipts []types.Receipts) error {
inserter = func(blocks []*types.Block, _ []types.Receipts) error {
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
i, err := chain.InsertChain(blocks)
if err != nil {
return fmt.Errorf("index %d: %w", i, err)
Expand Down Expand Up @@ -2724,7 +2724,7 @@ func testReorgToShorterRemovesCanonMappingHeaderChain(t *testing.T, scheme strin
}

// Benchmarks large blocks with value transfers to non-existing accounts
func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks int, recipientFn func(uint64) common.Address, dataFn func(uint64) []byte) {
func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks int, recipientFn func(uint64) common.Address) {
var (
signer = types.HomesteadSigner{}
testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
Expand Down Expand Up @@ -2787,10 +2787,7 @@ func BenchmarkBlockChain_1x1000ValueTransferToNonexisting(b *testing.B) {
recipientFn := func(nonce uint64) common.Address {
return common.BigToAddress(new(big.Int).SetUint64(1337 + nonce))
}
dataFn := func(nonce uint64) []byte {
return nil
}
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn, dataFn)
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn)
}

func BenchmarkBlockChain_1x1000ValueTransferToExisting(b *testing.B) {
Expand All @@ -2804,10 +2801,7 @@ func BenchmarkBlockChain_1x1000ValueTransferToExisting(b *testing.B) {
recipientFn := func(nonce uint64) common.Address {
return common.BigToAddress(new(big.Int).SetUint64(1337))
}
dataFn := func(nonce uint64) []byte {
return nil
}
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn, dataFn)
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn)
}

func BenchmarkBlockChain_1x1000Executions(b *testing.B) {
Expand All @@ -2821,10 +2815,7 @@ func BenchmarkBlockChain_1x1000Executions(b *testing.B) {
recipientFn := func(nonce uint64) common.Address {
return common.BigToAddress(new(big.Int).SetUint64(0xc0de))
}
dataFn := func(nonce uint64) []byte {
return nil
}
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn, dataFn)
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn)
}

// Tests that importing a some old blocks, where all blocks are before the
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
}
}

func allBlobTxs(addr common.Address, config *params.ChainConfig) []txData {
func allBlobTxs(addr common.Address, _ *params.ChainConfig) []txData {
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
return []txData{
{
Tx: &types.BlobTx{
Expand Down Expand Up @@ -1244,7 +1244,7 @@ func TestFillBlobTransaction(t *testing.T) {
if len(tc.err) > 0 {
if err == nil {
t.Fatalf("missing error. want: %s", tc.err)
} else if err != nil && err.Error() != tc.err {
} else if err.Error() != tc.err {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the nil-check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because line 1245 has checked if err==nil, so in else, do not need to check err!=nil

t.Fatalf("error mismatch. want: %s, have: %s", tc.err, err.Error())
}
return
Expand Down
2 changes: 1 addition & 1 deletion miner/payload_building_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestBuildPayload(t *testing.T) {
db = rawdb.NewMemoryDatabase()
recipient = common.HexToAddress("0xdeadbeef")
)
w, b := newTestWorker(t, params.TestChainConfig, ethash.NewFaker(), db, 0)
w, b := newTestWorker(t, params.TestChainConfig, ethash.NewFaker(), db)
defer w.close()

timestamp := uint64(time.Now().Unix())
Expand Down
14 changes: 7 additions & 7 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type testWorkerBackend struct {
genesis *core.Genesis
}

func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, n int) *testWorkerBackend {
func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database) *testWorkerBackend {
var gspec = &core.Genesis{
Config: chainConfig,
Alloc: types.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
Expand Down Expand Up @@ -159,8 +159,8 @@ func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
return tx
}

func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, blocks int) (*worker, *testWorkerBackend) {
backend := newTestWorkerBackend(t, chainConfig, engine, db, blocks)
func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database) (*worker, *testWorkerBackend) {
backend := newTestWorkerBackend(t, chainConfig, engine, db)
backend.txPool.Add(pendingTxs, true, false)
w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil, false)
w.setEtherbase(testBankAddress)
Expand All @@ -176,7 +176,7 @@ func TestGenerateAndImportBlock(t *testing.T) {
config.Clique = &params.CliqueConfig{Period: 1, Epoch: 30000}
engine := clique.New(config.Clique, db)

w, b := newTestWorker(t, &config, engine, db, 0)
w, b := newTestWorker(t, &config, engine, db)
defer w.close()

// This test chain imports the mined blocks.
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestEmptyWorkClique(t *testing.T) {
func testEmptyWork(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
defer engine.Close()

w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase())
defer w.close()

taskCh := make(chan struct{}, 2)
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestAdjustIntervalClique(t *testing.T) {
func testAdjustInterval(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
defer engine.Close()

w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase())
defer w.close()

w.skipSealHook = func(task *task) bool {
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestGetSealingWorkPostMerge(t *testing.T) {
func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
defer engine.Close()

w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase())
defer w.close()

w.setExtra([]byte{0x01, 0x02})
Expand Down
4 changes: 2 additions & 2 deletions trie/stacktrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestStacktrieNotModifyValues(t *testing.T) {
}
}

func buildPartialTree(entries []*kv, t *testing.T) map[string]common.Hash {
func buildPartialTree(entries []*kv) map[string]common.Hash {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to have this reference stay. Probably, the person who wrote this once upon a time was debugging something, and maybe used t.Log to emit info. Test-functions passing around the t doesn't hurt, imo

Copy link
Contributor Author

@tomdever tomdever Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does not hurt, and can be used for debugging in the future. I have restored it.

var (
options = NewStackTrieOptions()
nodes = make(map[string]common.Hash)
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestPartialStackTrie(t *testing.T) {
tr.Commit()

for j := 0; j < 100; j++ {
for path, hash := range buildPartialTree(entries, t) {
for path, hash := range buildPartialTree(entries) {
if nodes[path] != hash {
t.Errorf("%v, want %x, got %x", []byte(path), nodes[path], hash)
}
Expand Down