Skip to content

Commit

Permalink
New gas price estimation + HashDB + Fork ID 5 SMC (#2196)
Browse files Browse the repository at this point in the history
* wip

Signed-off-by: Nikolay Nedkov <[email protected]>

* update executor proto (#2122)

* update executor proto

* gas price as string

Signed-off-by: Nikolay Nedkov <[email protected]>

* new smc

* smc docker image

* merging feature/HashDB

Signed-off-by: Nikolay Nedkov <[email protected]>

* wip

Signed-off-by: Nikolay Nedkov <[email protected]>

* fixing comments.

Signed-off-by: Nikolay Nedkov <[email protected]>

* improve: adding missing safe check for L2 Min Gas Price.

Signed-off-by: Nikolay Nedkov <[email protected]>

* fix: fixing eth-CallEcrecoverInvalidSignature.json 'expectedOldStateRoot'.

Signed-off-by: Nikolay Nedkov <[email protected]>

* improve: adding missing check in finalizer for old txs.

Signed-off-by: Nikolay Nedkov <[email protected]>

* Optimize trace (#2183) (#2206)

* Optimize trace (#2183)

* optimize trace

* fix memory reading

* update docker image

* update prover image

* fix converter

* fix memory

* fix step memory

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* fix structlogs

* update prover image

* fix struclogs

* fix memory size

* fix memory size

* fix memory size

* refactor memory resize

* refactor memory resize

* update test

* new prover

* New image with geth1.12.0

* geth1.11.5

* fix: fixing contract addresses in configs.

Signed-off-by: Nikolay Nedkov <[email protected]>

* changing zkevm-mock-l1-network image to hermeznetwork/geth-zkevm-contracts:v2.0.0-RC1-fork.5-geth1.12.0

Signed-off-by: Nikolay Nedkov <[email protected]>

* Fix/group8 (#2211)

* fix gaslimit

* fix gaslimit

* fix gaslimit

* smc

* genBlockNumb

* use forkID while encoding/decoding txs (#2219)

* Add effective_gas_price to receipt (#2222)

* add effective_gas_used to receipt

* fix

* fix

* fix sql

* fix

* fix sql

* fix sql

* fix

* fix

* fix helper

* fix sql

* change sql

* update prover image

* update prover image

* effective gas price comparation (#2234)

* effective gas price comparation

* rename function

* fix

* refactor

* linter

* fix

* update prover image

* update prover image

* refactor

* refactor gas prices

* refactor gas prices

* fix

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* mutex

* fix test

* do not return error on l1gas=0

* remove commented code

* refactor

* fix conflicts

* fix conflicts

* make factors floats

* fix gasprice

* fix gasprice

* merge develop and fix conflicts

---------

Signed-off-by: Nikolay Nedkov <[email protected]>
Co-authored-by: Toni Ramírez <[email protected]>
Co-authored-by: Alonso <[email protected]>
Co-authored-by: Toni Ramírez <[email protected]>
  • Loading branch information
4 people authored Jun 30, 2023
1 parent 93b54af commit cf20a24
Show file tree
Hide file tree
Showing 142 changed files with 7,730 additions and 5,338 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ install-git-hooks: ## Moves hook files to the .git/hooks directory

.PHONY: generate-code-from-proto
generate-code-from-proto: ## Generates code from proto files
cd proto/src/proto/statedb/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../merkletree/pb --go-grpc_out=../../../../../merkletree/pb --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative statedb.proto
cd proto/src/proto/hashdb/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../merkletree/pb --go-grpc_out=../../../../../merkletree/pb --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative hashdb.proto
cd proto/src/proto/executor/v1 && protoc --proto_path=. --go_out=../../../../../state/runtime/executor/pb --go-grpc_out=../../../../../state/runtime/executor/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative executor.proto
cd proto/src/proto/aggregator/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../aggregator/pb --go-grpc_out=../../../../../aggregator/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative aggregator.proto

Expand Down
51 changes: 25 additions & 26 deletions aggregator/pb/aggregator.pb.go

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

3 changes: 2 additions & 1 deletion ci/e2e-group10/forced_batches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
const (
toAddressHex = "0x4d5Cf5032B2a844602278b01199ED191A86c93ff"
gerFinalityBlocks = uint64(250)
forkID5 = 5
)

var (
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestForcedBatches(t *testing.T) {
unsignedTx := types.NewTransaction(nonce, toAddress, amount, gasLimit, gasPrice, nil)
signedTx, err := auth.Signer(auth.From, unsignedTx)
require.NoError(t, err)
encodedTxs, err := state.EncodeTransactions([]types.Transaction{*signedTx})
encodedTxs, err := state.EncodeTransactions([]types.Transaction{*signedTx}, constants.EffectivePercentage, forkID5)
require.NoError(t, err)
forcedBatch, err := sendForcedBatch(t, encodedTxs, opsman)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion ci/e2e-group10/forced_batches_vector_group2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestForcedBatchesVectorFiles(t *testing.T) {
require.Equal(t, testCase.ExpectedOldStateRoot, actualOldStateRoot.Hex())
decodedData, err := hex.DecodeHex(testCase.BatchL2Data)
require.NoError(t, err)
_, txBytes, err := state.DecodeTxs(decodedData)
_, txBytes, _, err := state.DecodeTxs(decodedData, forkID5)
forcedBatch, err := sendForcedBatchForVector(t, txBytes, opsman)
require.NoError(t, err)
actualNewStateRoot := forcedBatch.StateRoot
Expand Down
6 changes: 5 additions & 1 deletion ci/e2e-group11/forced_batches_vector_group3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
"github.com/stretchr/testify/require"
)

const (
forkID5 = 5
)

func TestForcedBatchesVectorFiles(t *testing.T) {

if testing.Short() {
Expand Down Expand Up @@ -71,7 +75,7 @@ func TestForcedBatchesVectorFiles(t *testing.T) {
require.Equal(t, testCase.ExpectedOldStateRoot, actualOldStateRoot.Hex())
decodedData, err := hex.DecodeHex(testCase.BatchL2Data)
require.NoError(t, err)
_, txBytes, err := state.DecodeTxs(decodedData)
_, txBytes, _, err := state.DecodeTxs(decodedData, forkID5)
forcedBatch, err := sendForcedBatchForVector(t, txBytes, opsman)
require.NoError(t, err)
actualNewStateRoot := forcedBatch.StateRoot
Expand Down
7 changes: 6 additions & 1 deletion ci/e2e-group9/forced_batches_vector_group1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
"github.com/stretchr/testify/require"
)

const (
forkID5 = 5
)

func TestForcedBatchesVectorFiles(t *testing.T) {

if testing.Short() {
Expand Down Expand Up @@ -71,7 +75,8 @@ func TestForcedBatchesVectorFiles(t *testing.T) {
require.Equal(t, testCase.ExpectedOldStateRoot, actualOldStateRoot.Hex())
decodedData, err := hex.DecodeHex(testCase.BatchL2Data)
require.NoError(t, err)
_, txBytes, err := state.DecodeTxs(decodedData)
_, txBytes, _, err := state.DecodeTxs(decodedData, forkID5)
require.NoError(t, err)
forcedBatch, err := sendForcedBatchForVector(t, txBytes, opsman)
require.NoError(t, err)
actualNewStateRoot := forcedBatch.StateRoot
Expand Down
25 changes: 13 additions & 12 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
executorpb "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor/pb"
"github.com/0xPolygonHermez/zkevm-node/synchronizer"
"github.com/ethereum/go-ethereum/common"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -127,9 +126,11 @@ func start(cliCtx *cli.Context) error {
}

currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId

log.Infof("Fork ID read from POE SC = %v", currentForkID)
c.Aggregator.ChainID = l2ChainID
c.Aggregator.ForkId = currentForkID
c.Sequencer.DBManager.ForkID = currentForkID
c.Sequencer.Finalizer.ForkID = currentForkID
log.Infof("Chain ID read from POE SC = %v", l2ChainID)

ctx := context.Background()
Expand All @@ -151,6 +152,9 @@ func start(cliCtx *cli.Context) error {

var poolInstance *pool.Pool

if c.Metrics.ProfilingEnabled {
go startProfilingHttpServer(c.Metrics)
}
for _, component := range components {
switch component {
case AGGREGATOR:
Expand All @@ -169,7 +173,7 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.NetworkConfig.L2BridgeAddr, l2ChainID, st, eventLog)
poolInstance = createPool(c.Pool, l2ChainID, st, eventLog)
}
seq := createSequencer(*c, poolInstance, ethTxManagerStorage, st, eventLog)
go seq.Start(ctx)
Expand All @@ -181,7 +185,7 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.NetworkConfig.L2BridgeAddr, l2ChainID, st, eventLog)
poolInstance = createPool(c.Pool, l2ChainID, st, eventLog)
}
seqSender := createSequenceSender(*c, poolInstance, ethTxManagerStorage, st, eventLog)
go seqSender.Start(ctx)
Expand All @@ -193,7 +197,7 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.NetworkConfig.L2BridgeAddr, l2ChainID, st, eventLog)
poolInstance = createPool(c.Pool, l2ChainID, st, eventLog)
}
if c.RPC.EnableL2SuggestedGasPricePolling {
// Needed for rejecting transactions with too low gas price
Expand All @@ -212,7 +216,7 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.NetworkConfig.L2BridgeAddr, l2ChainID, st, eventLog)
poolInstance = createPool(c.Pool, l2ChainID, st, eventLog)
}
go runSynchronizer(*c, etherman, etm, st, poolInstance)
case ETHTXMANAGER:
Expand All @@ -232,7 +236,7 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
if poolInstance == nil {
poolInstance = createPool(c.Pool, c.NetworkConfig.L2BridgeAddr, l2ChainID, st, eventLog)
poolInstance = createPool(c.Pool, l2ChainID, st, eventLog)
}
go runL2GasPriceSuggester(c.L2GasPriceSuggester, st, poolInstance, etherman)
}
Expand All @@ -242,9 +246,6 @@ func start(cliCtx *cli.Context) error {
go startMetricsHttpServer(c.Metrics)
}

if c.Metrics.ProfilingEnabled {
go startProfilingHttpServer(c.Metrics)
}
waitSignal(cancelFuncs)

return nil
Expand Down Expand Up @@ -482,13 +483,13 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt
return st
}

func createPool(cfgPool pool.Config, l2BridgeAddr common.Address, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool {
func createPool(cfgPool pool.Config, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool {
runPoolMigrations(cfgPool.DB)
poolStorage, err := pgpoolstorage.NewPostgresPoolStorage(cfgPool.DB)
if err != nil {
log.Fatal(err)
}
poolInstance := pool.NewPool(cfgPool, poolStorage, st, l2BridgeAddr, l2ChainID, eventLog)
poolInstance := pool.NewPool(cfgPool, poolStorage, st, l2ChainID, eventLog)
return poolInstance
}

Expand Down
24 changes: 24 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ func Test_Defaults(t *testing.T) {
path: "Sequencer.Finalizer.TimestampResolution",
expectedValue: types.NewDuration(10 * time.Second),
},
{
path: "Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage",
expectedValue: uint64(10),
},
{
path: "Sequencer.EffectiveGasPrice.Enabled",
expectedValue: false,
},
{
path: "Sequencer.DBManager.PoolRetrievalInterval",
expectedValue: types.NewDuration(500 * time.Millisecond),
Expand Down Expand Up @@ -276,6 +284,10 @@ func Test_Defaults(t *testing.T) {
path: "StateDB.MaxConns",
expectedValue: 200,
},
{
path: "Pool.IntervalToRefreshGasPrices",
expectedValue: types.NewDuration(5 * time.Second),
},
{
path: "Pool.MaxTxBytesSize",
expectedValue: uint64(100132),
Expand Down Expand Up @@ -333,6 +345,18 @@ func Test_Defaults(t *testing.T) {
path: "Pool.DB.MaxConns",
expectedValue: 200,
},
{
path: "Pool.EffectiveGasPrice.L1GasPriceFactor",
expectedValue: float64(0.25),
},
{
path: "Pool.EffectiveGasPrice.ByteGasCost",
expectedValue: uint64(16),
},
{
path: "Pool.EffectiveGasPrice.MarginFactor",
expectedValue: float64(1),
},
{
path: "RPC.Host",
expectedValue: "0.0.0.0",
Expand Down
Loading

0 comments on commit cf20a24

Please sign in to comment.