diff --git a/go/common/batches.go b/go/common/batches.go index 3aa90935ae..cccacdb283 100644 --- a/go/common/batches.go +++ b/go/common/batches.go @@ -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) } diff --git a/go/enclave/storage/storage.go b/go/enclave/storage/storage.go index 57e61de6da..5d3e336e99 100644 --- a/go/enclave/storage/storage.go +++ b/go/enclave/storage/storage.go @@ -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) diff --git a/go/host/enclave/guardian.go b/go/host/enclave/guardian.go index bfb00b7b74..dd00d6adc2 100644 --- a/go/host/enclave/guardian.go +++ b/go/host/enclave/guardian.go @@ -520,6 +520,8 @@ func (g *Guardian) periodicBatchProduction() { } } +const batchCompressionFactor = 0.85 + func (g *Guardian) periodicRollupProduction() { defer g.logger.Info("Stopping rollup production") @@ -542,6 +544,7 @@ 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) @@ -549,11 +552,14 @@ func (g *Guardian) periodicRollupProduction() { 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) @@ -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++ }