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

core,eth,miner: fix initial test cases #922

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
var burntContractAddress common.Address

if rules.IsLondon {
burntContractAddress := common.HexToAddress(st.evm.ChainConfig().Bor.CalculateBurntContract(st.evm.Context.BlockNumber.Uint64()))
burntContractAddress = common.HexToAddress(st.evm.ChainConfig().Bor.CalculateBurntContract(st.evm.Context.BlockNumber.Uint64()))
burnAmount = new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee)

if !st.noFeeBurnAndTip {
Expand Down
30 changes: 20 additions & 10 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@
// Transactor should have enough funds to cover the costs
// cost == V + GP * GL
balance := pool.currentState.GetBalance(from)
if balance.Cmp(tx.Cost()) < 0 {
return core.ErrInsufficientFunds
}
// if balance.Cmp(tx.Cost()) < 0 {
// return core.ErrInsufficientFunds
// }
// Verify that replacing transactions will not result in overdraft
list := pool.pending[from]
if list != nil { // Sender already has pending txs
Expand Down Expand Up @@ -1200,31 +1200,33 @@

// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
return pool.AddRemoteSync(tx)
errs := pool.AddRemotesSync([]*types.Transaction{tx})
return errs[0]
}

// AddRemote enqueues a single transaction into the pool if it is valid. This is a convenience
// wrapper around AddRemotes.
func (pool *TxPool) AddRemote(tx *types.Transaction) error {
return pool.addTx(tx, false, false)
errs := pool.AddRemotes([]*types.Transaction{tx})
return errs[0]
}

// addTxs attempts to queue a batch of transactions if they are valid.
func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
// Filter out known ones without obtaining the pool lock or recovering signatures
var (
errs []error
errs = make([]error, len(txs))
news = make([]*types.Transaction, 0, len(txs))

hash common.Hash
)

for _, tx := range txs {
for i, tx := range txs {
// If the transaction is known, pre-set the error slot
hash = tx.Hash()

if pool.all.Get(hash) != nil {
errs = append(errs, ErrAlreadyKnown)
errs[i] = ErrAlreadyKnown

knownTxMeter.Mark(1)

Expand All @@ -1236,7 +1238,7 @@
// in transactions before obtaining lock

if err := pool.validateTxBasics(tx, local); err != nil {
errs = append(errs, ErrAlreadyKnown)
errs[i] = err

invalidTxMeter.Mark(1)

Expand All @@ -1257,9 +1259,17 @@

// Process all the new transaction and merge any errors into the original slice
pool.mu.Lock()
errs, dirtyAddrs := pool.addTxsLocked(news, local)
newErrs, dirtyAddrs := pool.addTxsLocked(news, local)
pool.mu.Unlock()

var nilSlot = 0
for _, err := range newErrs {
for errs[nilSlot] != nil {
nilSlot++
}
errs[nilSlot] = err

Check failure on line 1270 in core/txpool/txpool.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04)

assignments should only be cuddled with other assignments (wsl)
nilSlot++
}
// Reorg the pool internals if needed and return
done := pool.requestPromoteExecutables(dirtyAddrs)
if sync {
Expand Down
2 changes: 0 additions & 2 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1860,8 +1860,6 @@ func TestCheckpointEnforcement67Light(t *testing.T) {
}

func testCheckpointEnforcement(t *testing.T, protocol uint, mode SyncMode) {
t.Parallel()

// Create a new tester with a particular hard coded checkpoint block
tester := newTester(t)
defer tester.terminate()
Expand Down
1 change: 1 addition & 0 deletions eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
Ethash: new(params.EthashConfig),
Bor: params.TestChainConfig.Bor,
}
engine = beacon.NewFaker()
}
Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ type testBackend struct {
// invoked in order to release associated resources.
func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i int, b *core.BlockGen)) *testBackend {
backend := &testBackend{
chainConfig: gspec.Config,
chainConfig: params.TestChainConfig,
engine: ethash.NewFaker(),
chaindb: rawdb.NewMemoryDatabase(),
}
// Generate blocks for testing
gspec.Config = backend.chainConfig
_, blocks, _ := core.GenerateChainWithGenesis(gspec, backend.engine, n, generator)

// Import the canonical chain
Expand Down
12 changes: 6 additions & 6 deletions miner/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"crypto/rand"
"errors"
"fmt"
"math/big"
"os"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/accounts" // nolint:typecheck
"github.com/ethereum/go-ethereum/consensus/bor"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"math/big"
"os"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
Expand Down Expand Up @@ -122,7 +122,7 @@ func newTestWorkerBackend(t TensingObject, chainConfig *params.ChainConfig, engi

genesis := gspec.MustCommit(db)

chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), &core.CacheConfig{TrieDirtyDisabled: true}, &gspec, nil, engine, vm.Config{}, nil, nil, nil)
chain, _ := core.NewBlockChain(db, &core.CacheConfig{TrieDirtyDisabled: true}, &gspec, nil, engine, vm.Config{}, nil, nil, nil)
txpool := txpool.NewTxPool(testTxPoolConfig, chainConfig, chain)

// Generate a small n-block chain and an uncle block for it
Expand Down