Skip to content

Commit

Permalink
fixing close empty batch and failure to send tx to the ethereum (0xPo…
Browse files Browse the repository at this point in the history
…lygonHermez#971)

* fixing close empty batch and failure to send tx to the ethereum

* fixed config_test.go

* WIP

* Sequencer stability update

* Imporve revert reason

* Single MaxCumulativeGas config

* Fix test int64 => uint64

Co-authored-by: Arnau Bennassar <[email protected]>
  • Loading branch information
Mikelle and arnaubennassar authored Aug 2, 2022
1 parent a742325 commit 1595b6e
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 185 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ stop-explorer-db: ## Stops the explorer database
$(STOPEXPLORERDB)

.PHONY: run
run: compile-scs ## Runs all the services
run: ## Runs all the services
$(RUNDB)
$(RUNL1NETWORK)
sleep 5
$(RUNZKPROVER)
sleep 2
sleep 5
$(RUNSEQUENCER)
$(RUNAGGREGATOR)
$(RUNJSONRPC)
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func newState(ctx context.Context, c *config.Config, sqlDB *pgxpool.Pool) *state
stateTree := merkletree.NewStateTree(stateDBClient)

stateCfg := state.Config{
MaxCumulativeGasUsed: c.NetworkConfig.MaxCumulativeGasUsed,
MaxCumulativeGasUsed: c.Sequencer.MaxCumulativeGasUsed,
}

st := state.NewState(stateCfg, stateDb, executorClient, stateTree)
Expand Down
10 changes: 9 additions & 1 deletion config/config.debug.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ TrustedSequencerURI = ""

[Sequencer]
WaitPeriodPoolIsEmpty = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "300s"
WaitBlocksToUpdateGER = 10
LastTimeBatchMaxWaitPeriod = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
MaxCumulativeGasUsed = 30000000
MaxKeccakHashes = 468
MaxPoseidonHashes = 279620
MaxPoseidonPaddings = 149796
MaxMemAligns = 262144
MaxArithmetics = 262144
MaxBinaries = 262144
MaxSteps = 8388608
[Sequencer.ProfitabilityChecker]
SendBatchesEvenWhenNotProfitable = "true"

Expand Down
10 changes: 9 additions & 1 deletion config/config.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ TrustedSequencerURI = ""

[Sequencer]
WaitPeriodPoolIsEmpty = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "300s"
WaitBlocksToUpdateGER = 10
LastTimeBatchMaxWaitPeriod = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
MaxCumulativeGasUsed = 30000000
MaxKeccakHashes = 468
MaxPoseidonHashes = 279620
MaxPoseidonPaddings = 149796
MaxMemAligns = 262144
MaxArithmetics = 262144
MaxBinaries = 262144
MaxSteps = 8388608
[Sequencer.ProfitabilityChecker]
SendBatchesEvenWhenNotProfitable = "true"

Expand Down
20 changes: 10 additions & 10 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_Defaults(t *testing.T) {
},
{
path: "Sequencer.LastBatchVirtualizationTimeMaxWaitPeriod",
expectedValue: types.NewDuration(15 * time.Second),
expectedValue: types.NewDuration(300 * time.Second),
},
{
path: "Sequencer.WaitBlocksToUpdateGER",
Expand All @@ -61,36 +61,36 @@ func Test_Defaults(t *testing.T) {
expectedValue: true,
},
{
path: "Sequencer.MaxGasUsed",
expectedValue: int64(100000),
path: "Sequencer.MaxCumulativeGasUsed",
expectedValue: uint64(30000000),
},
{
path: "Sequencer.MaxKeccakHashes",
expectedValue: int32(100),
expectedValue: int32(468),
},
{
path: "Sequencer.MaxPoseidonHashes",
expectedValue: int32(100),
expectedValue: int32(279620),
},
{
path: "Sequencer.MaxPoseidonPaddings",
expectedValue: int32(100),
expectedValue: int32(149796),
},
{
path: "Sequencer.MaxMemAligns",
expectedValue: int32(100),
expectedValue: int32(262144),
},
{
path: "Sequencer.MaxArithmetics",
expectedValue: int32(100),
expectedValue: int32(262144),
},
{
path: "Sequencer.MaxBinaries",
expectedValue: int32(100),
expectedValue: int32(262144),
},
{
path: "Sequencer.MaxSteps",
expectedValue: int32(100),
expectedValue: int32(8388608),
},
{
path: "EthTxManager.MaxSendBatchTxRetries",
Expand Down
18 changes: 9 additions & 9 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ TrustedSequencerURI = ""
[Sequencer]
WaitPeriodPoolIsEmpty = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "300s"
WaitBlocksToUpdateGER = 10
LastTimeBatchMaxWaitPeriod = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
MaxGasUsed = 100000
MaxKeccakHashes = 100
MaxPoseidonHashes = 100
MaxPoseidonPaddings = 100
MaxMemAligns = 100
MaxArithmetics = 100
MaxBinaries = 100
MaxSteps = 100
MaxCumulativeGasUsed = 30000000
MaxKeccakHashes = 468
MaxPoseidonHashes = 279620
MaxPoseidonPaddings = 149796
MaxMemAligns = 262144
MaxArithmetics = 262144
MaxBinaries = 262144
MaxSteps = 8388608
[Sequencer.ProfitabilityChecker]
SendBatchesEvenWhenNotProfitable = "true"
Expand Down
7 changes: 0 additions & 7 deletions config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type NetworkConfig struct {
OldStateRootPosition uint64
ChainID uint64
Genesis Genesis
MaxCumulativeGasUsed uint64
}

// Genesis is part of NetworkConfig
Expand All @@ -52,7 +51,6 @@ type networkConfigFromJSON struct {
OldStateRootPosition uint64 `json:"oldStateRootPosition"`
ChainID uint64 `json:"chainID"`
Genesis []genesisAccountFromJSON `json:"genesis"`
MaxCumulativeGasUsed uint64 `json:"maxCumulativeGasUsed"`
}

type genesisAccountFromJSON struct {
Expand Down Expand Up @@ -92,7 +90,6 @@ var (
common.HexToAddress("0xb1D0Dc8E2Ce3a93EB2b32f4C7c3fD9dDAf1211FB"): big.NewInt(2000),
},
},
MaxCumulativeGasUsed: 30000000,
}
testnetConfig = NetworkConfig{
Arity: 4,
Expand All @@ -112,7 +109,6 @@ var (
common.HexToAddress("0xb1D0Dc8E2Ce3a93EB2b32f4C7c3fD9dDAf1211FB"): big.NewInt(2000),
},
},
MaxCumulativeGasUsed: 30000000,
}
internalTestnetConfig = NetworkConfig{
Arity: 4,
Expand Down Expand Up @@ -181,7 +177,6 @@ var (
common.HexToAddress("0x61ba0248b0986c2480181c6e76b6adeeaa962483"): bigIntFromBase10String("1"),
},
},
MaxCumulativeGasUsed: 30000000,
}
localConfig = NetworkConfig{
Arity: 4,
Expand Down Expand Up @@ -251,7 +246,6 @@ var (
common.HexToAddress("0x61ba0248b0986c2480181c6e76b6adeeaa962483"): bigIntFromBase10String("1"),
},
},
MaxCumulativeGasUsed: 30000000,
}

