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

fix : runtime testcases #910

Merged
merged 28 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
64486d0
fix : runtime testcases
0xsharma Jun 26, 2023
392bebd
fix : testcase : config, addTxWithChain, burnAmount
0xsharma Jun 26, 2023
36e2382
fix : ethhash bor burn contract
0xsharma Jun 26, 2023
a25bc77
fix : genspec config
0xsharma Jun 26, 2023
6d4e600
fix : freezer, TestStateProcessorErrors
0xsharma Jul 3, 2023
2b06029
core,eth,miner: fix initial test cases (#922)
Raneet10 Jul 4, 2023
2ad1e0f
fix : TestTransactionIndices, testBeaconSync
0xsharma Jul 4, 2023
616e33f
fix : TestBeaconSync66
0xsharma Jul 4, 2023
b605c38
core,eth: fix TestDeduplication, TestSyncAccountPerformance, TestTrac…
Raneet10 Jul 4, 2023
0a7ab3a
Merge pull request #924 from maticnetwork/raneet10/pos-1600
Raneet10 Jul 4, 2023
e2292bf
fix : TestTxIndexer
0xsharma Jul 4, 2023
25be127
rm : multiple coinbase balance
0xsharma Jul 5, 2023
a8aca88
fix : testCommitInterruptExperimentBor
0xsharma Jul 5, 2023
a454c46
adding balance send to burntcontract back
0xsharma Jul 5, 2023
46882e8
Fix header encoding test
cffls Jul 5, 2023
60b85cf
core,eth/tracers: fix TestPrestateWithDiffModeTracer
Raneet10 Jul 6, 2023
ddce55e
consensus/bor,eth/filters,miner,params,tests: fix mocks
Raneet10 Jul 12, 2023
c5b74b6
fix : TestGraphQLConcurrentResolvers
0xsharma Jul 12, 2023
c42f81f
fix : TestBuildPayload
0xsharma Jul 12, 2023
0f32302
common,core,miner: fix goleaks,duplicate init and inconsistent mutex …
Raneet10 Jul 13, 2023
2652d6c
fix : lint
0xsharma Jul 13, 2023
a8e85c4
fix : lint
0xsharma Jul 13, 2023
54acb92
fix : test-integration
0xsharma Jul 17, 2023
585dba2
fix : test-integration
0xsharma Jul 17, 2023
964faf2
core: restore AddFeeTransferLog post miner tipping
Raneet10 Jul 18, 2023
706af9e
fix : TestGraphQLConcurrentResolvers
0xsharma Jul 18, 2023
c48743a
fix : deadlocks
0xsharma Jul 21, 2023
973f116
rm: t.parallel from testQueueTimeLimiting tests
0xsharma Jul 23, 2023
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protoc:
generate-mocks:
go generate mockgen -destination=./tests/bor/mocks/IHeimdallClient.go -package=mocks ./consensus/bor IHeimdallClient
go generate mockgen -destination=./eth/filters/IBackend.go -package=filters ./eth/filters Backend
go generate mockgen -destination=../eth/filters/IDatabase.go -package=filters . Database

geth:
$(GORUN) build/ci.go install ./cmd/geth
Expand Down
8 changes: 6 additions & 2 deletions common/leak/ignore_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ func IgnoreList() []goleak.Option {
goleak.IgnoreTopFunction("github.com/rjeczalik/notify._Cfunc_CFRunLoopRun"),

// todo: this leaks should be fixed
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/metrics.(*meterArbiter).tick"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.nullSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribeNewTxsEvent.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.(*filterBackend).SubscribePendingLogsEvent.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/consensus/ethash.(*remoteSealer).loop"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core.(*BlockChain).updateFutureBlocks"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.nullSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/eth/filters.(*EventSystem).eventLoop"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/event.NewSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/event.NewSubscription"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/metrics.(*meterArbiter).tick"),
}
}
2 changes: 1 addition & 1 deletion consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead
header.UncleHash = types.CalcUncleHash(nil)

// Assemble block
block := types.NewBlock(header, txs, nil, receipts, new(trie.Trie))
block := types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil))

// set state sync
bc := chain.(core.BorStateSyncer)
Expand Down
1 change: 1 addition & 0 deletions consensus/bor/bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestGenesisContractChange(t *testing.T) {
Code: []byte{0x1, 0x1},
},
},
Config: &params.ChainConfig{},
}

