Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add executor reserved ZK counters #3348

Merged
merged 9 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
zkevm-prover:
container_name: zkevm-prover
restart: unless-stopped
image: hermeznetwork/zkevm-prover:v5.0.0-RC5
image: hermeznetwork/zkevm-prover:v5.0.0-RC8
depends_on:
zkevm-state-db:
condition: service_healthy
Expand Down
3 changes: 2 additions & 1 deletion event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ const (
EventID_SynchronizerHalt EventID = "SYNCHRONIZER HALT"
// EventID_SequenceSenderHalt is triggered when the SequenceSender halts
EventID_SequenceSenderHalt EventID = "SEQUENCESENDER HALT"

// EventID_NodeOOC is triggered when an OOC at node level is detected
EventID_NodeOOC EventID = "NODE OOC"
// EventID_ReservedZKCountersOverflow is triggered when reserved ZK counters exceeds remaining batch ZK counters
EventID_ReservedZKCountersOverflow EventID = "RESERVED ZKCOUNTERS OVERFLOW"
// Source_Node is the source of the event
Source_Node Source = "node"

Expand Down
6 changes: 3 additions & 3 deletions sequencer/addrqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ func (a *addrQueue) updateCurrentNonceBalance(nonce *uint64, balance *big.Int) (
}

// UpdateTxZKCounters updates the ZKCounters for the given tx (txHash)
func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters) {
func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, usedZKCounters state.ZKCounters, reservedZKCounters state.ZKCounters) {
txHashStr := txHash.String()

if (a.readyTx != nil) && (a.readyTx.HashStr == txHashStr) {
log.Debugf("updating readyTx %s with new ZKCounters from addrQueue %s", txHashStr, a.fromStr)
a.readyTx.updateZKCounters(counters)
a.readyTx.updateZKCounters(usedZKCounters, reservedZKCounters)
} else {
for _, txTracker := range a.notReadyTxs {
if txTracker.HashStr == txHashStr {
log.Debugf("updating notReadyTx %s with new ZKCounters from addrQueue %s", txHashStr, a.fromStr)
txTracker.updateZKCounters(counters)
txTracker.updateZKCounters(usedZKCounters, reservedZKCounters)
break
}
}
Expand Down
40 changes: 14 additions & 26 deletions sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (f *finalizer) closeAndOpenNewWIPBatch(ctx context.Context, closeReason sta
if f.wipL2Block != nil {
f.wipBatch.imStateRoot = f.wipL2Block.imStateRoot
// Subtract the WIP L2 block used resources to batch
overflow, overflowResource := f.wipBatch.imRemainingResources.Sub(f.wipL2Block.usedResources)
overflow, overflowResource := f.wipBatch.imRemainingResources.Sub(state.BatchResources{ZKCounters: f.wipL2Block.usedZKCounters, Bytes: f.wipL2Block.bytes})
if overflow {
return fmt.Errorf("failed to subtract L2 block [%d] used resources to new wip batch %d, overflow resource: %s",
f.wipL2Block.trackingNum, f.wipBatch.batchNumber, overflowResource)
Expand Down Expand Up @@ -424,19 +424,7 @@ func (f *finalizer) batchSanityCheck(ctx context.Context, batchNum uint64, initi
if err != nil {
log.Errorf("error marshaling payload, error: %v", err)
} else {
event := &event.Event{
ReceivedAt: time.Now(),
Source: event.Source_Node,
Component: event.Component_Sequencer,
Level: event.Level_Critical,
EventID: event.EventID_ReprocessFullBatchOOC,
Description: string(payload),
Json: batchRequest,
}
err = f.eventLog.LogEvent(ctx, event)
if err != nil {
log.Errorf("error storing payload, error: %v", err)
}
f.LogEvent(ctx, event.Level_Critical, event.EventID_ReprocessFullBatchOOC, string(payload), batchRequest)
}

return nil, ErrProcessBatchOOC
Expand Down Expand Up @@ -469,7 +457,7 @@ func (f *finalizer) maxTxsPerBatchReached(batch *Batch) bool {

// isBatchResourcesMarginExhausted checks if one of resources of the batch has reached the exhausted margin and returns the name of the exhausted resource
func (f *finalizer) isBatchResourcesMarginExhausted(resources state.BatchResources) (bool, string) {
zkCounters := resources.UsedZKCounters
zkCounters := resources.ZKCounters
result := false
resourceName := ""
if resources.Bytes <= f.getConstraintThresholdUint64(f.batchConstraints.MaxBatchBytesSize) {
Expand Down Expand Up @@ -517,16 +505,16 @@ func (f *finalizer) getConstraintThresholdUint32(input uint32) uint32 {
// getUsedBatchResources calculates and returns the used resources of a batch from remaining resources
func getUsedBatchResources(constraints state.BatchConstraintsCfg, remainingResources state.BatchResources) state.BatchResources {
return state.BatchResources{
UsedZKCounters: state.ZKCounters{
GasUsed: constraints.MaxCumulativeGasUsed - remainingResources.UsedZKCounters.GasUsed,
KeccakHashes: constraints.MaxKeccakHashes - remainingResources.UsedZKCounters.KeccakHashes,
PoseidonHashes: constraints.MaxPoseidonHashes - remainingResources.UsedZKCounters.PoseidonHashes,
PoseidonPaddings: constraints.MaxPoseidonPaddings - remainingResources.UsedZKCounters.PoseidonPaddings,
MemAligns: constraints.MaxMemAligns - remainingResources.UsedZKCounters.MemAligns,
Arithmetics: constraints.MaxArithmetics - remainingResources.UsedZKCounters.Arithmetics,
Binaries: constraints.MaxBinaries - remainingResources.UsedZKCounters.Binaries,
Steps: constraints.MaxSteps - remainingResources.UsedZKCounters.Steps,
Sha256Hashes_V2: constraints.MaxSHA256Hashes - remainingResources.UsedZKCounters.Sha256Hashes_V2,
ZKCounters: state.ZKCounters{
GasUsed: constraints.MaxCumulativeGasUsed - remainingResources.ZKCounters.GasUsed,
KeccakHashes: constraints.MaxKeccakHashes - remainingResources.ZKCounters.KeccakHashes,
PoseidonHashes: constraints.MaxPoseidonHashes - remainingResources.ZKCounters.PoseidonHashes,
PoseidonPaddings: constraints.MaxPoseidonPaddings - remainingResources.ZKCounters.PoseidonPaddings,
MemAligns: constraints.MaxMemAligns - remainingResources.ZKCounters.MemAligns,
Arithmetics: constraints.MaxArithmetics - remainingResources.ZKCounters.Arithmetics,
Binaries: constraints.MaxBinaries - remainingResources.ZKCounters.Binaries,
Steps: constraints.MaxSteps - remainingResources.ZKCounters.Steps,
Sha256Hashes_V2: constraints.MaxSHA256Hashes - remainingResources.ZKCounters.Sha256Hashes_V2,
},
Bytes: constraints.MaxBatchBytesSize - remainingResources.Bytes,
}
Expand All @@ -535,7 +523,7 @@ func getUsedBatchResources(constraints state.BatchConstraintsCfg, remainingResou
// getMaxRemainingResources returns the max resources that can be used in a batch
func getMaxRemainingResources(constraints state.BatchConstraintsCfg) state.BatchResources {
return state.BatchResources{
UsedZKCounters: state.ZKCounters{
ZKCounters: state.ZKCounters{
GasUsed: constraints.MaxCumulativeGasUsed,
KeccakHashes: constraints.MaxKeccakHashes,
PoseidonHashes: constraints.MaxPoseidonHashes,
Expand Down
4 changes: 2 additions & 2 deletions sequencer/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var (
ErrExecutorError = errors.New("executor error")
// ErrNoFittingTransaction happens when there is not a tx (from the txSortedList) that fits in the remaining batch resources
ErrNoFittingTransaction = errors.New("no fit transaction")
// ErrBatchResourceUnderFlow happens when there is batch resoure underflow after sustract the resources from a tx
ErrBatchResourceUnderFlow = errors.New("batch resource underflow")
// ErrBatchResourceOverFlow happens when there is a tx that overlows remaining batch resources
ErrBatchResourceOverFlow = errors.New("batch resource overflow")
// ErrTransactionsListEmpty happens when txSortedList is empty
ErrTransactionsListEmpty = errors.New("transactions list empty")
)
Loading
Loading