networkConfigByName = map[string]NetworkConfig{
Expand Down Expand Up @@ -343,7 +337,6 @@ func loadCustomNetworkConfig(ctx *cli.Context) (NetworkConfig, error) {
cfg.LocalExitRootStoragePosition = cfgJSON.LocalExitRootStoragePosition
cfg.OldStateRootPosition = cfgJSON.OldStateRootPosition
cfg.ChainID = cfgJSON.ChainID
cfg.MaxCumulativeGasUsed = cfgJSON.MaxCumulativeGasUsed

if len(cfgJSON.Genesis) == 0 {
return cfg, nil
Expand Down
20 changes: 8 additions & 12 deletions config/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func TestLoadCustomNetworkConfig(t *testing.T) {
common.HexToAddress("0x61ba0248b0986c2480181c6e76b6adeeaa962483"): bigIntFromBase10String("1"),
},
},
MaxCumulativeGasUsed: 300000,
},
},
{
Expand Down Expand Up @@ -163,7 +162,6 @@ func TestLoadCustomNetworkConfig(t *testing.T) {
Storage: map[common.Address]map[*big.Int]*big.Int{},
Nonces: map[common.Address]*big.Int{},
},
MaxCumulativeGasUsed: 123456,
},
},
{
Expand Down Expand Up @@ -272,18 +270,16 @@ func TestMergeNetworkConfig(t *testing.T) {
MaticAddr: common.HexToAddress("0x1D217d81831009a5fE44C9a1Ee2480e48830CbD4"),
},
inputBaseConfig: NetworkConfig{
PoEAddr: common.HexToAddress("0xb1Fe4a65D3392df68F96daC8eB4df56B2411afBf"),
Arity: 4,
ChainID: 5,
MaxCumulativeGasUsed: 300,
PoEAddr: common.HexToAddress("0xb1Fe4a65D3392df68F96daC8eB4df56B2411afBf"),
Arity: 4,
ChainID: 5,
},
expectedOutputConfig: NetworkConfig{
Arity: 4,
ChainID: 5,
MaxCumulativeGasUsed: 300,
GenBlockNumber: 300,
PoEAddr: common.HexToAddress("0xc949254d682d8c9ad5682521675b8f43b102aec4"),
MaticAddr: common.HexToAddress("0x1D217d81831009a5fE44C9a1Ee2480e48830CbD4"),
Arity: 4,
ChainID: 5,
GenBlockNumber: 300,
PoEAddr: common.HexToAddress("0xc949254d682d8c9ad5682521675b8f43b102aec4"),
MaticAddr: common.HexToAddress("0x1D217d81831009a5fE44C9a1Ee2480e48830CbD4"),
},
},
{
Expand Down
20 changes: 10 additions & 10 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/proverclient/pb"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/test/operations"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -57,6 +58,7 @@ type ethClienter interface {
ethereum.ChainReader
ethereum.LogFilterer
ethereum.TransactionReader
ethereum.ContractCaller
}

// Client is a simple implementation of EtherMan.
Expand Down Expand Up @@ -190,6 +192,11 @@ func (etherMan *Client) updateGlobalExitRootEvent(ctx context.Context, vLog type
return nil
}

// WaitTxToBeMined waits for an L1 tx to be mined. It will return error if the tx is reverted or timeout is exceeded
func (etherMan *Client) WaitTxToBeMined(hash common.Hash, timeout time.Duration) error {
return operations.WaitTxToBeMined(etherMan.EtherClient, hash, timeout)
}

// EstimateGasSequenceBatches estimates gas for sending batches
func (etherMan *Client) EstimateGasSequenceBatches(sequences []ethmanTypes.Sequence) (uint64, error) {
noSendOpts := *etherMan.auth
Expand All @@ -198,7 +205,7 @@ func (etherMan *Client) EstimateGasSequenceBatches(sequences []ethmanTypes.Seque
if err != nil {
return 0, err
}
return tx.Cost().Uint64(), nil
return tx.Gas(), nil
}

// SequenceBatches send sequences of batches to the ethereum
Expand All @@ -224,14 +231,7 @@ func (etherMan *Client) sequenceBatches(opts *bind.TransactOpts, sequences []eth

batches = append(batches, batch)
}

tx, err := etherMan.PoE.SequenceBatches(opts, batches)

if err != nil {
return nil, err
}

return tx, nil
return etherMan.PoE.SequenceBatches(opts, batches)
}

// EstimateGasForVerifyBatch estimates gas for verify batch smart contract call
Expand All @@ -242,7 +242,7 @@ func (etherMan *Client) EstimateGasForVerifyBatch(batchNumber uint64, resGetProo
if err != nil {
return 0, err
}
return tx.Cost().Uint64(), nil
return tx.Gas(), nil
}

// VerifyBatch send verifyBatch request to the ethereum
Expand Down
Loading

0 comments on commit 1595b6e

Please sign in to comment.