db := rawdb.NewMemoryDatabase()
Expand Down
3 changes: 0 additions & 3 deletions consensus/bor/genesis_contract_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions consensus/bor/span_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2798,6 +2798,8 @@ func TestTransactionIndices(t *testing.T) {
block.AddTx(tx)
})

borReceipts := make([]types.Receipts, len(receipts))

check := func(tail *uint64, chain *BlockChain) {
stored := rawdb.ReadTxIndexTail(chain.db)
if tail == nil && stored != nil {
Expand Down Expand Up @@ -2841,7 +2843,7 @@ func TestTransactionIndices(t *testing.T) {
for _, l := range limit {
frdir := t.TempDir()
ancientDb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), frdir, "", false)
_, _ = rawdb.WriteAncientBlocks(ancientDb, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), []types.Receipts{nil}, big.NewInt(0))
_, _ = rawdb.WriteAncientBlocks(ancientDb, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), append([]types.Receipts{{}}, borReceipts...), big.NewInt(0))

l := l

Expand All @@ -2867,7 +2869,7 @@ func TestTransactionIndices(t *testing.T) {
ancientDb, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), t.TempDir(), "", false)
defer ancientDb.Close()

_, _ = rawdb.WriteAncientBlocks(ancientDb, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), []types.Receipts{nil}, big.NewInt(0))
_, _ = rawdb.WriteAncientBlocks(ancientDb, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), append([]types.Receipts{{}}, borReceipts...), big.NewInt(0))

limit = []uint64{0, 64 /* drop stale */, 32 /* shorten history */, 64 /* extend history */, 0 /* restore all */}

Expand Down Expand Up @@ -4387,10 +4389,12 @@ func TestTxIndexer(t *testing.T) {
},
}

borReceipts := make([]types.Receipts, len(receipts))

for _, c := range cases {
frdir := t.TempDir()
db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), frdir, "", false)
_, _ = rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), []types.Receipts{nil}, big.NewInt(0))
_, _ = rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), append([]types.Receipts{{}}, borReceipts...), big.NewInt(0))

// Index the initial blocks from ancient store
chain, _ := NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil, &c.limitA, nil)
Expand Down
4 changes: 4 additions & 0 deletions core/bor_fee_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var transferFeeLogSig = common.HexToHash("0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b4
var feeAddress = common.HexToAddress("0x0000000000000000000000000000000000001010")
var bigZero = big.NewInt(0)

func GetFeeAddress() common.Address {
return feeAddress
}

// AddTransferLog adds transfer log into state
func AddTransferLog(
state vm.StateDB,
Expand Down
9 changes: 0 additions & 9 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
// the block in chain will be returned.
func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
b.addTx(bc, vm.Config{}, tx)
b.statedb.SetTxContext(tx.Hash(), len(b.txs))

receipt, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{}, nil)
if err != nil {
panic(err)
}

b.txs = append(b.txs, tx)
b.receipts = append(b.receipts, receipt)
}

// AddTxWithVMConfig adds a transaction to the generated block. If no coinbase has
Expand Down
9 changes: 9 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,15 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
return block
}

// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block {
g := Genesis{
Alloc: GenesisAlloc{addr: {Balance: balance}},
BaseFee: big.NewInt(params.InitialBaseFee),
}
return g.MustCommit(db)
}

// DefaultGenesisBlock returns the Ethereum main net genesis block.
func DefaultGenesisBlock() *Genesis {
return &Genesis{
Expand Down
1 change: 1 addition & 0 deletions core/rawdb/ancient_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var chainFreezerNoSnappy = map[string]bool{
ChainFreezerBodiesTable: false,
ChainFreezerReceiptTable: false,
ChainFreezerDifficultyTable: true,
freezerBorReceiptTable: false,
}

// The list of identifiers of ancient stores.
Expand Down
6 changes: 6 additions & 0 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash
return fmt.Errorf("can't write td to Freezer: %v", err)
}

// bor block receipt
borBlockReceipt := ReadBorReceiptRLP(nfdb, hash, number)
if err := op.AppendRaw(freezerBorReceiptTable, number, borBlockReceipt); err != nil {
return fmt.Errorf("can't write bor-receipt to freezer: %v", err)
}

hashes = append(hashes, hash)
}

