Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0171536
check unsupported precompiles (#3264)
ToniRamirezM Feb 14, 2024
eb3ae9b
fix RPC closebatch executor error (#3272)
ToniRamirezM Feb 14, 2024
2d76f12
fix executor error closebatch (#3276)
joanestebanr Feb 14, 2024
20fa91f
add oog2 checks for all the oog cheks (#3277)
tclemos Feb 14, 2024
f968d8b
fix oog2 in internal gas estimation (#3280)
ToniRamirezM Feb 16, 2024
ca5a2c2
execution mode (#3285)
ToniRamirezM Feb 16, 2024
0a58f28
update prover image (#3286)
ToniRamirezM Feb 16, 2024
857be17
fix log when error on batch sanity check (#3287)
agnusmor Feb 16, 2024
5a1782f
update prover image to v4.0.13 (#3289)
agnusmor Feb 16, 2024
a7c9c71
update prover image (#3290)
ToniRamirezM Feb 17, 2024
3b25971
fix deltaTimestamp when debug tx (#3291)
tclemos Feb 17, 2024
bfe0166
fix checkStateInconsistency when starting sequencer (#3294)
agnusmor Feb 17, 2024
8cb1842
disable delete addrQueue if empty as a workaround (#3295)
agnusmor Feb 18, 2024
03a9291
add aggregator.BatchProofL1BlockConfirmations config parameter (#3302…
agnusmor Feb 20, 2024
e13c7ad
Feature remove executor errors (#3317)
ToniRamirezM Feb 20, 2024
5a5a642
support to elderberry fork (#3301)
joanestebanr Feb 20, 2024
fabe7ee
update prover image (#3322)
ToniRamirezM Feb 21, 2024
f0093b0
Get last l2 block in a batch by batch number (#3335)
ToniRamirezM Feb 21, 2024
c091cfb
add selector for trusted sync to prevent from executing from an old t…
joanestebanr Feb 21, 2024
a86d444
synchronizer adopt GetLastL2BlockByBatchNumber to check elderberry ts…
joanestebanr Feb 21, 2024
5c2fcff
reserved zk counters (#3343)
ToniRamirezM Feb 22, 2024
a039a0a
Add reserved zk counters to pool transactions (#3346)
ToniRamirezM Feb 22, 2024
d218fe2
Merge v0.5.13 into v0.6.0 (#3350)
tclemos Feb 22, 2024
b3a1b04
Update reserved counters with used in pool db during migration (#3352)
ToniRamirezM Feb 22, 2024
1bd33f5
fix initial sequenced batch event (#3347)
joanestebanr Feb 22, 2024
19c6694
Add executor reserved ZK counters (#3348)
agnusmor Feb 23, 2024
6aacee4
fix return on node OOC. Fix logs (#3359)
agnusmor Feb 23, 2024
54b7fcd
to decode ETROG processBatches use ETROG contract (#3360)
joanestebanr Feb 23, 2024
f08d413
Synchronized inform field state.batch.closing_reason from DB
joanestebanr Feb 26, 2024
92f191d
remove unnecessary eventlog call when processing unsigned txs (#3365)
tclemos Feb 26, 2024
3ab6d44
Fix batch 0 timestamp (#3364)
tclemos Feb 27, 2024
2b70cce
ignore forkid events from another rollup (#3383)
joanestebanr Feb 27, 2024
cd4c30c
Add l2block/interval metrics. Use timeoutCond when waiting for worker…
agnusmor Feb 27, 2024
fe1dacc
Feature/cherry pick 3370 3374 synchronizer, fix bugs, ReprocessFullBa…
joanestebanr Feb 27, 2024
4769da0
fix metrics cleanUp (#3385)
agnusmor Feb 27, 2024
f7f1809
fix check poseidonHashes exhausted (#3393)
agnusmor Feb 28, 2024
e0cd81e
remove execution mode (#3395)
ToniRamirezM Feb 28, 2024
4bd2089
fix metrics estimatedTxsPerSec (#3396)
agnusmor Feb 28, 2024
858edac
Fix metrics estimatedTxsPerSec division (#3398)
agnusmor Feb 29, 2024
f4f44b5
Get IM State root from receipt for data stream. (#3400)
ToniRamirezM Feb 29, 2024
f4dd705
Add gas per second estimation in metrics (#3401)
agnusmor Feb 29, 2024
2d93d42
Feature/cherry pick 3375 sync add check l2block hash (#3406)
joanestebanr Mar 1, 2024
fe9b257
update prover image to v5.0.3 (#3407)
agnusmor Mar 1, 2024
1365a55
keep empty RPC.SequencerNodeURI config parameter to get node URI from…
agnusmor Mar 7, 2024
2261ccc
add log0 debug trace e2e tests (#3422)
tclemos Mar 8, 2024
21491a8
Elderberry blockhash adjustments (#3424)
tclemos Mar 8, 2024
76cf00f
update prover to v5.0.6 (#3437)
ToniRamirezM Mar 8, 2024
b184e2b
use empty byte array instead of all zeros for receipt poststate (#3449)
tclemos Mar 11, 2024
393d47f
L1 Synchronization process check some L2Blocks from TrustedNode (#3445)
joanestebanr Mar 12, 2024
5361315
l1sync: if local batch is WIP need to be reprocess (#3443)
joanestebanr Mar 12, 2024
8ffd1dc
Synchronizer accept forkids that are the same as in database (#3452)
joanestebanr Mar 13, 2024
b65af69
remove unnecessary eventlog call when estimating tx gas (#3457)
tclemos Mar 15, 2024
04cc024
Merge tag 'v0.6.3' into feat/merge-upstream-v0.6.3
Stefan-Ethernal Mar 22, 2024
a4aca2d
Update diff
Stefan-Ethernal Mar 22, 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
1 change: 0 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS
log.Info("trustedSequencerURL ", trustedSequencerURL)
}
zkEVMClient := client.NewClient(trustedSequencerURL)

etherManForL1 := []syncinterfaces.EthermanFullInterface{}
// If synchronizer are using sequential mode, we only need one etherman client
if cfg.Synchronizer.L1SynchronizationMode == synchronizer.ParallelMode {
Expand Down
2 changes: 2 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ SyncInterval = "1s"
SyncChunkSize = 100
TrustedSequencerURL = "" # If it is empty or not specified, then the value is read from the smc
L1SynchronizationMode = "sequential"
L1SyncCheckL2BlockHash = true
L1SyncCheckL2BlockNumberhModulus = 30
[Synchronizer.L1ParallelSynchronization]
MaxClients = 10
MaxPendingNoProcessedBlocks = 25
Expand Down
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

83 changes: 57 additions & 26 deletions docs/config-file/node-config-doc.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,16 @@
"description": "TrustedSequencerURL is the rpc url to connect and sync the trusted state",
"default": ""
},
"L1SyncCheckL2BlockHash": {
"type": "boolean",
"description": "L1SyncCheckL2BlockHash if is true when a batch is closed is force to check L2Block hash against trustedNode (only apply for permissionless)",
"default": true
},
"L1SyncCheckL2BlockNumberhModulus": {
"type": "integer",
"description": "L1SyncCheckL2BlockNumberhModulus is the modulus used to choose the l2block to check\na modules 5, for instance, means check all l2block multiples of 5 (10,15,20,...)",
"default": 30
},
"L1SynchronizationMode": {
"type": "string",
"enum": [
Expand Down
53,345 changes: 38,370 additions & 14,975 deletions docs/diff/diff.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ type storage interface {
GetBatchByForcedBatchNum(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) (*Batch, error)
AddForkID(ctx context.Context, forkID ForkIDInterval, dbTx pgx.Tx) error
GetForkIDs(ctx context.Context, dbTx pgx.Tx) ([]ForkIDInterval, error)
UpdateForkID(ctx context.Context, forkID ForkIDInterval, dbTx pgx.Tx) error
UpdateForkIDToBatchNumber(ctx context.Context, forkID ForkIDInterval, dbTx pgx.Tx) error
UpdateForkIDBlockNumber(ctx context.Context, forkdID uint64, newBlockNumber uint64, updateMemCache bool, dbTx pgx.Tx) error
GetNativeBlockHashesInRange(ctx context.Context, fromBlock, toBlock uint64, dbTx pgx.Tx) ([]common.Hash, error)
GetDSGenesisBlock(ctx context.Context, dbTx pgx.Tx) (*DSL2Block, error)
GetDSBatches(ctx context.Context, firstBatchNumber, lastBatchNumber uint64, readWIPBatch bool, dbTx pgx.Tx) ([]*DSBatch, error)
Expand Down
82 changes: 66 additions & 16 deletions state/mocks/mock_storage.go

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

23 changes: 21 additions & 2 deletions state/pgstatestorage/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *PostgresStorage) GetForkIDs(ctx context.Context, dbTx pgx.Tx) ([]state.
}

// UpdateForkID updates the forkID stored in db
func (p *PostgresStorage) UpdateForkID(ctx context.Context, forkID state.ForkIDInterval, dbTx pgx.Tx) error {
func (p *PostgresStorage) UpdateForkIDToBatchNumber(ctx context.Context, forkID state.ForkIDInterval, dbTx pgx.Tx) error {
const updateForkIDSQL = "UPDATE state.fork_id SET to_batch_num = $1 WHERE fork_id = $2"
e := p.getExecQuerier(dbTx)
if _, err := e.Exec(ctx, updateForkIDSQL, forkID.ToBatchNumber, forkID.ForkId); err != nil {
Expand All @@ -60,6 +60,25 @@ func (p *PostgresStorage) UpdateForkID(ctx context.Context, forkID state.ForkIDI
return nil
}

// UpdateForkID updates the forkID stored in db
func (p *PostgresStorage) UpdateForkIDBlockNumber(ctx context.Context, forkdID uint64, newBlockNumber uint64, updateMemCache bool, dbTx pgx.Tx) error {
const sql = "UPDATE state.fork_id SET block_num = $1 WHERE fork_id = $2"
e := p.getExecQuerier(dbTx)
if _, err := e.Exec(ctx, sql, forkdID, newBlockNumber); err != nil {
return err
}
if updateMemCache {
log.Debugf("Updating forkID %d in memory", forkdID)
forkIDs, err := p.GetForkIDs(ctx, dbTx)
if err != nil {
log.Error("error getting oldForkIDs. Error: ", err)
return err
}
p.UpdateForkIDIntervalsInMemory(forkIDs)
}
return nil
}

// UpdateForkIDIntervalsInMemory updates the forkID intervals in memory
func (p *PostgresStorage) UpdateForkIDIntervalsInMemory(intervals []state.ForkIDInterval) {
log.Infof("Updating forkIDs. Setting %d forkIDs", len(intervals))
Expand Down Expand Up @@ -88,7 +107,7 @@ func (p *PostgresStorage) AddForkIDInterval(ctx context.Context, newForkID state
return err
}
forkIDs[len(forkIDs)-1].ToBatchNumber = newForkID.FromBatchNumber - 1
err := p.UpdateForkID(ctx, forkIDs[len(forkIDs)-1], dbTx)
err := p.UpdateForkIDToBatchNumber(ctx, forkIDs[len(forkIDs)-1], dbTx)
if err != nil {
log.Errorf("error updating forkID: %d. Error: %v", forkIDs[len(forkIDs)-1].ForkId, err)
return err
Expand Down
2 changes: 1 addition & 1 deletion state/pgstatestorage/pgstatestorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func TestForkIDs(t *testing.T) {
require.Equal(t, forks[i].Version, forkId.Version)
}
forkID3.ToBatchNumber = 18446744073709551615
err = testState.UpdateForkID(ctx, forkID3, dbTx)
err = testState.UpdateForkIDToBatchNumber(ctx, forkID3, dbTx)
require.NoError(t, err)

forkIDs, err = testState.GetForkIDs(ctx, dbTx)
Expand Down
19 changes: 19 additions & 0 deletions state/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
}
}

// gets the L1InfoTreeData for the transactions
l1InfoTreeData, _, _, err = s.GetL1InfoTreeDataFromBatchL2Data(ctx, transactions, dbTx)
if err != nil {
return nil, err
}

// In case we have any l1InfoTreeData, add them to the request
if len(l1InfoTreeData) > 0 {
processBatchRequestV2.L1InfoTreeData = map[uint32]*executor.L1DataV2{}
processBatchRequestV2.SkipVerifyL1InfoRoot = cTrue
for k, v := range l1InfoTreeData {
processBatchRequestV2.L1InfoTreeData[k] = &executor.L1DataV2{
GlobalExitRoot: v.GlobalExitRoot.Bytes(),
BlockHashL1: v.BlockHashL1.Bytes(),
MinTimestamp: v.MinTimestamp,
}
}
}

// Send Batch to the Executor
startTime = time.Now()
processBatchResponseV2, err := s.executorClient.ProcessBatchV2(ctx, processBatchRequestV2)
Expand Down
1 change: 0 additions & 1 deletion state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,6 @@ func (s *State) internalTestGasEstimationTransactionV2(ctx context.Context, batc
}
if processBatchResponseV2.ErrorRom != executor.RomError_ROM_ERROR_NO_ERROR {
err = executor.RomErr(processBatchResponseV2.ErrorRom)
s.eventLog.LogExecutorErrorV2(ctx, processBatchResponseV2.Error, processBatchRequestV2)
return false, false, gasUsed, nil, err
}

Expand Down
139 changes: 139 additions & 0 deletions synchronizer/actions/check_l2block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package actions

import (
"context"
"errors"
"fmt"
"math/big"

"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/jackc/pgx/v4"
)

// Implements PostClosedBatchChecker

type stateGetL2Block interface {
GetL2BlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.L2Block, error)
GetLastL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
}

type trustedRPCGetL2Block interface {
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
}

// CheckL2BlockHash is a struct that implements a checker of L2Block hash
type CheckL2BlockHash struct {
state stateGetL2Block
trustedClient trustedRPCGetL2Block
lastL2BlockChecked uint64
// Is a modulus used to choose the l2block to check
modulusL2BlockToCheck uint64
}

// NewCheckL2BlockHash creates a new CheckL2BlockHash
func NewCheckL2BlockHash(state stateGetL2Block,
trustedClient trustedRPCGetL2Block,
initialL2BlockNumber uint64,
modulusBlockNumber uint64) *CheckL2BlockHash {
return &CheckL2BlockHash{
state: state,
trustedClient: trustedClient,
lastL2BlockChecked: initialL2BlockNumber,
modulusL2BlockToCheck: modulusBlockNumber,
}
}

// CheckL2Block checks the L2Block hash between the local and the trusted
func (p *CheckL2BlockHash) CheckL2Block(ctx context.Context, dbTx pgx.Tx) error {
lastLocalL2BlockNumber, err := p.state.GetLastL2BlockNumber(ctx, dbTx)
if errors.Is(err, state.ErrNotFound) || errors.Is(err, state.ErrStateNotSynchronized) {
log.Debugf("checkL2block:No L2Block in database. err: %s", err.Error())
return nil
}
if err != nil {
log.Errorf("checkL2block: Error getting last L2Block from the database. err: %s", err.Error())
return err
}
shouldCheck, l2BlockNumber := p.GetNextL2BlockToCheck(lastLocalL2BlockNumber, p.GetMinimumL2BlockToCheck())
if !shouldCheck {
return nil
}
err = p.iterationCheckL2Block(ctx, l2BlockNumber, dbTx)
if err != nil {
return err
}
return nil
}

// GetNextL2BlockToCheck returns true is need to check and the blocknumber
func (p *CheckL2BlockHash) GetNextL2BlockToCheck(lastLocalL2BlockNumber, minL2BlockNumberToCheck uint64) (bool, uint64) {
l2BlockNumber := max(minL2BlockNumberToCheck, lastLocalL2BlockNumber)
if l2BlockNumber > lastLocalL2BlockNumber {
log.Infof("checkL2block: skip check L2block (next to check: %d) currently LastL2BlockNumber: %d", minL2BlockNumberToCheck, lastLocalL2BlockNumber)
return false, 0
}
return true, l2BlockNumber
}

// GetMinimumL2BlockToCheck returns the minimum L2Block to check
func (p *CheckL2BlockHash) GetMinimumL2BlockToCheck() uint64 {
if p.modulusL2BlockToCheck == 0 {
return p.lastL2BlockChecked + 1
}
return ((p.lastL2BlockChecked / p.modulusL2BlockToCheck) + 1) * p.modulusL2BlockToCheck
}

// GetL2Blocks returns localL2Block and trustedL2Block
func (p *CheckL2BlockHash) GetL2Blocks(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.L2Block, *types.Block, error) {
localL2Block, err := p.state.GetL2BlockByNumber(ctx, blockNumber, dbTx)
if err != nil {
log.Debugf("checkL2block: Error getting L2Block %d from the database. err: %s", blockNumber, err.Error())
return nil, nil, err
}
trustedL2Block, err := p.trustedClient.BlockByNumber(ctx, big.NewInt(int64(blockNumber)))
if err != nil {
log.Errorf("checkL2block: Error getting L2Block %d from the Trusted RPC. err:%s", blockNumber, err.Error())
return nil, nil, err
}
return localL2Block, trustedL2Block, nil
}

// CheckPostClosedBatch checks the last L2Block hash on close batch
func (p *CheckL2BlockHash) iterationCheckL2Block(ctx context.Context, l2BlockNumber uint64, dbTx pgx.Tx) error {
prefixLogs := fmt.Sprintf("checkL2block: L2BlockNumber: %d ", l2BlockNumber)
localL2Block, trustedL2Block, err := p.GetL2Blocks(ctx, l2BlockNumber, dbTx)
if errors.Is(err, state.ErrNotFound) || errors.Is(err, state.ErrStateNotSynchronized) {
log.Debugf("%s not found in the database", prefixLogs, l2BlockNumber)
return nil
}
if err != nil {
log.Errorf("%s Error getting from the database and trusted. err: %s", prefixLogs, err.Error())
return err
}
if localL2Block == nil || trustedL2Block == nil {
log.Errorf("%s localL2Block or trustedL2Block is nil", prefixLogs, l2BlockNumber)
return nil
}

if err := compareL2Blocks(prefixLogs, localL2Block, trustedL2Block); err != nil {
log.Errorf("%s Error comparing L2Blocks from the database and trusted. err: %s", prefixLogs, err.Error())
return err
}

log.Infof("%s checked L2Block in the database and the trusted batch are the same %s", prefixLogs, localL2Block.Hash().String())
// Compare the two blocks
p.lastL2BlockChecked = l2BlockNumber
return nil
}

func compareL2Blocks(prefixLogs string, localL2Block *state.L2Block, trustedL2Block *types.Block) error {
if localL2Block == nil || trustedL2Block == nil || trustedL2Block.Hash == nil {
return fmt.Errorf("%s localL2Block or trustedL2Block or trustedHash are nil", prefixLogs)
}
if localL2Block.Hash() != *trustedL2Block.Hash {
return fmt.Errorf("%s localL2Block.Hash %s and trustedL2Block.Hash %s are different", prefixLogs, localL2Block.Hash().String(), (*trustedL2Block.Hash).String())
}
return nil
}
Loading