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

synchronizer: check l1blocks #3546

Merged
merged 38 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4dc61a2
wip
joanestebanr Apr 8, 2024
a8c6ff7
Merge branch 'release/v0.6.5' into feature/3540-check_l1blocks
joanestebanr Apr 8, 2024
ef4daee
Merge branch 'release/v0.6.5' into feature/3540-check_l1blocks
joanestebanr Apr 8, 2024
67a4319
run on background L1block checker
joanestebanr Apr 9, 2024
c94866c
fix lint and documentation
joanestebanr Apr 9, 2024
cbcdd7a
Merge branch 'release/v0.6.6' into feature/3540-check_l1blocks
joanestebanr Apr 9, 2024
4e01e3a
fix conflict
joanestebanr Apr 9, 2024
5e27271
add unittest
joanestebanr Apr 9, 2024
1b0cd7f
more unittest
joanestebanr Apr 10, 2024
7edad4f
fix lint
joanestebanr Apr 10, 2024
73264a0
increase timeout for async unittest
joanestebanr Apr 10, 2024
2751e54
fix unittest
joanestebanr Apr 11, 2024
14c1c49
rename GetResponse for GetResult and fix uniitest
joanestebanr Apr 11, 2024
4e65b4f
add a second gorutines for check the newest blocks
joanestebanr Apr 11, 2024
6a40470
more unittest
joanestebanr Apr 12, 2024
aa36f31
add unittest and run also preCheck on launch
joanestebanr Apr 12, 2024
48ec900
by default Precheck from FINALIZED and SAFE
joanestebanr Apr 12, 2024
256feee
fix unittest, apply PR comments
joanestebanr Apr 12, 2024
045f468
changes suggested by ARR552 in integration method
joanestebanr Apr 12, 2024
2a5764f
fix documentation
joanestebanr Apr 12, 2024
531b006
import new network-l1-mock from PR#3553
joanestebanr Apr 12, 2024
cd89095
import new network-l1-mock from PR#3553
joanestebanr Apr 12, 2024
babcd8a
import new network-l1-mock from PR#3553
joanestebanr Apr 12, 2024
329e025
import new network-l1-mock from PR#3553
joanestebanr Apr 12, 2024
2da279d
fix unittest
joanestebanr Apr 13, 2024
3956335
fix PR comments
joanestebanr Apr 15, 2024
ba3d2c6
fix error
joanestebanr Apr 15, 2024
05c57e4
checkReorgAndExecuteReset can't be call with lastEthBlockSynced=nil
joanestebanr Apr 15, 2024
feac8e9
add parentHash to error
joanestebanr Apr 15, 2024
fb4f8f9
fix error
joanestebanr Apr 15, 2024
c2e12f8
Merge branch 'release/v0.6.6' into feature/3540-check_l1blocks
joanestebanr Apr 15, 2024
74699b8
merge 3553 fix unittest
joanestebanr Apr 15, 2024
9da7f3c
fix unittest
joanestebanr Apr 15, 2024
c5d246c
fix wrong merge
joanestebanr Apr 15, 2024
dcb271c
adapt parallel reorg detection to flow
joanestebanr Apr 15, 2024
ad9144d
fix unit tests
ARR552 Apr 16, 2024
f791f26
fix log
ARR552 Apr 16, 2024
63ccaab
allow use sync parallel mode
ARR552 Apr 16, 2024
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
32 changes: 16 additions & 16 deletions config/environments/local/local.genesis.config.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1540,15 +1540,15 @@ PreCheckEnable=true

**Type:** : `enum (of string)`

**Default:** `"latest"`
**Default:** `"safe"`

**Description:** L1PreSafeBlockPoint is the point that a block is considered safe enough to be checked
it can be: finalized, safe,pending or latest

**Example setting the default value** ("latest"):
**Example setting the default value** ("safe"):
```
[Synchronizer.L1BlockCheck]
L1PreSafeBlockPoint="latest"
L1PreSafeBlockPoint="safe"
```

Must be one of:
Expand All @@ -1560,16 +1560,16 @@ Must be one of:

**Type:** : `integer`

**Default:** `-32`
**Default:** `0`

**Description:** L1PreSafeBlockOffset is the offset to add to L1PreSafeBlockPoint as a safe point
it can be positive or negative
Example: L1PreSafeBlockPoint= finalized, L1PreSafeBlockOffset= -10, then the safe block ten blocks before the finalized block

**Example setting the default value** (-32):
**Example setting the default value** (0):
```
[Synchronizer.L1BlockCheck]
L1PreSafeBlockOffset=-32
L1PreSafeBlockOffset=0
```

