Skip to content

Commit

Permalink
Revert "Fix nil pointer dereference errors in tests post upstream mer…
Browse files Browse the repository at this point in the history
…ge changes" (#917)
  • Loading branch information
0xsharma committed Jun 27, 2023
1 parent c66418d commit b0c435c
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 56 deletions.
1 change: 0 additions & 1 deletion consensus/bor/bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestGenesisContractChange(t *testing.T) {
statedb, err := state.New(genesis.Root(), state.NewDatabase(db), nil)
require.NoError(t, err)

genspec.Config = &params.ChainConfig{}
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, genspec, nil, b, vm.Config{}, nil, nil, nil)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ func writeAncientBlock(op ethdb.AncientWriteOp, block *types.Block, header *type
return fmt.Errorf("can't append block %d total difficulty: %v", num, err)
}

if err := op.Append(ChainFreezerBorReceiptTable, num, borReceipts); err != nil {
if err := op.Append(freezerBorReceiptTable, num, borReceipts); err != nil {
return fmt.Errorf("can't append block %d borReceipts: %v", num, err)
}

Expand Down
4 changes: 0 additions & 4 deletions core/rawdb/ancient_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ const (
// ChainFreezerReceiptTable indicates the name of the freezer receipts table.
ChainFreezerReceiptTable = "receipts"

// ChainFreezerBorReceiptTable indicates the name of the freezer bor receipts table.
ChainFreezerBorReceiptTable = "matic-bor-receipts"

// ChainFreezerDifficultyTable indicates the name of the freezer total difficulty table.
ChainFreezerDifficultyTable = "diffs"
)
Expand All @@ -44,7 +41,6 @@ var chainFreezerNoSnappy = map[string]bool{
ChainFreezerHashTable: true,
ChainFreezerBodiesTable: false,
ChainFreezerReceiptTable: false,
ChainFreezerBorReceiptTable: false,
ChainFreezerDifficultyTable: true,
}

Expand Down
5 changes: 4 additions & 1 deletion core/rawdb/bor_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var (

const (
borTxLookupPrefixStr = "matic-bor-tx-lookup-"

// freezerBorReceiptTable indicates the name of the freezer bor receipts table.
freezerBorReceiptTable = "matic-bor-receipts"
)

// borTxLookupKey = borTxLookupPrefix + bor tx hash
Expand All @@ -34,7 +37,7 @@ func ReadBorReceiptRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.Raw
err := db.ReadAncients(func(reader ethdb.AncientReaderOp) error {
// Check if the data is in ancients
if isCanon(reader, number, hash) {
data, _ = reader.Ancient(ChainFreezerBorReceiptTable, number)
data, _ = reader.Ancient(freezerBorReceiptTable, number)

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
// This way they don't have to sync again from block 0 and still be compatible
// for block logs for future blocks. Note that already synced nodes
// won't have past block logs. Newly synced node will have all the data.
if _, ok := freezer.tables[ChainFreezerBorReceiptTable]; ok {
if err := freezer.tables[ChainFreezerBorReceiptTable].Fill(freezer.tables[ChainFreezerHeaderTable].items.Load()); err != nil {
if _, ok := freezer.tables[freezerBorReceiptTable]; ok {
if err := freezer.tables[freezerBorReceiptTable].Fill(freezer.tables[ChainFreezerHeaderTable].items.Load()); err != nil {
return nil, err
}
}
Expand Down
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
45 changes: 22 additions & 23 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,18 +805,26 @@ func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {

// Drop non-local transactions under our own minimal accepted gas price or tip
pool.gasPriceMu.RLock()

if !local && tx.GasTipCapUIntLt(pool.gasPriceUint) {
pool.gasPriceMu.RUnlock()

return ErrUnderpriced
}

pool.gasPriceMu.RUnlock()

// Ensure the transaction adheres to nonce ordering
if pool.currentState.GetNonce(from) > tx.Nonce() {
return core.ErrNonceTooLow
}

// 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
}
// 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 @@ -1169,8 +1177,7 @@ func (pool *TxPool) AddLocals(txs []*types.Transaction) []error {
// AddLocal enqueues a single local transaction into the pool if it is valid. This is
// a convenience wrapper around AddLocals.
func (pool *TxPool) AddLocal(tx *types.Transaction) error {
errs := pool.AddLocals([]*types.Transaction{tx})
return errs[0]
return pool.addTx(tx, !pool.config.NoLocals, true)
}

// AddRemotes enqueues a batch of transactions into the pool if they are valid. If the
Expand Down Expand Up @@ -1199,26 +1206,25 @@ func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
// 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 {
errs := pool.AddRemotes([]*types.Transaction{tx})
return errs[0]
return pool.addTx(tx, false, false)
}

// 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 = make([]error, len(txs))
errs []error
news = make([]*types.Transaction, 0, len(txs))

hash common.Hash
)

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

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

knownTxMeter.Mark(1)

Expand All @@ -1230,7 +1236,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[i] = err
errs = append(errs, ErrAlreadyKnown)

invalidTxMeter.Mark(1)

Expand All @@ -1251,20 +1257,9 @@ 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()
newErrs, dirtyAddrs := pool.addTxsLocked(news, local)
errs, 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 {
Expand Down Expand Up @@ -1333,12 +1328,16 @@ func (pool *TxPool) addTx(tx *types.Transaction, local, sync bool) error {
// The transaction pool lock must be held.
func (pool *TxPool) addTxsLocked(txs []*types.Transaction, local bool) ([]error, *accountSet) {
dirty := newAccountSet(pool.signer)
errs := make([]error, len(txs))

var (
replaced bool
errs []error
)

for _, tx := range txs {
var err error

replaced, err := pool.add(tx, local)
replaced, err = pool.add(tx, local)
if err == nil && !replaced {
dirty.addTx(tx)
}
Expand Down
1 change: 0 additions & 1 deletion core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestBlockEncoding(t *testing.T) {
}
}

// FIXME: Fix after finalising block structure
func TestTxDependencyBlockEncoding(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {

_ = ethereum.engine.VerifyHeader(ethereum.blockchain, ethereum.blockchain.CurrentHeader(), true) // TODO think on it

ethereum.APIBackend.gpo = gasprice.NewOracle(ethereum.APIBackend, gpoParams)
// BOR changes
ethereum.APIBackend.gpo.ProcessCache()
// BOR changes
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/snap/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ func makeAccountTrieNoStorage(n int) (string, *trie.Trie, entrySlice) {
accTrie = trie.NewEmpty(db)
)

entries := make(entrySlice, 0, uint64(n))
entries := make(entrySlice, uint64(n))

for i := uint64(1); i <= uint64(n); i++ {
value, _ := rlp.EncodeToBytes(&types.StateAccount{
Expand Down
1 change: 0 additions & 1 deletion eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
file := file // capture range variable
t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) {
t.Parallel()
t.Log("FILE!!", file.Name())

var (
test = new(callTracerTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@
"clique": {
"period": 0,
"epoch": 30000
},
"bor": {
"jaipurBlock": 0,
"delhiBlock": 0,
"period": {
"0": 2
},
"producerDelay": {
"0": 4
},
"sprint": {
"0": 16
},
"backupMultiplier": {
"0": 2
},
"burntContract": {
"0": "0x000000000000000000000000000000000000dead"
}
}
}
},
Expand Down

0 comments on commit b0c435c

Please sign in to comment.