From d689f3bb1f580fff6cea911932e9861beee8fcbc Mon Sep 17 00:00:00 2001 From: buddho Date: Tue, 24 Jun 2025 15:29:26 +0800 Subject: [PATCH 1/2] core: warm key TransactionIndexTail by writing (#3196) --- core/txindexer.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/core/txindexer.go b/core/txindexer.go index 293124f681..effb0499d0 100644 --- a/core/txindexer.go +++ b/core/txindexer.go @@ -127,14 +127,30 @@ func (indexer *txIndexer) loop(chain *BlockChain) { // Listening to chain events and manipulate the transaction indexes. var ( - stop chan struct{} // Non-nil if background routine is active. - done chan struct{} // Non-nil if background routine is active. - lastHead uint64 // The latest announced chain head (whose tx indexes are assumed created) - lastTail = rawdb.ReadTxIndexTail(indexer.db) // The oldest indexed block, nil means nothing indexed - - headCh = make(chan ChainHeadEvent) - sub = chain.SubscribeChainHeadEvent(headCh) + stop chan struct{} // Non-nil if background routine is active. + done chan struct{} // Non-nil if background routine is active. + lastHead uint64 // The latest announced chain head (whose tx indexes are assumed created) + headCh = make(chan ChainHeadEvent) + sub = chain.SubscribeChainHeadEvent(headCh) ) + + lastTail := rawdb.ReadTxIndexTail(indexer.db) + if lastTail != nil { + // NOTE: The "TransactionIndexTail" key may exist only in cold SST files. + // Without a recent write, the key won't be in the memtable or block cache, + // causing every Get to trigger expensive readBlock + CRC checks. + // + // This dummy write forces the key into the memtable (and later SST), + // ensuring future reads are fast (from memory or block cache). + batch := indexer.db.NewBatch() + rawdb.WriteTxIndexTail(batch, *lastTail) + + if err := batch.Write(); err != nil { + log.Crit("Failed to write TransactionIndexTail warm-up", "error", err) + return + } + } + defer sub.Unsubscribe() // Launch the initial processing if chain is not empty (head != genesis). From b845b7186349933dc542027f61697b096e63fbe6 Mon Sep 17 00:00:00 2001 From: kaifulee Date: Fri, 11 Jul 2025 18:37:43 +0800 Subject: [PATCH 2/2] chore: fix some typos Signed-off-by: kaifulee --- eth/fetcher/block_fetcher.go | 2 +- eth/peerset.go | 2 +- eth/protocols/snap/sync.go | 2 +- miner/ordering.go | 2 +- node/api.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eth/fetcher/block_fetcher.go b/eth/fetcher/block_fetcher.go index 312cf08c80..2794726b57 100644 --- a/eth/fetcher/block_fetcher.go +++ b/eth/fetcher/block_fetcher.go @@ -768,7 +768,7 @@ func (f *BlockFetcher) loop() { } case entry := <-f.quickBlockFetchingCh: annHash := entry.announce.hash - // if there is error or timeout, and the shcedule have not started, just retry the fetch + // if there is error or timeout, and the schedule have not started, just retry the fetch if entry.err != nil { quickBlockFetchingErrMeter.Mark(1) log.Debug("Quick block fetching err", "hash", annHash, "err", entry.err) diff --git a/eth/peerset.go b/eth/peerset.go index d3617ec892..fdf0d60327 100644 --- a/eth/peerset.go +++ b/eth/peerset.go @@ -538,7 +538,7 @@ func (ps *peerSet) peersWithoutBlock(hash common.Hash) []*ethPeer { list = append(list, p) } } - log.Debug("get peers without block", "hash", hash, "total", len(ps.peers), "unknonw", len(list)) + log.Debug("get peers without block", "hash", hash, "total", len(ps.peers), "unknown", len(list)) return list } diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index 37c481e1a6..01840d620d 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -83,7 +83,7 @@ const ( minTrienodeHealThrottle = 1 // maxTrienodeHealThrottle is the maximum divisor for throttling trie node - // heal requests to avoid overloading the local node and exessively expanding + // heal requests to avoid overloading the local node and excessively expanding // the state trie bedth wise. maxTrienodeHealThrottle = maxTrieRequestCount diff --git a/miner/ordering.go b/miner/ordering.go index 7cbe2d5630..d545d47e81 100644 --- a/miner/ordering.go +++ b/miner/ordering.go @@ -126,7 +126,7 @@ func newTransactionsByPriceAndNonce(signer types.Signer, txs map[common.Address] } } -// Copy copys a new TransactionsPriceAndNonce with the same *transaction +// Copy copies a new TransactionsPriceAndNonce with the same *transaction func (t *transactionsByPriceAndNonce) Copy() *transactionsByPriceAndNonce { heads := make([]*txWithMinerFee, len(t.heads)) copy(heads, t.heads) diff --git a/node/api.go b/node/api.go index 97986cb608..27b91d4aee 100644 --- a/node/api.go +++ b/node/api.go @@ -52,7 +52,7 @@ func (n *Node) apis() []rpc.API { } // adminAPI is the collection of administrative API methods exposed over -// both secure and unsecure RPC channels. +// both secure and insecure RPC channels. type adminAPI struct { node *Node // Node interfaced by this API }