Skip to content

Commit

Permalink
fix rollup estimation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Oct 2, 2023
1 parent 48eaed5 commit 9e8091e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 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
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 9e8091e

Please sign in to comment.