Skip to content

Commit

Permalink
upstream: Cancun code merge v1.13.12~v1.13.14 fix CI (ethereum#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 authored Mar 11, 2024
1 parent 411d5c5 commit b7d3be0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 166 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestHistoryImportAndExport(t *testing.T) {

// Now import Era.
freezer := t.TempDir()
db2, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), freezer, "", false)
db2, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), freezer, "", false, false, false, false)
if err != nil {
panic(err)
}
Expand Down
4 changes: 3 additions & 1 deletion core/txpool/blobpool/blobpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,9 @@ func benchmarkPoolPending(b *testing.B, datacap uint64) {
statedb.AddBalance(addr, uint256.NewInt(1_000_000_000))
pool.add(tx)
}
statedb.Commit(0, true)
statedb.Finalise(true)
statedb.AccountsIntermediateRoot()
statedb.Commit(0, nil)
defer pool.Close()

// Benchmark assembling the pending
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ func TestTransactionPendingReannouce(t *testing.T) {
reannounceInterval = time.Second

pool := New(config, blockchain)
pool.Init(new(big.Int).SetUint64(config.PriceLimit), blockchain.CurrentBlock(), makeAddressReserver())
pool.Init(config.PriceLimit, blockchain.CurrentBlock(), makeAddressReserver())
// Modify ReannounceTime to trigger quicker.
pool.config.ReannounceTime = time.Second
defer pool.Close()
Expand Down
138 changes: 0 additions & 138 deletions eth/filters/filter_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/ethapi"
Expand Down Expand Up @@ -773,143 +772,6 @@ func TestPendingLogsSubscription(t *testing.T) {
}
}

func TestLightFilterLogs(t *testing.T) {
t.Parallel()

var (
db = rawdb.NewMemoryDatabase()
backend, sys = newTestFilterSystem(t, db, Config{})
api = NewFilterAPI(sys, true)
signer = types.HomesteadSigner{}

firstAddr = common.HexToAddress("0x1111111111111111111111111111111111111111")
secondAddr = common.HexToAddress("0x2222222222222222222222222222222222222222")
thirdAddress = common.HexToAddress("0x3333333333333333333333333333333333333333")
notUsedAddress = common.HexToAddress("0x9999999999999999999999999999999999999999")
firstTopic = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")
secondTopic = common.HexToHash("0x2222222222222222222222222222222222222222222222222222222222222222")

// posted twice, once as regular logs and once as pending logs.
allLogs = []*types.Log{
// Block 1
{Address: firstAddr, Topics: []common.Hash{}, Data: []byte{}, BlockNumber: 2, Index: 0},
// Block 2
{Address: firstAddr, Topics: []common.Hash{firstTopic}, Data: []byte{}, BlockNumber: 3, Index: 0},
{Address: secondAddr, Topics: []common.Hash{firstTopic}, Data: []byte{}, BlockNumber: 3, Index: 1},
{Address: thirdAddress, Topics: []common.Hash{secondTopic}, Data: []byte{}, BlockNumber: 3, Index: 2},
// Block 3
{Address: thirdAddress, Topics: []common.Hash{secondTopic}, Data: []byte{}, BlockNumber: 4, Index: 0},
}

testCases = []struct {
crit FilterCriteria
expected []*types.Log
id rpc.ID
}{
// match all
0: {FilterCriteria{}, allLogs, ""},
// match none due to no matching addresses
1: {FilterCriteria{Addresses: []common.Address{{}, notUsedAddress}, Topics: [][]common.Hash{nil}}, []*types.Log{}, ""},
// match logs based on addresses, ignore topics
2: {FilterCriteria{Addresses: []common.Address{firstAddr}}, allLogs[:2], ""},
// match logs based on addresses and topics
3: {FilterCriteria{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{{firstTopic, secondTopic}}}, allLogs[3:5], ""},
// all logs with block num >= 3
4: {FilterCriteria{FromBlock: big.NewInt(3), ToBlock: big.NewInt(5)}, allLogs[1:], ""},
// all logs
5: {FilterCriteria{FromBlock: big.NewInt(0), ToBlock: big.NewInt(5)}, allLogs, ""},
// all logs with 1>= block num <=2 and topic secondTopic
6: {FilterCriteria{FromBlock: big.NewInt(2), ToBlock: big.NewInt(3), Topics: [][]common.Hash{{secondTopic}}}, allLogs[3:4], ""},
}

key, _ = crypto.GenerateKey()
addr = crypto.PubkeyToAddress(key.PublicKey)
genesis = &core.Genesis{Config: params.TestChainConfig,
Alloc: types.GenesisAlloc{
addr: {Balance: big.NewInt(params.Ether)},
},
}
receipts = []*types.Receipt{{
Logs: []*types.Log{allLogs[0]},
}, {
Logs: []*types.Log{allLogs[1], allLogs[2], allLogs[3]},
}, {
Logs: []*types.Log{allLogs[4]},
}}
)

_, blocks, _ := core.GenerateChainWithGenesis(genesis, ethash.NewFaker(), 4, func(i int, b *core.BlockGen) {
if i == 0 {
return
}
receipts[i-1].Bloom = types.CreateBloom(types.Receipts{receipts[i-1]})
b.AddUncheckedReceipt(receipts[i-1])
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i - 1), To: &common.Address{}, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, key)
b.AddTx(tx)
})
for i, block := range blocks {
rawdb.WriteBlock(db, block)
rawdb.WriteCanonicalHash(db, block.Hash(), block.NumberU64())
rawdb.WriteHeadBlockHash(db, block.Hash())
if i > 0 {
rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), []*types.Receipt{receipts[i-1]})
}
}
// create all filters
for i := range testCases {
id, err := api.NewFilter(testCases[i].crit)
if err != nil {
t.Fatal(err)
}
testCases[i].id = id
}

