From 3ded4c867180ae40459d2515ed63fce3e7be6302 Mon Sep 17 00:00:00 2001 From: gop Date: Fri, 3 Nov 2023 14:17:34 -0500 Subject: [PATCH] Added a subRollupCache so that, Collection of subRollup is only done once per block --- core/headerchain.go | 5 +++++ core/slice.go | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/headerchain.go b/core/headerchain.go index c32a5a55dc..1d163f722d 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -28,6 +28,7 @@ import ( const ( headerCacheLimit = 512 numberCacheLimit = 2048 + c_subRollupCacheSize = 50 primeHorizonThreshold = 20 ) @@ -62,6 +63,7 @@ type HeaderChain struct { pendingEtxsRollup *lru.Cache pendingEtxs *lru.Cache blooms *lru.Cache + subRollupCache *lru.Cache wg sync.WaitGroup // chain processing wait group for shutting down running int32 // 0 if chain is running, 1 when stopped @@ -102,6 +104,9 @@ func NewHeaderChain(db ethdb.Database, engine consensus.Engine, pEtxsRollupFetch blooms, _ := lru.New(c_maxBloomFilters) hc.blooms = blooms + subRollupCache, _ := lru.New(c_subRollupCacheSize) + hc.subRollupCache = subRollupCache + hc.genesisHeader = hc.GetHeaderByNumber(0) if hc.genesisHeader.Hash() != chainConfig.GenesisHash { return nil, fmt.Errorf("genesis block mismatch: have %x, want %x", hc.genesisHeader.Hash(), chainConfig.GenesisHash) diff --git a/core/slice.go b/core/slice.go index bc8eb9eeff..5138b5ba18 100644 --- a/core/slice.go +++ b/core/slice.go @@ -595,9 +595,16 @@ func (sl *Slice) CollectNewlyConfirmedEtxs(block *types.Block, location common.L subRollup := types.Transactions{} var err error if nodeCtx < common.ZONE_CTX { - subRollup, err = sl.hc.CollectSubRollup(block) - if err != nil { - return nil, nil, err + rollup, exists := sl.hc.subRollupCache.Get(block.Hash()) + if !exists { + subRollup, err = sl.hc.CollectSubRollup(block) + if err != nil { + return nil, nil, err + } + sl.hc.subRollupCache.Add(block.Hash(), subRollup) + } else { + subRollup = rollup.(types.Transactions) + log.Info("Found the rollup in cache", "Hash", block.Hash(), "len", len(subRollup)) } }