Skip to content

Commit

Permalink
Merge pull request #72 from 0xPolygonHermez/fix/71_70-updateEtrog-syn…
Browse files Browse the repository at this point in the history
…c_flag

Fix/71 70 update etrog sync flag
  • Loading branch information
joanestebanr authored Jun 11, 2024
2 parents 13869fd + e66446b commit c2cdfef
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 8 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/check_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check Version
on:
push:
branches:
- 'release/**'
- 'feature/**'
- 'fix/**'
pull_request:
jobs:
check_version:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v4
- name: Check Version
run: make check-is-new-version
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ install-linter: ## Installs the linter
lint: ## Runs the linter
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/golangci-lint run --timeout=5m



.PHONY: lint
check-is-new-version: ## Checks if the version is new or already exists
@export VERSION=$$(go run ./cmd/ --version | cut -f 3 -d ' ') ; \
echo "current version: $$VERSION" ; \
if [ -z "$$VERSION" ]; then echo "Error: Version is empty" && exit 1; fi ; \
git tag -l $$VERSION | grep $$VERSION ; \
if [ $$? -eq 0 ]; then echo "Error: Version already exists"; exit 1; fi ; \
echo "Version is new"



.PHONY: update-external-dependencies
Expand Down
8 changes: 7 additions & 1 deletion cmd/run/run_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ func RunCmd(cliCtx *cli.Context) error {
log.Error("Error creating synchronizer", err)
return err
}
return sync.Sync(true)
err = sync.Sync(false)
if err != nil {
log.Error("Error syncing", err)
} else {
log.Info("Syncing done")
}
return err
}
2 changes: 1 addition & 1 deletion config/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDefault(t *testing.T) {
MaxConns: 10,
},
Synchronizer: syncconfig.Config{
SyncInterval: types.Duration{time.Second * 10},
SyncInterval: types.Duration{Duration: time.Second * 10},
SyncChunkSize: 500,
GenesisBlockNumber: 0,
SyncUpToBlock: "latest",
Expand Down
60 changes: 60 additions & 0 deletions synchronizer/actions/etrog/processor_l1_update_etrog_sequence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package etrog

import (
"context"
"time"

"github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/synchronizer/actions"
"github.com/ethereum/go-ethereum/common"
)

// ProcessorL1UpdateEtrogSequence implements L1EventProcessor
type ProcessorL1UpdateEtrogSequence struct {
actions.ProcessorBase[ProcessorL1UpdateEtrogSequence]
state stateOnSequencedBatchesInterface
}

// NewProcessorL1UpdateEtrogSequence returns instance of a processor for UpdateEtrogSequenceOrder
func NewProcessorL1UpdateEtrogSequence(state stateOnSequencedBatchesInterface,
) *ProcessorL1UpdateEtrogSequence {
return &ProcessorL1UpdateEtrogSequence{
ProcessorBase: actions.ProcessorBase[ProcessorL1UpdateEtrogSequence]{
SupportedEvent: []etherman.EventOrder{etherman.UpdateEtrogSequenceOrder},
SupportedForkdIds: &actions.ForksIdOnlyEtrog},
state: state,
}
}

// Process process event
func (p *ProcessorL1UpdateEtrogSequence) Process(ctx context.Context, forkId ForkIdType, order etherman.Order, l1Block *etherman.Block, dbTx stateTxType) error {
if l1Block == nil || l1Block.UpdateEtrogSequence.BatchNumber == 0 {
return actions.ErrInvalidParams
}
err := p.processUpdateEtrogSequence(ctx, forkId, order, l1Block.UpdateEtrogSequence, l1Block.BlockNumber, l1Block.ReceivedAt, dbTx)
return err
}

func (p *ProcessorL1UpdateEtrogSequence) processUpdateEtrogSequence(ctx context.Context, forkId ForkIdType, order etherman.Order, updateEtrogSequence etherman.UpdateEtrogSequence, blockNumber uint64, l1BlockTimestamp time.Time, dbTx stateTxType) error {
l1inforoot := common.Hash(updateEtrogSequence.PolygonRollupBaseEtrogBatchData.ForcedGlobalExitRoot)
seq := SequenceOfBatches{}
seq.Sequence = *entities.NewSequencedBatches(
updateEtrogSequence.BatchNumber, updateEtrogSequence.BatchNumber,
blockNumber, uint64(forkId),
l1BlockTimestamp, time.Now(),
l1inforoot, string(order.Name))
ethSeqBatch := etherman.SequencedBatch{
BatchNumber: updateEtrogSequence.BatchNumber,
L1InfoRoot: &l1inforoot,
SequencerAddr: updateEtrogSequence.SequencerAddr,
TxHash: updateEtrogSequence.TxHash,
PolygonRollupBaseEtrogBatchData: updateEtrogSequence.PolygonRollupBaseEtrogBatchData,
}

batch := entities.NewVirtualBatchFromL1(blockNumber, seq.Sequence.FromBatchNumber, uint64(forkId), ethSeqBatch)

seq.Batches = append(seq.Batches, batch)

return p.state.OnSequencedBatchesOnL1(ctx, seq, dbTx)
}
1 change: 1 addition & 0 deletions synchronizer/internal/synchronizer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func newL1EventProcessor(state syncinterfaces.StateInterface) *processor_manager
builder.Register(incaberry.NewProcessorForkId(state))
builder.Register(etrog.NewProcessorL1InitialSequenceBatches(state))
builder.Register(elderberry.NewProcessorL1SequenceBatchesElderberry(etrogSequenceBatchesProcessor))
builder.Register(etrog.NewProcessorL1UpdateEtrogSequence(state))
return builder.Build()
}

