Skip to content

Commit

Permalink
Pullupstream/v0.5.6 (#70)
Browse files Browse the repository at this point in the history
* fix migration batch wip field. fix sequence when no wip batch (0xPolygonHermez#3126)

* fix Leaves smtproof (0xPolygonHermez#3127)

* fix Leaves smtproof

* pointer protection

* fix unit test

* Add l2block log dump when storing error. Refactor ProcessBatchV2 logs (0xPolygonHermez#3129)

* add l2block log dump when storing error. refactor ProcessBatchV2 logs

* add AddL2Block log

* fix index AddL2Block log

* use aux variable to avoid reusing poiner

---------

Co-authored-by: Toni Ramírez <toni@polygon.technology>

* fix panic etherman (0xPolygonHermez#3133)

* Fix GetL2Hash function. Use tx L2 hash returned by the executor when storing L2Block. Logs changes (0xPolygonHermez#3134)

* fix l2 hash when to is nill

* get l2 hash from executor

* fix use tx L2 hash returned by the executor when storing L2Block. Logs changes

* fix linter

* add L2block tracking number to process tx logs

* fix ProcessBatchV2 log format

* fix UTs. set useMainExecGenerated to true

* set prover image to v4.0.0-RC30

* test setting useMainExecGenerated = false

* fix independent_test

* fix non-e2e tests

---------

Co-authored-by: Toni Ramírez <toni@polygon.technology>

* remove l2 tx hash computation and use data stored in the state returned by the executor (0xPolygonHermez#3139)

* etrog: fix permissionless errors (0xPolygonHermez#3140)

* if got an error getting lastBlock produce a SIGSEGV

* reduce info logs

* fix unittest

* Fix missing batch bookmark (0xPolygonHermez#3122)

* fix missingBookMark

* fix missingBookMark

* fixes

* fix

* fix

* fix seq-sender config

* fixes

* doc

* fix wipL2Block deltaTimestamp (0xPolygonHermez#3142)

* improve open new wipL2Block logs

* fix wipL2Block deltaTimestamp

* ensure tx order in stream (0xPolygonHermez#3144)

* fix wipL2Block stateRoot (0xPolygonHermez#3145)

* fix panic NewStackTrie (0xPolygonHermez#3146)

* fix sync initalization for etrog (0xPolygonHermez#3147)

* fix wipL2block imStateRoot (0xPolygonHermez#3148)

* fix tracer to work by block stateroot instead of by tx (0xPolygonHermez#3150)

* update prover image (0xPolygonHermez#3151)

* if a trusted batch is empty and WIP just create the entry in state.batch (0xPolygonHermez#3152)

* fix trace for tx index greater than 0 (0xPolygonHermez#3153)

* add cardona.zip (0xPolygonHermez#3154)

* Fix default value when creating transaction.used_sha256_hashes field in the pool (0xPolygonHermez#3156)

* set DEFAULT 0 when creatingtransaction.used_sha256_hashes field in the pool

* update prover image to v4.0.0

* add cardona testnet (0xPolygonHermez#2909) (0xPolygonHermez#3155)

* add cardona testnet (0xPolygonHermez#2909)
* update config
* update cardona genesis

---------

Co-authored-by: Thiago Coimbra Lemos <tclemos@users.noreply.github.com>

* new fields in stream (0xPolygonHermez#3149)

* new fields in stream

* update test

* remove unused constant

* add UpgradeEtrogBatchNumber handling to stream

* doc

* add log to test

* add log to test

* add protection

* add check

* fix

* fix

* set stateManagerPurge to false in Cardona (0xPolygonHermez#3158)

* synchronizer: fix case emtpy batch and unittest (0xPolygonHermez#3159)

* fix case emtpy batch and unittest

* fix error in conversion

* fix unittest

* update prover image to v4.0.1 (0xPolygonHermez#3160)

* update prover image to v4.0.2 (0xPolygonHermez#3162)

* Add a note in deployment instruction to restart rpc after forkId 7 (0xPolygonHermez#3163)

* note to restart zkevm-rpc

* update comment

* change position of point 10

* add point 11

* add lines

* add breakline

* add lines

* add line

* Sync old network compatibility (0xPolygonHermez#3166)

* Sync old network compatibility

* logs

* synchronizer: unittest and remove pool_reorg  (0xPolygonHermez#3111) (0xPolygonHermez#3168)

* removed reorgPool call
* add test for l1 sequenced batches
* removed panic after halt call as PR comments ask for

* fix parentHash when storing a new L2 block (0xPolygonHermez#3171)

* Fix/rom error (0xPolygonHermez#3177)

* fix rom error

* linter

* fix

* Cherrypick/0xPolygonHermez#3179 geth version v1.13.11 (0xPolygonHermez#3180)

* new geth version v1.13.11

* Add sanity check: last L2 block timestamp in the sequence is also L1BlockTimestampMargin seconds behind "now" (0xPolygonHermez#3181)

* add sanity check L1BlockTimestampMargin vs now

* Update prover image to v4.0.4

* synchronizer: update fromTrusted fix cache update (0xPolygonHermez#3169)

* fix cache update and sync from Trusted of closed batch

* Feature/3173 sync trusted state in networks previous to  ETROG (0xPolygonHermez#3175)

* Fix/3164 eth syncing dont return expected values (0xPolygonHermez#3165)

* fix im state root in stream (0xPolygonHermez#3192)

* sync: fix getting URL from contract in compatibility mode, and set sequential by default (0xPolygonHermez#3191)

* fix getting URL from contract in compatibility mode
* synchronizer configuration  by default use `sequential` mode

* Fix isSynced function (0xPolygonHermez#3188)

* fix isSynced

* fix linter

* fix logs

* halt on sanity check error

* fix l2 block gas price to use value returned by the executor (0xPolygonHermez#3186) (0xPolygonHermez#3190)

* allow rpc to access the ForkID directly from DB (0xPolygonHermez#3196)

* allow rpc to access the ForkID directly from DB

* update docs

* allow rpc to access the ForkID directly from DB (0xPolygonHermez#3197)

* allow rpc to access the ForkID directly from DB

* update docs

* fix migration down; check for greater forkIDs instead of the next +1 (0xPolygonHermez#3182)

* fix state storage config initialization

* add tests and fix get forkID by block number

* fix test TestGetForkIDByBlockNumber

---------

Co-authored-by: agnusmor <agnusmor@gmail.com>

* Fix/3200 l1inforoot error on reorg (0xPolygonHermez#3201)

* L1InfooTree cache is calculated when needed and is discard when a reorg happens

* Fix/3203 panic if batch process fail and must be closed (0xPolygonHermez#3206)

* synchronizer avoid panic if process trusted batch fails

* Remove L1SynchronizationMode parameter from environments config files (it will use default "sequential" value) (0xPolygonHermez#3210)

* allow GetL2TxHashByTxHash to return null for txs prior to Etrog (0xPolygonHermez#3209)

* Fix L2 block gas limit to 2**50 (1125899906842624) (0xPolygonHermez#3219)

* set l2 block gas limit to 2**50 (1125899906842624)

* limit L2 block gasLimit in StoreL2Block function

* change 2^64-1 for an esmitation of blocks (0xPolygonHermez#3220)

* removed restart RPC on deploy instructions (0xPolygonHermez#3221)

* Cherry pick/3222 (0xPolygonHermez#3224)

* fix stream

* fix stream

* fix stream

* fix stream

* linter

* add retries in is Synced function when last virtual batch is greater than last SC sequenced batcj (0xPolygonHermez#3225)

* wip

* update mocks

* wip

* modified sequencesender interfaces signatures

* linter fix

* removed unused methods and linter fix

* wip

* update diff docs

* Fix errors when generating mocks and regenerate them

* cr fix

* cr fix

* docs update

* Generate mock_etherman for sequencesender package

* cr fix and docs update

* Fix etherman test

* fix UT

* update docs

---------

Co-authored-by: agnusmor <100322135+agnusmor@users.noreply.github.com>
Co-authored-by: Alonso Rodriguez <ARR552@users.noreply.github.com>
Co-authored-by: Toni Ramírez <toni@polygon.technology>
Co-authored-by: Thiago Coimbra Lemos <tclemos@users.noreply.github.com>
Co-authored-by: Joan Esteban <129153821+joanestebanr@users.noreply.github.com>
Co-authored-by: Toni Ramírez <58293609+ToniRamirezM@users.noreply.github.com>
Co-authored-by: agnusmor <agnusmor@gmail.com>
Co-authored-by: Stefan Negovanović <stefan@ethernal.tech>
Co-authored-by: bros <arnaubennassar5@gmail.com>
  • Loading branch information
10 people authored Feb 8, 2024
1 parent 283971e commit b7fc8bc
Show file tree
Hide file tree
Showing 123 changed files with 26,456 additions and 17,903 deletions.
48 changes: 24 additions & 24 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/gasprice"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/client"
"github.com/0xPolygonHermez/zkevm-node/l1infotree"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/merkletree"
"github.com/0xPolygonHermez/zkevm-node/metrics"
Expand Down Expand Up @@ -122,20 +121,17 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}

st := newState(cliCtx.Context, c, l2ChainID, []state.ForkIDInterval{}, stateSqlDB, eventLog, needsExecutor, needsStateTree)

etherman, err := newEtherman(*c, st)
etherman, err := etherman.NewClient(c.Etherman, c.NetworkConfig.L1Config, nil)
if err != nil {
log.Fatal(err)
}
forkIDIntervals, err := forkIDIntervals(cliCtx.Context, st, etherman, c.NetworkConfig.Genesis.BlockNumber)
st, currentForkID := newState(cliCtx.Context, c, etherman, l2ChainID, stateSqlDB, eventLog, needsExecutor, needsStateTree, false)

etherman, err = newEtherman(*c, st)
if err != nil {
log.Fatal("error getting forkIDs. Error: ", err)
log.Fatal(err)
}
st.UpdateForkIDIntervalsInMemory(forkIDIntervals)

currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId
log.Infof("Fork ID read from POE SC = %v", forkIDIntervals[len(forkIDIntervals)-1].ForkId)
c.Aggregator.ChainID = l2ChainID
c.Sequencer.StreamServer.ChainID = l2ChainID
log.Infof("Chain ID read from POE SC = %v", l2ChainID)
Expand Down Expand Up @@ -220,6 +216,7 @@ func start(cliCtx *cli.Context) error {
for _, a := range cliCtx.StringSlice(config.FlagHTTPAPI) {
apis[a] = true
}
st, _ := newState(cliCtx.Context, c, etherman, l2ChainID, stateSqlDB, eventLog, needsExecutor, needsStateTree, true)
go runJSONRPCServer(*c, etherman, l2ChainID, poolInstance, st, apis)
case SYNCHRONIZER:
ev.Component = event.Component_Synchronizer
Expand Down Expand Up @@ -379,7 +376,7 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS
log.Fatal("error getting trusted sequencer URI. Error: %v", err)
}
}
log.Debug("trustedSequencerURL ", trustedSequencerURL)
log.Info("trustedSequencerURL ", trustedSequencerURL)
}
zkEVMClient := client.NewClient(trustedSequencerURL)

Expand Down Expand Up @@ -543,9 +540,7 @@ func waitSignal(cancelFuncs []context.CancelFunc) {
}
}

func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDIntervals []state.ForkIDInterval, sqlDB *pgxpool.Pool, eventLog *event.EventLog, needsExecutor, needsStateTree bool) *state.State {
stateDb := pgstatestorage.NewPostgresStorage(c.State, sqlDB)

func newState(ctx context.Context, c *config.Config, etherman *etherman.Client, l2ChainID uint64, sqlDB *pgxpool.Pool, eventLog *event.EventLog, needsExecutor, needsStateTree, avoidForkIDInMemory bool) (*state.State, uint64) {
// Executor
var executorClient executor.ExecutorServiceClient
if needsExecutor {
Expand All @@ -562,30 +557,35 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt
stateCfg := state.Config{
MaxCumulativeGasUsed: c.State.Batch.Constraints.MaxCumulativeGasUsed,
ChainID: l2ChainID,
ForkIDIntervals: forkIDIntervals,
ForkIDIntervals: []state.ForkIDInterval{},
MaxResourceExhaustedAttempts: c.Executor.MaxResourceExhaustedAttempts,
WaitOnResourceExhaustion: c.Executor.WaitOnResourceExhaustion,
ForkUpgradeBatchNumber: c.ForkUpgradeBatchNumber,
ForkUpgradeNewForkId: c.ForkUpgradeNewForkId,
MaxLogsCount: c.RPC.MaxLogsCount,
MaxLogsBlockRange: c.RPC.MaxLogsBlockRange,
MaxNativeBlockHashBlockRange: c.RPC.MaxNativeBlockHashBlockRange,
AvoidForkIDInMemory: avoidForkIDInMemory,
}
allLeaves, err := stateDb.GetAllL1InfoRootEntries(ctx, nil)
stateDb := pgstatestorage.NewPostgresStorage(stateCfg, sqlDB)
st := state.NewState(stateCfg, stateDb, executorClient, stateTree, eventLog, nil)
// This is to force to build cache, and check that DB is ok before starting the application
l1inforoot, err := st.GetCurrentL1InfoRoot(ctx, nil)
if err != nil {
log.Fatal("error getting all leaves. Error: ", err)
}
var leaves [][32]byte
for _, leaf := range allLeaves {
leaves = append(leaves, leaf.Hash())
log.Fatal("error getting current L1InfoRoot. Error: ", err)
}
mt, err := l1infotree.NewL1InfoTree(uint8(32), leaves) //nolint:gomnd
log.Infof("Starting L1InfoRoot: %v", l1inforoot.String())

forkIDIntervals, err := forkIDIntervals(ctx, st, etherman, c.NetworkConfig.Genesis.BlockNumber)
if err != nil {
log.Fatal("error creating L1InfoTree. Error: ", err)
log.Fatal("error getting forkIDs. Error: ", err)
}
st.UpdateForkIDIntervalsInMemory(forkIDIntervals)

currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId
log.Infof("Fork ID read from POE SC = %v", forkIDIntervals[len(forkIDIntervals)-1].ForkId)

st := state.NewState(stateCfg, stateDb, executorClient, stateTree, eventLog, mt)
return st
return st, currentForkID
}

func createPool(cfgPool pool.Config, constraintsCfg state.BatchConstraintsCfg, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool {
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_Defaults(t *testing.T) {
},
{
path: "Synchronizer.L1SynchronizationMode",
expectedValue: "parallel",
expectedValue: "sequential",
},
{
path: "Synchronizer.L1ParallelSynchronization.MaxClients",
Expand Down Expand Up @@ -491,7 +491,7 @@ func Test_Defaults(t *testing.T) {
},
{
path: "State.Batch.Constraints.MaxCumulativeGasUsed",
expectedValue: uint64(30000000),
expectedValue: uint64(1125899906842624),
},
{
path: "State.Batch.Constraints.MaxKeccakHashes",
Expand Down
4 changes: 2 additions & 2 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Outputs = ["stderr"]
[State.Batch.Constraints]
MaxTxsPerBatch = 300
MaxBatchBytesSize = 120000
MaxCumulativeGasUsed = 30000000
MaxCumulativeGasUsed = 1125899906842624
MaxKeccakHashes = 2145
MaxPoseidonHashes = 252357
MaxPoseidonPaddings = 135191
Expand Down Expand Up @@ -102,7 +102,7 @@ EnableHttpLog = true
SyncInterval = "1s"
SyncChunkSize = 100
TrustedSequencerURL = "" # If it is empty or not specified, then the value is read from the smc
L1SynchronizationMode = "parallel"
L1SynchronizationMode = "sequential"
[Synchronizer.L1ParallelSynchronization]
MaxClients = 10
MaxPendingNoProcessedBlocks = 25
Expand Down
2 changes: 1 addition & 1 deletion config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Outputs = ["stderr"]
[State.Batch.Constraints]
MaxTxsPerBatch = 300
MaxBatchBytesSize = 120000
MaxCumulativeGasUsed = 30000000
MaxCumulativeGasUsed = 1125899906842624
MaxKeccakHashes = 2145
MaxPoseidonHashes = 252357
MaxPoseidonPaddings = 135191
Expand Down
107 changes: 0 additions & 107 deletions config/mainnetgenesis.go

This file was deleted.

108 changes: 0 additions & 108 deletions config/testnetgenesis.go

This file was deleted.

12 changes: 7 additions & 5 deletions dataavailability/datacommittee/datacommittee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygondatacommittee"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func init() {
// This function prepare the blockchain, the wallet with funds and deploy the smc
func newTestingEnv(t *testing.T) (
dac *DataCommitteeBackend,
ethBackend *backends.SimulatedBackend,
ethBackend *simulated.Backend,
auth *bind.TransactOpts,
da *polygondatacommittee.Polygondatacommittee,
) {
Expand All @@ -87,7 +87,7 @@ func newTestingEnv(t *testing.T) (
// must be 1337. The address that holds the auth will have an initial balance of 10 ETH
func newSimulatedDacman(t *testing.T, auth *bind.TransactOpts) (
dacman *DataCommitteeBackend,
ethBackend *backends.SimulatedBackend,
ethBackend *simulated.Backend,
da *polygondatacommittee.Polygondatacommittee,
err error,
) {
Expand All @@ -105,17 +105,19 @@ func newSimulatedDacman(t *testing.T, auth *bind.TransactOpts) (
},
}
blockGasLimit := uint64(999999999999999999) //nolint:gomnd
client := backends.NewSimulatedBackend(genesisAlloc, blockGasLimit)
client := simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit))

// DAC Setup
_, _, da, err = polygondatacommittee.DeployPolygondatacommittee(auth, client)
_, _, da, err = polygondatacommittee.DeployPolygondatacommittee(auth, client.Client())
if err != nil {
return &DataCommitteeBackend{}, nil, nil, err
}
client.Commit()
_, err = da.Initialize(auth)
if err != nil {
return &DataCommitteeBackend{}, nil, nil, err
}
client.Commit()
_, err = da.SetupCommittee(auth, big.NewInt(0), []string{}, []byte{})
if err != nil {
return &DataCommitteeBackend{}, nil, nil, err
Expand Down
6 changes: 4 additions & 2 deletions db/migrations/state/0009.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ALTER TABLE IF EXISTS state.fork_id DROP CONSTRAINT IF EXISTS fork_id_block_num_fkey;

-- +migrate Down
DELETE FROM state.fork_id f
WHERE NOT EXISTS(SELECT 1 FROM state.block b WHERE b.block_num = f.block_num);

ALTER TABLE IF EXISTS state.fork_id ADD CONSTRAINT fork_id_block_num_fkey
FOREIGN KEY(block_num)
REFERENCES state.block (block_num) ON DELETE CASCADE;
FOREIGN KEY(block_num) REFERENCES state.block (block_num) ON DELETE CASCADE;
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
zkevm-prover:
container_name: zkevm-prover
restart: unless-stopped
image: hermeznetwork/zkevm-prover:v4.0.2
image: hermeznetwork/zkevm-prover:v4.0.4
depends_on:
zkevm-state-db:
condition: service_healthy
Expand Down
Loading

0 comments on commit b7fc8bc

Please sign in to comment.