Skip to content

Commit

Permalink
Feature/3173 sync trusted state in networks previous to ETROG (0xPoly…
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr authored Feb 1, 2024
1 parent 5583622 commit a110d2e
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 31 deletions.
1 change: 1 addition & 0 deletions state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ type storage interface {
GetForcedBatchParentHash(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) (common.Hash, error)
GetLatestBatchGlobalExitRoot(ctx context.Context, dbTx pgx.Tx) (common.Hash, error)
GetL2TxHashByTxHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (common.Hash, error)
GetForkIDInMemory(forkId uint64) *ForkIDInterval
}
48 changes: 48 additions & 0 deletions state/mocks/mock_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions state/pgstatestorage/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,13 @@ func (p *PostgresStorage) GetForkIDByBatchNumber(batchNumber uint64) uint64 {
// If not found return the last fork id
return p.cfg.ForkIDIntervals[len(p.cfg.ForkIDIntervals)-1].ForkId
}

// GetForkIDInMemory get the forkIDs stored in cache, or nil if not found
func (p *PostgresStorage) GetForkIDInMemory(forkId uint64) *state.ForkIDInterval {
for _, interval := range p.cfg.ForkIDIntervals {
if interval.ForkId == forkId {
return &interval
}
}
return nil
}
48 changes: 48 additions & 0 deletions synchronizer/common/syncinterfaces/mocks/state_full_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions synchronizer/common/syncinterfaces/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ type StateFullInterface interface {
UpdateWIPBatch(ctx context.Context, receipt state.ProcessingReceipt, dbTx pgx.Tx) error
GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]state.L1DataV2, common.Hash, common.Hash, error)
GetExitRootByGlobalExitRoot(ctx context.Context, ger common.Hash, dbTx pgx.Tx) (*state.GlobalExitRoot, error)
GetForkIDInMemory(forkId uint64) *state.ForkIDInterval
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package syncinterfaces
import (
"context"
"errors"

"github.com/0xPolygonHermez/zkevm-node/state"
)

var (
Expand All @@ -15,8 +17,12 @@ var (
// SyncTrustedStateExecutor is the interface that class that synchronize permissionless with a trusted node
type SyncTrustedStateExecutor interface {
// SyncTrustedState syncs the trusted state with the permissionless state
// maximumBatchToProcess: maximum Batchnumber of batches to process, after have to returns
// if returns error ErrMissingSyncFromL1 then must force a L1 sync
SyncTrustedState(ctx context.Context, latestSyncedBatch uint64) error
//
SyncTrustedState(ctx context.Context, latestSyncedBatch uint64, maximumBatchNumberToProcess uint64) error
// CleanTrustedState clean cache of Batches and StateRoot
CleanTrustedState()
// Returns the cached data for a batch
GetCachedBatch(batchNumber uint64) *state.Batch
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a110d2e

Please sign in to comment.