From 0476172e20fd9f45cc95a819c03cb6b04d1a3f45 Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 13 Sep 2024 22:51:06 +0800 Subject: [PATCH 1/2] avoid posible zero index panic --- core/txpool/blobpool/blobpool.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index d66a08aa17a4..465cd26733dd 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -566,7 +566,7 @@ func (p *BlobPool) recheck(addr common.Address, inclusions map[common.Hash]uint6 ids []uint64 nonces []uint64 ) - for txs[0].nonce < next { + for ; len(txs) > 0 && txs[0].nonce < next; txs = txs[1:] { ids = append(ids, txs[0].id) nonces = append(nonces, txs[0].nonce) @@ -578,7 +578,6 @@ func (p *BlobPool) recheck(addr common.Address, inclusions map[common.Hash]uint6 if inclusions != nil { p.offload(addr, txs[0].nonce, txs[0].id, inclusions) } - txs = txs[1:] } log.Trace("Dropping overlapped blob transactions", "from", addr, "overlapped", nonces, "ids", ids, "left", len(txs)) dropOverlappedMeter.Mark(int64(len(ids))) From 114fc6b964436a58eeb762658c05b39a0d3807da Mon Sep 17 00:00:00 2001 From: maskpp Date: Sat, 14 Sep 2024 09:31:39 +0800 Subject: [PATCH 2/2] temporary code --- core/stateless/witness.go | 4 +--- core/txpool/blobpool/blobpool.go | 6 ++++-- core/types/transaction.go | 2 +- trie/trie.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/stateless/witness.go b/core/stateless/witness.go index 7622c5eb610d..0f2d6cfe079c 100644 --- a/core/stateless/witness.go +++ b/core/stateless/witness.go @@ -101,9 +101,7 @@ func (w *Witness) AddState(nodes map[string]struct{}) { w.lock.Lock() defer w.lock.Unlock() - for node := range nodes { - w.State[node] = struct{}{} - } + maps.Copy(w.State, nodes) } // Copy deep-copies the witness object. Witness.Block isn't deep-copied as it diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 465cd26733dd..0384f6a8edd9 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -939,7 +939,7 @@ func (p *BlobPool) reorg(oldHead, newHead *types.Header) (map[common.Address][]* } // Generate the set of transactions per address to pull back into the pool, // also updating the rest along the way - reinject := make(map[common.Address][]*types.Transaction) + reinject := make(map[common.Address][]*types.Transaction, len(transactors)) for addr := range transactors { // Generate the set that was lost to reinject into the pool lost := make([]*types.Transaction, 0, len(discarded[addr])) @@ -948,7 +948,9 @@ func (p *BlobPool) reorg(oldHead, newHead *types.Header) (map[common.Address][]* lost = append(lost, tx) } } - reinject[addr] = lost + if len(lost) > 0 { + reinject[addr] = lost + } // Update the set that was already reincluded to track the blocks in limbo for _, tx := range types.TxDifference(included[addr], discarded[addr]) { diff --git a/core/types/transaction.go b/core/types/transaction.go index 4ac9187bdbfe..6c8759ee69b6 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -560,7 +560,7 @@ func (s Transactions) EncodeIndex(i int, w *bytes.Buffer) { func TxDifference(a, b Transactions) Transactions { keep := make(Transactions, 0, len(a)) - remove := make(map[common.Hash]struct{}) + remove := make(map[common.Hash]struct{}, b.Len()) for _, tx := range b { remove[tx.Hash()] = struct{}{} } diff --git a/trie/trie.go b/trie/trie.go index f44e10b918d4..885b6b79628c 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -666,7 +666,7 @@ func (t *Trie) Witness() map[string]struct{} { if len(t.tracer.accessList) == 0 { return nil } - witness := make(map[string]struct{}) + witness := make(map[string]struct{}, len(t.tracer.accessList)) for _, node := range t.tracer.accessList { witness[string(node)] = struct{}{} }