Skip to content

Commit

Permalink
keep halting when use HaltOnBatchNumber param (#209)
Browse files Browse the repository at this point in the history
* add keep halting

* setup ds default

* update

* update
  • Loading branch information
zjg555543 authored May 30, 2024
1 parent 97541a1 commit 8100533
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (f *finalizer) initWIPBatch(ctx context.Context) {

if isClosed { //if the last batch is close then open a new wip batch
if lastStateBatch.BatchNumber+1 == f.cfg.HaltOnBatchNumber {
f.Halt(ctx, fmt.Errorf("finalizer reached stop sequencer on batch number: %d", f.cfg.HaltOnBatchNumber), false)
f.keepHalting(ctx, fmt.Errorf("finalizer reached stop sequencer on batch number: %d", f.cfg.HaltOnBatchNumber))
}
f.wipBatch = f.openNewWIPBatch(lastStateBatch.BatchNumber+1, lastStateBatch.StateRoot)
f.pipBatch = nil
Expand Down Expand Up @@ -278,7 +278,7 @@ func (f *finalizer) closeAndOpenNewWIPBatch(ctx context.Context, closeReason sta
return fmt.Errorf("error finalizing sip batch %d when halting on batch %d", f.sipBatch.batchNumber, f.cfg.HaltOnBatchNumber)
}

f.Halt(ctx, fmt.Errorf("finalizer reached stop sequencer on batch number: %d", f.cfg.HaltOnBatchNumber), false)
f.keepHalting(ctx, fmt.Errorf("finalizer reached stop sequencer on batch number: %d", f.cfg.HaltOnBatchNumber))
}

// Process forced batches
Expand Down
16 changes: 16 additions & 0 deletions sequencer/finalizer_xlayer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package sequencer

import (
"context"
"fmt"
"time"

"github.com/0xPolygonHermez/zkevm-node/event"
"github.com/0xPolygonHermez/zkevm-node/log"
seqMetrics "github.com/0xPolygonHermez/zkevm-node/sequencer/metrics"
)
Expand All @@ -15,3 +18,16 @@ func (f *finalizer) tryToSleep() {
seqMetrics.GetLogStatistics().CumulativeCounting(seqMetrics.GetTxPauseCounter)
}
}

// keepHalting keeps the finalizer halted
func (f *finalizer) keepHalting(ctx context.Context, err error) {
f.haltFinalizer.Store(true)

f.LogEvent(ctx, event.Level_Critical, event.EventID_FinalizerHalt, fmt.Sprintf("finalizer halted due to error: %s", err), nil)

for {
seqMetrics.HaltCount()
log.Errorf("keep halting finalizer, error: %v", err)
time.Sleep(5 * time.Second) //nolint:gomnd
}
}
2 changes: 1 addition & 1 deletion sequencer/l2block.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (f *finalizer) processL2Block(ctx context.Context, l2Block *L2Block) error
blockResponse.BlockNumber, l2Block.trackingNum, l2Block.metrics.log(), f.metrics.startsAt().Unix(), f.metrics.log())
}

log.Infof("%v", l2Block.metrics.Summary(blockResponse.BlockNumber, f.wipBatch.batchNumber, l2Block.timestamp))
log.Infof("%v", l2Block.metrics.Summary(blockResponse.BlockNumber, l2Block.batch.batchNumber, l2Block.timestamp))
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ STOPV1TOV2APPROVE := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSENODEAPPROVEV1TOV2) &&

STOPMETRICS := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEMETRICS) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEMETRICS)

STOPDSDATA := rm -rf datastream.bin && rm -rf datastream.db

STOP := $(DOCKERCOMPOSE) down --remove-orphans

.PHONY: test-full-non-e2e
Expand Down Expand Up @@ -693,6 +695,7 @@ run-v1tov2: ## Runs a full node using v1tov2 network
.PHONY: stop
stop: ## Stops all services
$(STOP)
$(STOPDSDATA)

.PHONY: ship
ship: ## Builds docker images and run them
Expand Down
4 changes: 2 additions & 2 deletions test/config/test.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ StateConsistencyCheckInterval = "5s"
Port = 6900
Filename = "/datastreamer/datastream.bin"
Version = 1
ChainID = 1337
Enabled = false
ChainID = 195
Enabled = true

[SequenceSender]
WaitPeriodSendSequence = "15s"
Expand Down

0 comments on commit 8100533

Please sign in to comment.