// raise events
time.Sleep(1 * time.Second)
for _, block := range blocks {
backend.chainFeed.Send(core.ChainEvent{Block: block, Hash: common.Hash{}, Logs: allLogs})
}

for i, tt := range testCases {
var fetched []*types.Log
timeout := time.Now().Add(1 * time.Second)
for { // fetch all expected logs
results, err := api.GetFilterChanges(tt.id)
if err != nil {
t.Fatalf("Unable to fetch logs: %v", err)
}
fetched = append(fetched, results.([]*types.Log)...)
if len(fetched) >= len(tt.expected) {
break
}
// check timeout
if time.Now().After(timeout) {
break
}

time.Sleep(100 * time.Millisecond)
}

if len(fetched) != len(tt.expected) {
t.Errorf("invalid number of logs for case %d, want %d log(s), got %d", i, len(tt.expected), len(fetched))
return
}

for l := range fetched {
if fetched[l].Removed {
t.Errorf("expected log not to be removed for log %d in case %d", l, i)
}
expected := *tt.expected[l]
blockNum := expected.BlockNumber - 1
expected.BlockHash = blocks[blockNum].Hash()
expected.TxHash = blocks[blockNum].Transactions()[0].Hash()
if !reflect.DeepEqual(fetched[l], &expected) {
t.Errorf("invalid log on index %d for case %d", l, i)
}
}
}
}

// TestPendingTxFilterDeadlock tests if the event loop hangs when pending
// txes arrive at the same time that one of multiple filters is timing out.
// Please refer to #22131 for more details.
Expand Down
20 changes: 2 additions & 18 deletions eth/handler_bsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *testBscHandler) Handle(peer *bsc.Peer, packet bsc.Packet) error {
}
}

func TestSendVotes67(t *testing.T) { testSendVotes(t, eth.ETH67) }
func TestSendVotes68(t *testing.T) { testSendVotes(t, eth.ETH68) }