Expand Down
8 changes: 7 additions & 1 deletion synchronizer/l1_sync/l1_syncer_sequential.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *L1SequentialSync) SyncBlocks(ctx context.Context, lastEthBlockSynced *s
return lastEthBlockSynced, true, nil
}
blockRange := blockRangeIterator.GetRange(lastEthBlockSynced.IsUnsafeAndHaveRollupdata())
log.Infof("Syncing %s", blockRangeIterator.String())
log.Infof("Syncing %s Progress: %s", blockRangeIterator.String(), s.calculateProgress(blockRange, blockPoints))
synced := false
lastEthBlockSynced, synced, err = s.iteration(ctx, blockRange, blockPoints.L1FinalizedBlockNumber, lastEthBlockSynced)
if err != nil {
Expand All @@ -168,6 +168,12 @@ func (s *L1SequentialSync) SyncBlocks(ctx context.Context, lastEthBlockSynced *s
return lastEthBlockSynced, true, nil
}

func (s *L1SequentialSync) calculateProgress(blockRange BlockRange, blockPoints BlockPoints) string {
totalBlocksToProcess := blockPoints.L1LastBlockToSync - s.cfg.GenesisBlockNumber
blocksProcessed := blockRange.FromBlock - s.cfg.GenesisBlockNumber
return fmt.Sprintf("Percent: %3.1f", float32(blocksProcessed*100)/float32(totalBlocksToProcess))
}

func (s *L1SequentialSync) checkResponseGetRollupInfoByBlockRangeForOverlappedFirstBlock(blocks []etherman.Block, fromBlock uint64) error {
if len(blocks) != 0 {
initBlockReceived := &blocks[0]
Expand Down
5 changes: 4 additions & 1 deletion synchronizer/l1event_orders/sequence_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func GetSequenceFromL1EventOrder(event etherman.EventOrder, l1Block *etherman.Bl
case etherman.InitialSequenceBatchesOrder:
return getSequence(l1Block.SequencedBatches[position],
func(batch etherman.SequencedBatch) uint64 { return batch.BatchNumber })

case etherman.UpdateEtrogSequenceOrder:
seq := Sequence{FromBatchNumber: l1Block.UpdateEtrogSequence.BatchNumber,
ToBatchNumber: l1Block.UpdateEtrogSequence.BatchNumber}
return &seq
}
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion synchronizer/synchronizer_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func (s *SynchronizerAdapter) SetCallbackOnReorgDone(callback func(reorgData Reo
}

func (s *SynchronizerAdapter) Sync(returnOnSync bool) error {
return s.internalSyncrhonizer.Sync(internal.FlagReturnOnSync)
var flags internal.SyncExecutionFlags
if returnOnSync {
flags = internal.FlagReturnOnSync
}
return s.internalSyncrhonizer.Sync(flags)
}

func (s *SynchronizerAdapter) Stop() {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var (
Version = "v0.5.3"
Version = "v0.5.4"
)

// PrintVersion prints version info into the provided io.Writer.
Expand Down

0 comments on commit c2cdfef

Please sign in to comment.