-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
synchronizer: check l1blocks (#3546)
* wip * run on background L1block checker * fix lint and documentation * fix conflict * add unittest * more unittest * fix lint * increase timeout for async unittest * fix unittest * rename GetResponse for GetResult and fix uniitest * add a second gorutines for check the newest blocks * more unittest * add unittest and run also preCheck on launch * by default Precheck from FINALIZED and SAFE * fix unittest, apply PR comments * changes suggested by ARR552 in integration method * fix documentation * import new network-l1-mock from PR#3553 * import new network-l1-mock from PR#3553 * import new network-l1-mock from PR#3553 * import new network-l1-mock from PR#3553 * fix unittest * fix PR comments * fix error * checkReorgAndExecuteReset can't be call with lastEthBlockSynced=nil * add parentHash to error * fix error * merge 3553 fix unittest * fix unittest * fix wrong merge * adapt parallel reorg detection to flow * fix unit tests * fix log * allow use sync parallel mode --------- Co-authored-by: Alonso <ARR551@protonmail.com>
- Loading branch information
Showing
38 changed files
with
3,756 additions
and
160 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package common | ||
|
||
import "fmt" | ||
|
||
// ReorgError is an error that is raised when a reorg is detected | ||
type ReorgError struct { | ||
// BlockNumber is the block number that caused the reorg | ||
BlockNumber uint64 | ||
Err error | ||
} | ||
|
||
// NewReorgError creates a new ReorgError | ||
func NewReorgError(blockNumber uint64, err error) *ReorgError { | ||
return &ReorgError{ | ||
BlockNumber: blockNumber, | ||
Err: err, | ||
} | ||
} | ||
|
||
func (e *ReorgError) Error() string { | ||
return fmt.Sprintf("%s blockNumber: %d", e.Err.Error(), e.BlockNumber) | ||
} | ||
|
||
// IsReorgError checks if an error is a ReorgError | ||
func IsReorgError(err error) bool { | ||
_, ok := err.(*ReorgError) | ||
return ok | ||
} | ||
|
||
// GetReorgErrorBlockNumber returns the block number that caused the reorg | ||
func GetReorgErrorBlockNumber(err error) uint64 { | ||
if reorgErr, ok := err.(*ReorgError); ok { | ||
return reorgErr.BlockNumber | ||
} | ||
return 0 | ||
} | ||
|
||
// GetReorgError returns the error that caused the reorg | ||
func GetReorgError(err error) error { | ||
if reorgErr, ok := err.(*ReorgError); ok { | ||
return reorgErr.Err | ||
} | ||
return nil | ||
} |
40 changes: 40 additions & 0 deletions
40
synchronizer/common/syncinterfaces/async_l1_block_checker.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package syncinterfaces | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/0xPolygonHermez/zkevm-node/state" | ||
) | ||
|
||
type IterationResult struct { | ||
Err error | ||
ReorgDetected bool | ||
BlockNumber uint64 | ||
ReorgMessage string | ||
} | ||
|
||
func (ir *IterationResult) String() string { | ||
if ir.Err == nil { | ||
if ir.ReorgDetected { | ||
return fmt.Sprintf("IterationResult{ReorgDetected: %v, BlockNumber: %d ReorgMessage:%s}", ir.ReorgDetected, ir.BlockNumber, ir.ReorgMessage) | ||
} else { | ||
return "IterationResult{None}" | ||
} | ||
} else { | ||
return fmt.Sprintf("IterationResult{Err: %s, ReorgDetected: %v, BlockNumber: %d ReorgMessage:%s}", ir.Err.Error(), ir.ReorgDetected, ir.BlockNumber, ir.ReorgMessage) | ||
} | ||
} | ||
|
||
type AsyncL1BlockChecker interface { | ||
Run(ctx context.Context, onFinish func()) | ||
RunSynchronous(ctx context.Context) IterationResult | ||
Stop() | ||
GetResult() *IterationResult | ||
} | ||
|
||
type L1BlockCheckerIntegrator interface { | ||
OnStart(ctx context.Context) error | ||
OnResetState(ctx context.Context) | ||
CheckReorgWrapper(ctx context.Context, reorgFirstBlockOk *state.Block, errReportedByReorgFunc error) (*state.Block, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.