func testSendVotes(t *testing.T, protocol uint) {
t.Parallel()
Expand All @@ -63,10 +63,6 @@ func testSendVotes(t *testing.T, protocol uint) {
time.Sleep(250 * time.Millisecond) // Wait until vote events get out of the system (can't use events, vote broadcaster races with peer join)

protos := []p2p.Protocol{
{
Name: "eth",
Version: eth.ETH67,
},
{
Name: "eth",
Version: eth.ETH68,
Expand All @@ -77,10 +73,6 @@ func testSendVotes(t *testing.T, protocol uint) {
},
}
caps := []p2p.Cap{
{
Name: "eth",
Version: eth.ETH67,
},
{
Name: "eth",
Version: eth.ETH68,
Expand Down Expand Up @@ -163,7 +155,7 @@ func testSendVotes(t *testing.T, protocol uint) {
}
}

func TestRecvVotes67(t *testing.T) { testRecvVotes(t, eth.ETH67) }
func TestRecvVotes68(t *testing.T) { testRecvVotes(t, eth.ETH68) }

func testRecvVotes(t *testing.T, protocol uint) {
t.Parallel()
Expand All @@ -173,10 +165,6 @@ func testRecvVotes(t *testing.T, protocol uint) {
defer handler.close()

protos := []p2p.Protocol{
{
Name: "eth",
Version: eth.ETH67,
},
{
Name: "eth",
Version: eth.ETH68,
Expand All @@ -187,10 +175,6 @@ func testRecvVotes(t *testing.T, protocol uint) {
},
}
caps := []p2p.Cap{
{
Name: "eth",
Version: eth.ETH67,
},
{
Name: "eth",
Version: eth.ETH68,
Expand Down
12 changes: 6 additions & 6 deletions eth/handler_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func testRecvTransactions(t *testing.T, protocol uint) {
}
}

func TestWaitSnapExtensionTimout67(t *testing.T) { testWaitSnapExtensionTimout(t, eth.ETH67) }
func TestWaitSnapExtensionTimout68(t *testing.T) { testWaitSnapExtensionTimout(t, eth.ETH68) }

func testWaitSnapExtensionTimout(t *testing.T, protocol uint) {
t.Parallel()
Expand Down Expand Up @@ -344,7 +344,7 @@ func testWaitSnapExtensionTimout(t *testing.T, protocol uint) {
}
}

func TestWaitBscExtensionTimout67(t *testing.T) { testWaitBscExtensionTimout(t, eth.ETH67) }
func TestWaitBscExtensionTimout68(t *testing.T) { testWaitBscExtensionTimout(t, eth.ETH68) }

func testWaitBscExtensionTimout(t *testing.T, protocol uint) {
t.Parallel()
Expand Down Expand Up @@ -553,8 +553,8 @@ func TestTransactionPendingReannounce(t *testing.T) {
defer sourcePipe.Close()
defer sinkPipe.Close()

sourcePeer := eth.NewPeer(eth.ETH67, p2p.NewPeer(enode.ID{0}, "", nil), sourcePipe, source.txpool)
sinkPeer := eth.NewPeer(eth.ETH67, p2p.NewPeer(enode.ID{0}, "", nil), sinkPipe, sink.txpool)
sourcePeer := eth.NewPeer(eth.ETH68, p2p.NewPeer(enode.ID{0}, "", nil), sourcePipe, source.txpool)
sinkPeer := eth.NewPeer(eth.ETH68, p2p.NewPeer(enode.ID{0}, "", nil), sinkPipe, sink.txpool)
defer sourcePeer.Close()
defer sinkPeer.Close()

Expand Down Expand Up @@ -774,8 +774,8 @@ func TestOptionMaxPeersPerIP(t *testing.T) {
}
uniPort++

src := eth.NewPeer(eth.ETH67, peer1, p2pSrc, handler.txpool)
sink := eth.NewPeer(eth.ETH67, peer2, p2pSink, handler.txpool)
src := eth.NewPeer(eth.ETH68, peer1, p2pSrc, handler.txpool)
sink := eth.NewPeer(eth.ETH68, peer2, p2pSink, handler.txpool)
defer src.Close()
defer sink.Close()

Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transac

stopPrefetchCh := make(chan struct{})
defer close(stopPrefetchCh)
// prefetch txs from all pending txs
// prefetch plainTxs txs, don't bother to prefetch a few blobTxs
txsPrefetch := plainTxs.Copy()
tx := txsPrefetch.PeekWithUnwrap()
if tx != nil {
Expand Down

0 comments on commit b7d3be0

Please sign in to comment.