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

This commit is contained in:
Raneet Debnath 2023-07-04 10:43:28 +05:30 committed by GitHub
parent 6d4e60045a
commit 2b06029fb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 24 deletions

View file

@ -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 {

View file

@ -822,9 +822,9 @@ func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
// 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
@ -1200,31 +1200,33 @@ func (pool *TxPool) AddRemoteSync(txs *types.Transaction) error {
// 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)
@ -1236,7 +1238,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
// in transactions before obtaining lock
if err := pool.validateTxBasics(tx, local); err != nil {
errs = append(errs, ErrAlreadyKnown)
errs[i] = err
invalidTxMeter.Mark(1)
@ -1257,9 +1259,17 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
// 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
nilSlot++
}
// Reorg the pool internals if needed and return
done := pool.requestPromoteExecutables(dirtyAddrs)
if sync {

View file

@ -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()

View file

@ -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()
}

View file

@ -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

View file

@ -5,20 +5,20 @@ import (
"crypto/rand"
"errors"
"fmt"
"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/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/state"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/common/tracing"
@ -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