From 1742bd3b278c83b69255db17c0a7107faf6158a3 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Thu, 22 May 2025 14:06:07 +0530 Subject: [PATCH] upstream v1.15.11: fixed all compilation errors --- accounts/abi/bind/backends/simulated.go | 8 +++ cmd/utils/cmd.go | 2 +- core/blockchain.go | 15 +++--- core/blockchain_test.go | 4 +- core/txindexer.go | 12 ++--- core/txpool/blobpool/blobpool_test.go | 4 -- eth/api_backend_test.go | 2 +- eth/backend.go | 27 +++++----- eth/downloader/queue.go | 9 ---- eth/filters/IBackend.go | 66 ++++++++++++++++--------- ethstats/ethstats_test.go | 2 +- internal/cli/server/api_service.go | 5 +- internal/cli/server/service.go | 2 +- internal/ethapi/api_test.go | 2 +- params/config.go | 2 + 15 files changed, 85 insertions(+), 77 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index f15d1ff2aa..9e89dcf460 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -977,6 +977,14 @@ func (fb *filterBackend) NewMatcherBackend() filtermaps.MatcherBackend { panic("not supported") } +func (fb *filterBackend) CurrentView() *filtermaps.ChainView { + panic("implement me") +} + +func (fb *filterBackend) HistoryPruningCutoff() uint64 { + panic("implement me") +} + func nullSubscription() event.Subscription { return event.NewSubscription(func(quit <-chan struct{}) error { <-quit diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index c7a9a3832e..5a3c675636 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -331,7 +331,7 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ if err != nil { return fmt.Errorf("error reading receipts %d: %w", it.Number(), err) } - if status, err := chain.HeaderChain().InsertHeaderChain([]*types.Header{block.Header()}, start); err != nil { + if status, err := chain.HeaderChain().InsertHeaderChain([]*types.Header{block.Header()}, start, forker); err != nil { return fmt.Errorf("error inserting header %d: %w", it.Number(), err) } else if status != core.CanonStatTy { return fmt.Errorf("error inserting header %d, not canon: %v", it.Number(), status) diff --git a/core/blockchain.go b/core/blockchain.go index c6bf7f3232..481173827b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "math" "math/big" "runtime" "slices" @@ -2548,8 +2547,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness trieDiffNodes, trieBufNodes, _ := bc.triedb.Size() stats.report(chain, it.index, snapDiffItems, snapBufItems, trieDiffNodes, trieBufNodes, setHead) - // Print confirmation that a future fork is scheduled, but not yet active. - bc.logForkReadiness(block) + /* + // Print confirmation that a future fork is scheduled, but not yet active. + bc.logForkReadiness(block) + */ if !setHead { // After merge we expect few side chains. Simply count @@ -3295,6 +3296,7 @@ func (bc *BlockChain) reportBlock(block *types.Block, res *ProcessResult, err er log.Error(summarizeBadBlock(block, receipts, bc.Config(), err)) } +/* // logForkReadiness will write a log when a future fork is scheduled, but not // active. This is useful so operators know their client is ready for the fork. func (bc *BlockChain) logForkReadiness(block *types.Block) { @@ -3311,6 +3313,7 @@ func (bc *BlockChain) logForkReadiness(block *types.Block) { bc.lastForkReadyAlert = time.Now() } } +*/ // summarizeBadBlock returns a string summarizing the bad block and other // relevant information. @@ -3388,9 +3391,3 @@ func (bc *BlockChain) GetTrieFlushInterval() time.Duration { func (bc *BlockChain) SubscribeChain2HeadEvent(ch chan<- Chain2HeadEvent) event.Subscription { return bc.scope.Track(bc.chain2HeadFeed.Subscribe(ch)) } - -// HistoryPruningCutoff returns the configured history pruning point. -// Blocks before this might not be available in the database. -func (bc *BlockChain) HistoryPruningCutoff() uint64 { - return bc.cacheConfig.HistoryPruningCutoff -} diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 26670ff76b..c2b38cf554 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -2125,13 +2125,13 @@ func testInsertReceiptChainRollback(t *testing.T, scheme string) { } // Set up a BlockChain that uses the ancient store. - ancientDb, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) + ancientDb, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false, false, false) if err != nil { t.Fatalf("failed to create temp freezer db: %v", err) } defer ancientDb.Close() - ancientChain, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil) + ancientChain, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil) defer ancientChain.Stop() // Import the canonical header chain. diff --git a/core/txindexer.go b/core/txindexer.go index 5606b2b021..587118ed7f 100644 --- a/core/txindexer.go +++ b/core/txindexer.go @@ -68,13 +68,13 @@ type txIndexer struct { // newTxIndexer initializes the transaction indexer. func newTxIndexer(limit uint64, chain *BlockChain) *txIndexer { + cutoff, _ := chain.HistoryPruningCutoff() indexer := &txIndexer{ - limit: limit, - cutoff: chain.HistoryPruningCutoff(), - db: chain.db, - progress: make(chan chan TxIndexProgress), - term: make(chan chan struct{}), - closed: make(chan struct{}), + limit: limit, + cutoff: cutoff, + db: chain.db, + term: make(chan chan struct{}), + closed: make(chan struct{}), } indexer.head.Store(indexer.resolveHead()) indexer.tail.Store(rawdb.ReadTxIndexTail(chain.db)) diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index 9feb6b65a3..9f61aaf790 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -218,10 +218,6 @@ func (r *reserver) Has(address common.Address) bool { return exists } -func MakeAddressReserver() { - makeAddressReserver() -} - // makeTx is a utility method to construct a random blob transaction and sign it // with a valid key, only setting the interesting fields from the perspective of // the blob pool. diff --git a/eth/api_backend_test.go b/eth/api_backend_test.go index 049f68d827..8129d837da 100644 --- a/eth/api_backend_test.go +++ b/eth/api_backend_test.go @@ -61,7 +61,7 @@ func initBackend(withLocal bool) *EthAPIBackend { db = rawdb.NewMemoryDatabase() engine = beacon.New(ethash.NewFaker()) ) - chain, _ := core.NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil) + chain, _ := core.NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil) txconfig := legacypool.DefaultConfig txconfig.Journal = "" // Don't litter the disk with test journals diff --git a/eth/backend.go b/eth/backend.go index 420e60e558..99189df605 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -227,18 +227,17 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { EnablePreimageRecording: config.EnablePreimageRecording, } cacheConfig = &core.CacheConfig{ - TrieCleanLimit: config.TrieCleanCache, - TrieCleanNoPrefetch: config.NoPrefetch, - TrieDirtyLimit: config.TrieDirtyCache, - TrieDirtyDisabled: config.NoPruning, - TrieTimeLimit: config.TrieTimeout, - SnapshotLimit: config.SnapshotCache, - Preimages: config.Preimages, - StateHistory: config.StateHistory, - StateScheme: scheme, - TriesInMemory: config.TriesInMemory, - ChainHistoryMode: config.HistoryMode, - HistoryPruningCutoff: historyPruningCutoff, + TrieCleanLimit: config.TrieCleanCache, + TrieCleanNoPrefetch: config.NoPrefetch, + TrieDirtyLimit: config.TrieDirtyCache, + TrieDirtyDisabled: config.NoPruning, + TrieTimeLimit: config.TrieTimeout, + SnapshotLimit: config.SnapshotCache, + Preimages: config.Preimages, + StateHistory: config.StateHistory, + StateScheme: scheme, + TriesInMemory: config.TriesInMemory, + ChainHistoryMode: config.HistoryMode, } ) @@ -296,7 +295,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { HashScheme: scheme == rawdb.HashScheme, } chainView := eth.newChainView(eth.blockchain.CurrentBlock()) - historyCutoff := eth.blockchain.HistoryPruningCutoff() + historyCutoff, _ := eth.blockchain.HistoryPruningCutoff() var finalBlock uint64 if fb := eth.blockchain.CurrentFinalBlock(); fb != nil { finalBlock = fb.Number.Uint64() @@ -867,7 +866,7 @@ func (s *Ethereum) updateFilterMapsHeads() { if head == nil || newHead.Hash() != head.Hash() { head = newHead chainView := s.newChainView(head) - historyCutoff := s.blockchain.HistoryPruningCutoff() + historyCutoff, _ := s.blockchain.HistoryPruningCutoff() var finalBlock uint64 if fb := s.blockchain.CurrentFinalBlock(); fb != nil { finalBlock = fb.Number.Uint64() diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 9d129d9a1d..fac47dbb94 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -436,8 +436,6 @@ func (q *queue) stats() []interface{} { } } -// This was removed from geth -/* // ReserveHeaders reserves a set of headers for the given peer, skipping any // previously failed batches. func (q *queue) ReserveHeaders(p *peerConnection, count int) *fetchRequest { @@ -480,7 +478,6 @@ func (q *queue) ReserveHeaders(p *peerConnection, count int) *fetchRequest { return request } -*/ // ReserveBodies reserves a set of body fetches for the given peer, skipping any // previously failed downloads. Beside the next batch of needed fetches, it also @@ -644,8 +641,6 @@ func (q *queue) Revoke(peerID string) { } } -// This was removed from geth -/* // ExpireHeaders cancels a request that timed out and moves the pending fetch // task back into the queue for rescheduling. func (q *queue) ExpireHeaders(peer string) int { @@ -656,7 +651,6 @@ func (q *queue) ExpireHeaders(peer string) int { return q.expire(peer, q.headerPendPool, q.headerTaskQueue) } -*/ // ExpireBodies checks for in flight block body requests that exceeded a timeout // allowance, canceling them and returning the responsible peers for penalisation. @@ -711,8 +705,6 @@ func (q *queue) expire(peer string, pendPool map[string]*fetchRequest, taskQueue return len(req.Headers) } -// This was removed from geth -/* // DeliverHeaders injects a header retrieval response into the header results // cache. This method either accepts all headers it received, or none of them // if they do not map correctly to the skeleton. @@ -836,7 +828,6 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, hashes []comm return len(headers), nil } -*/ // DeliverBodies injects a block body retrieval response into the results queue. // The method returns the number of blocks bodies accepted from the delivery and diff --git a/eth/filters/IBackend.go b/eth/filters/IBackend.go index 5e32437a8d..dcb56df757 100644 --- a/eth/filters/IBackend.go +++ b/eth/filters/IBackend.go @@ -10,10 +10,10 @@ import ( common "github.com/ethereum/go-ethereum/common" core "github.com/ethereum/go-ethereum/core" + filtermaps "github.com/ethereum/go-ethereum/core/filtermaps" types "github.com/ethereum/go-ethereum/core/types" ethdb "github.com/ethereum/go-ethereum/ethdb" event "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/core/filtermaps" params "github.com/ethereum/go-ethereum/params" rpc "github.com/ethereum/go-ethereum/rpc" gomock "github.com/golang/mock/gomock" @@ -42,21 +42,6 @@ func (m *MockBackend) EXPECT() *MockBackendMockRecorder { return m.recorder } -// BloomStatus mocks base method. -func (m *MockBackend) BloomStatus() (uint64, uint64) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BloomStatus") - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(uint64) - return ret0, ret1 -} - -// BloomStatus indicates an expected call of BloomStatus. -func (mr *MockBackendMockRecorder) BloomStatus() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BloomStatus", reflect.TypeOf((*MockBackend)(nil).BloomStatus)) -} - // ChainConfig mocks base method. func (m *MockBackend) ChainConfig() *params.ChainConfig { m.ctrl.T.Helper() @@ -99,6 +84,20 @@ func (mr *MockBackendMockRecorder) CurrentHeader() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentHeader", reflect.TypeOf((*MockBackend)(nil).CurrentHeader)) } +// CurrentView mocks base method. +func (m *MockBackend) CurrentView() *filtermaps.ChainView { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CurrentView") + ret0, _ := ret[0].(*filtermaps.ChainView) + return ret0 +} + +// CurrentView indicates an expected call of CurrentView. +func (mr *MockBackendMockRecorder) CurrentView() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentView", reflect.TypeOf((*MockBackend)(nil).CurrentView)) +} + // GetBody mocks base method. func (m *MockBackend) GetBody(arg0 context.Context, arg1 common.Hash, arg2 rpc.BlockNumber) (*types.Body, error) { m.ctrl.T.Helper() @@ -204,6 +203,33 @@ func (mr *MockBackendMockRecorder) HeaderByNumber(arg0, arg1 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HeaderByNumber", reflect.TypeOf((*MockBackend)(nil).HeaderByNumber), arg0, arg1) } +// HistoryPruningCutoff mocks base method. +func (m *MockBackend) HistoryPruningCutoff() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HistoryPruningCutoff") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// HistoryPruningCutoff indicates an expected call of HistoryPruningCutoff. +func (mr *MockBackendMockRecorder) HistoryPruningCutoff() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HistoryPruningCutoff", reflect.TypeOf((*MockBackend)(nil).HistoryPruningCutoff)) +} + +// NewMatcherBackend mocks base method. +func (m *MockBackend) NewMatcherBackend() filtermaps.MatcherBackend { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewMatcherBackend") + ret0, _ := ret[0].(filtermaps.MatcherBackend) + return ret0 +} + +// NewMatcherBackend indicates an expected call of NewMatcherBackend. +func (mr *MockBackendMockRecorder) NewMatcherBackend() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewMatcherBackend", reflect.TypeOf((*MockBackend)(nil).NewMatcherBackend)) +} // SubscribeChainEvent mocks base method. func (m *MockBackend) SubscribeChainEvent(arg0 chan<- core.ChainEvent) event.Subscription { @@ -288,11 +314,3 @@ func (mr *MockBackendMockRecorder) SubscribeStateSyncEvent(arg0 interface{}) *go mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeStateSyncEvent", reflect.TypeOf((*MockBackend)(nil).SubscribeStateSyncEvent), arg0) } - -func (m *MockBackend) NewMatcherBackend() filtermaps.MatcherBackend { - panic("implement me") -} - -func (mr *MockBackendMockRecorder) NewMatcherBackend() filtermaps.MatcherBackend { - panic("implement me") -} \ No newline at end of file diff --git a/ethstats/ethstats_test.go b/ethstats/ethstats_test.go index aed4356f4a..74613d050c 100644 --- a/ethstats/ethstats_test.go +++ b/ethstats/ethstats_test.go @@ -120,7 +120,7 @@ func (m *MockFullNodeBackend) Stats() (pending int, queued int) { return 0, 0 } -func (m *MockFullNodeBackend) SyncProgress() ethereum.SyncProgress { +func (m *MockFullNodeBackend) SyncProgress(ctx context.Context) ethereum.SyncProgress { return ethereum.SyncProgress{} } diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index e66c8fa610..4189254bc7 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -80,10 +80,7 @@ func blockToProtoBlock(h *types.Block) *protobor.Block { } func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - _, _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) - if err != nil { - return nil, err - } + _, _, blockHash, _, txnIndex := s.backend.APIBackend.GetTransaction(protoutil.ConvertH256ToHash(req.Hash)) receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) if err != nil { diff --git a/internal/cli/server/service.go b/internal/cli/server/service.go index dd2c02d722..d73ed0573a 100644 --- a/internal/cli/server/service.go +++ b/internal/cli/server/service.go @@ -203,7 +203,7 @@ func (s *Server) Status(ctx context.Context, in *proto.StatusRequest) (*proto.St } apiBackend := s.backend.APIBackend - syncProgress := apiBackend.SyncProgress() + syncProgress := apiBackend.SyncProgress(ctx) resp := &proto.StatusResponse{ CurrentHeader: headerToProtoHeader(apiBackend.CurrentHeader()), diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index e363608121..0af8a3d03f 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -716,7 +716,7 @@ func (b testBackend) SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Sub } func (b testBackend) HistoryPruningCutoff() uint64 { - bn := b.chain.HistoryPruningCutoff() + bn, _ := b.chain.HistoryPruningCutoff() return bn } diff --git a/params/config.go b/params/config.go index e02044292d..df6eb18789 100644 --- a/params/config.go +++ b/params/config.go @@ -1384,6 +1384,7 @@ func (c *ChainConfig) LatestFork(time uint64) forks.Fork { } } +/* // Timestamp returns the timestamp associated with the fork or returns nil if // the fork isn't defined or isn't a time-based fork. func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 { @@ -1400,6 +1401,7 @@ func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 { return nil } } +*/ // isForkBlockIncompatible returns true if a fork scheduled at block s1 cannot be // rescheduled to block s2 because head is already past the fork.