Skip to content

Commit

Permalink
adjust cache cfg (#1568)
Browse files Browse the repository at this point in the history
* adjust cache cfg

* fix rollup estimation logic
  • Loading branch information
tudor-malene authored Oct 2, 2023
1 parent a030959 commit 4525fd5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
5 changes: 0 additions & 5 deletions go/common/batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ func (b *ExtBatch) Hash() L2BatchHash {
return v
}

func (b *ExtBatch) Size() (int, error) {
bytes, err := rlp.EncodeToBytes(b)
return len(bytes), err
}

func (b *ExtBatch) Encoded() ([]byte, error) {
return rlp.EncodeToBytes(b)
}
Expand Down
4 changes: 3 additions & 1 deletion go/enclave/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func NewStorage(backingDB enclavedb.EnclaveDB, chainConfig *params.ChainConfig,

// todo (tudor) figure out the context and the config
cfg := bigcache.DefaultConfig(2 * time.Minute)
cfg.HardMaxCacheSize = 512
cfg.Shards = 512
// 1GB cache. Max value in a shard is 2MB. No batch or block should be larger than that
cfg.HardMaxCacheSize = cfg.Shards * 4
bigcacheClient, err := bigcache.New(context.Background(), cfg)
if err != nil {
logger.Crit("Could not initialise bigcache", log.ErrKey, err)
Expand Down
13 changes: 8 additions & 5 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ func (g *Guardian) periodicBatchProduction() {
}
}

const batchCompressionFactor = 0.85

func (g *Guardian) periodicRollupProduction() {
defer g.logger.Info("Stopping rollup production")

Expand All @@ -542,18 +544,22 @@ func (g *Guardian) periodicRollupProduction() {
continue
}

// estimate the size of a compressed rollup
availBatchesSumSize, err := g.calculateNonRolledupBatchesSize(fromBatch)
if err != nil {
g.logger.Error("Unable to estimate the size of the current rollup", log.ErrKey, err)
// todo - this should not happen. Is it worth continuing?
availBatchesSumSize = 0
}

// adjust the availBatchesSumSize
estimatedRunningRollupSize := uint64(float64(availBatchesSumSize) * batchCompressionFactor)

// produce and issue rollup when either:
// it has passed g.rollupInterval from last lastSuccessfulRollup
// or the size of accumulated batches is > g.maxRollupSize
timeExpired := time.Since(lastSuccessfulRollup) > g.rollupInterval
sizeExceeded := availBatchesSumSize >= g.maxRollupSize
sizeExceeded := estimatedRunningRollupSize >= g.maxRollupSize
if timeExpired || sizeExceeded {
g.logger.Info("Trigger rollup production.", "timeExpired", timeExpired, "sizeExceeded", sizeExceeded)
producedRollup, err := g.enclaveClient.CreateRollup(fromBatch)
Expand Down Expand Up @@ -642,10 +648,7 @@ func (g *Guardian) calculateNonRolledupBatchesSize(seqNo uint64) (uint64, error)
return 0, err
}

bSize, err := batch.Size()
if err != nil {
return 0, err
}
bSize := len(batch.EncryptedTxBlob)
size += uint64(bSize)
currentNo++
}
Expand Down

0 comments on commit 4525fd5

Please sign in to comment.