### <a name="Synchronizer_L1SynchronizationMode"></a>9.8. `Synchronizer.L1SynchronizationMode`
Expand Down
4 changes: 2 additions & 2 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,12 @@
"latest"
],
"description": "L1PreSafeBlockPoint is the point that a block is considered safe enough to be checked\nit can be: finalized, safe,pending or latest",
"default": "latest"
"default": "safe"
},
"L1PreSafeBlockOffset": {
"type": "integer",
"description": "L1PreSafeBlockOffset is the offset to add to L1PreSafeBlockPoint as a safe point\nit can be positive or negative\nExample: L1PreSafeBlockPoint= finalized, L1PreSafeBlockOffset= -10, then the safe block ten blocks before the finalized block",
"default": -32
"default": 0
}
},
"additionalProperties": false,
Expand Down
4 changes: 2 additions & 2 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func NewClient(cfg Config, l1Config L1Config) (*Client, error) {
rollupID, err := rollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, l1Config.ZkEVMAddr)
if err != nil {
log.Debugf("error rollupManager.RollupAddressToID(%s). Error: %w", l1Config.RollupManagerAddr, err)
// TODO return error after the upgrade
return nil, err
}
log.Debug("rollupID: ", rollupID)

Expand Down Expand Up @@ -1512,7 +1512,7 @@ func (etherMan *Client) forceSequencedBatchesEvent(ctx context.Context, vLog typ
if err != nil {
return err
}
// TODO completar los datos de forcedBlockHas, forcedGer y forcedTimestamp
// TODO complete data forcedBlockHash, forcedGer y forcedTimestamp

// Read the tx for this batch.
tx, err := etherMan.EthClient.TransactionInBlock(ctx, vLog.BlockHash, vLog.TxIndex)
Expand Down
2 changes: 0 additions & 2 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func (e *EthEndpoints) Call(arg *types.TxArgs, blockArg *types.BlockNumberOrHash
return e.txMan.NewDbTxScope(e.state, func(ctx context.Context, dbTx pgx.Tx) (interface{}, types.Error) {
if arg == nil {
return RPCErrorResponse(types.InvalidParamsErrorCode, "missing value for required argument 0", nil, false)
} else if blockArg == nil {
return RPCErrorResponse(types.InvalidParamsErrorCode, "missing value for required argument 1", nil, false)
}
block, respErr := e.getBlockByArg(ctx, blockArg, dbTx)
if respErr != nil {
Expand Down
1 change: 1 addition & 0 deletions state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ type storage interface {
UpdateBatchAsChecked(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) error
GetNotCheckedBatches(ctx context.Context, dbTx pgx.Tx) ([]*Batch, error)
GetLastL2BlockByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*L2Block, error)
GetPreviousBlockToBlockNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*Block, error)
}
60 changes: 60 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.

20 changes: 20 additions & 0 deletions state/pgstatestorage/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ func (p *PostgresStorage) GetPreviousBlock(ctx context.Context, offset uint64, d
return &block, err
}

// GetPreviousBlockToBlockNumber gets the previous L1 block respect blockNumber.
func (p *PostgresStorage) GetPreviousBlockToBlockNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.Block, error) {
var (
blockHash string
parentHash string
block state.Block
)
const getPreviousBlockSQL = "SELECT block_num, block_hash, parent_hash, received_at,checked FROM state.block WHERE block_num < $1 ORDER BY block_num DESC LIMIT 1 "

q := p.getExecQuerier(dbTx)

err := q.QueryRow(ctx, getPreviousBlockSQL, blockNumber).Scan(&block.BlockNumber, &blockHash, &parentHash, &block.ReceivedAt, &block.Checked)
if errors.Is(err, pgx.ErrNoRows) {
return nil, state.ErrNotFound
}
block.BlockHash = common.HexToHash(blockHash)
block.ParentHash = common.HexToHash(parentHash)
return &block, err
}

// GetBlockByNumber returns the L1 block with the given number.
func (p *PostgresStorage) GetBlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.Block, error) {
var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type AsyncL1BlockChecker interface {

type L1BlockCheckerIntegrator interface {
OnStart(ctx context.Context) error
OnStartL1Sync(ctx context.Context) bool
OnStartL2Sync(ctx context.Context) bool
OnCheckReorg(ctx context.Context, latestBlock *state.Block) bool
OnResetState(ctx context.Context)
CheckReorgWrapper(ctx context.Context, reorgFirstBlockOk *state.Block, errReportedByReorgFunc error) (*state.Block, error)
}
Loading
Loading