Expand Down
1 change: 1 addition & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
statedb.AddBalance(result.BurntContractAddress, result.FeeBurnt)
}

// TODO(raneet10) Double check
statedb.AddBalance(evm.Context.Coinbase, result.FeeTipped)
output1 := new(big.Int).SetBytes(result.SenderInitBalance.Bytes())
output2 := new(big.Int).SetBytes(coinbaseBalance.Bytes())
Expand Down
13 changes: 10 additions & 3 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func u64(val uint64) *uint64 { return &val }
// contain invalid transactions
func TestStateProcessorErrors(t *testing.T) {
var (
cacheConfig = &CacheConfig{
TrieCleanLimit: 154,
TrieCleanJournal: "triecache",
Preimages: true,
}

config = &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
Expand Down Expand Up @@ -256,7 +262,7 @@ func TestStateProcessorErrors(t *testing.T) {
},
}
blockchain, _ = NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
parallelBlockchain, _ = NewParallelBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil)
parallelBlockchain, _ = NewParallelBlockChain(db, cacheConfig, gspec, nil, ethash.NewFaker(), vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil)
)

defer blockchain.Stop()
Expand Down Expand Up @@ -303,7 +309,7 @@ func TestStateProcessorErrors(t *testing.T) {
},
}
blockchain, _ = NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
parallelBlockchain, _ = NewParallelBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil)
parallelBlockchain, _ = NewParallelBlockChain(db, cacheConfig, gspec, nil, ethash.NewFaker(), vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil)
)

defer blockchain.Stop()
Expand Down Expand Up @@ -360,6 +366,7 @@ func TestStateProcessorErrors(t *testing.T) {
TerminalTotalDifficultyPassed: true,
// TODO marcello double check
ShanghaiTime: u64(0),
Bor: &params.BorConfig{BurntContract: map[string]string{"0": "0x000000000000000000000000000000000000dead"}},
},
Alloc: GenesisAlloc{
common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): GenesisAccount{
Expand All @@ -370,7 +377,7 @@ func TestStateProcessorErrors(t *testing.T) {
}
genesis = gspec.MustCommit(db)
blockchain, _ = NewBlockChain(db, nil, gspec, nil, beacon.New(ethash.NewFaker()), vm.Config{}, nil, nil, nil)
parallelBlockchain, _ = NewParallelBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil)
parallelBlockchain, _ = NewParallelBlockChain(db, cacheConfig, gspec, nil, beacon.New(ethash.NewFaker()), vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil)
tooBigInitCode = [params.MaxInitCodeSize + 1]byte{}
smallInitCode = [320]byte{}
)
Expand Down
23 changes: 12 additions & 11 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,16 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
effectiveTip = cmath.BigMin(msg.GasTipCap, new(big.Int).Sub(msg.GasFeeCap, st.evm.Context.BaseFee))
}

if st.evm.Config.NoBaseFee && msg.GasFeeCap.Sign() == 0 && msg.GasTipCap.Sign() == 0 {
// Skip fee payment when NoBaseFee is set and the fee fields
// are 0. This avoids a negative effectiveTip being applied to
// the coinbase when simulating calls.
} else {
fee := new(big.Int).SetUint64(st.gasUsed())
fee.Mul(fee, effectiveTip)
st.state.AddBalance(st.evm.Context.Coinbase, fee)
}
// TODO(raneet10): Double check. We might want to inculcate this fix in a separate condition
// if st.evm.Config.NoBaseFee && msg.GasFeeCap.Sign() == 0 && msg.GasTipCap.Sign() == 0 {
// // Skip fee payment when NoBaseFee is set and the fee fields
// // are 0. This avoids a negative effectiveTip being applied to
// // the coinbase when simulating calls.
// } else {
// fee := new(big.Int).SetUint64(st.gasUsed())
// fee.Mul(fee, effectiveTip)
// st.state.AddBalance(st.evm.Context.Coinbase, fee)
// }

amount := new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)

Expand All @@ -458,8 +459,8 @@ 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()))
burnAmount := new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee)
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 {
st.state.AddBalance(burntContractAddress, burnAmount)
Expand Down