Skip to content

Commit

Permalink
Added a subRollupCache so that, Collection of subRollup is only done …
Browse files Browse the repository at this point in the history
…once per block
  • Loading branch information
gameofpointers committed Nov 7, 2023
1 parent bd40fb5 commit 6cee1f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
const (
headerCacheLimit = 512
numberCacheLimit = 2048
c_subRollupCacheSize = 50
primeHorizonThreshold = 20
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 && rollup != nil {
subRollup = rollup.(types.Transactions)
log.Info("Found the rollup in cache", "Hash", block.Hash(), "len", len(subRollup))
} else {
subRollup, err = sl.hc.CollectSubRollup(block)
if err != nil {
return nil, nil, err
}
sl.hc.subRollupCache.Add(block.Hash(), subRollup)
}
}

Expand Down

0 comments on commit 6cee1f5

Please sign in to comment.