Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into CDK-90-remove-pack-2-usage-in-agglayer
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Feb 23, 2024
2 parents a236b70 + 8b2b965 commit 5214610
Show file tree
Hide file tree
Showing 25 changed files with 405 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
docker/data
.idea
coverage.out
.vscode/launch.json
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ LDFLAGS += -X 'github.com/0xPolygon/agglayer.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygon/agglayer.BuildDate=$(DATE)'

.PHONY: build
build: generate-migrations ## Builds the binary locally into ./dist
build: ## Builds the binary locally into ./dist
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD)

.PHONY: build-docker
Expand Down Expand Up @@ -120,4 +120,4 @@ unit-tests: ## Runs unit tests

.PHONY: generate-mocks
generate-mocks: ## Generates mocks and other autogenerated types
$(GOENVVARS) go generate ./...
mockery
9 changes: 6 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
dbConf "github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/0xPolygon/agglayer/db"
"github.com/0xPolygon/agglayer/etherman"
"github.com/0xPolygon/agglayer/interop"
"github.com/0xPolygon/agglayer/log"
"github.com/0xPolygon/agglayer/network"
"github.com/0xPolygon/agglayer/rpc"
)
Expand Down Expand Up @@ -73,6 +73,7 @@ func start(cliCtx *cli.Context) error {

setupLog(c.Log)

log.Errorf("EthTxManager config%+v", c.EthTxManager)
// Load private key
pk, err := config.NewKeyFromKeystore(c.EthTxManager.PrivateKeys[0])
if err != nil {
Expand Down Expand Up @@ -119,7 +120,7 @@ func start(cliCtx *cli.Context) error {
if err != nil {
log.Fatal(err)
}
etm := ethtxmanager.New(c.EthTxManager, &ethMan, ethTxManagerStorage, &ethMan)
etm := ethtxmanager.New(c.EthTxManager.Config, &ethMan, ethTxManagerStorage, &ethMan)

// Create opentelemetry metric provider
metricProvider, err := createMetricProvider()
Expand Down Expand Up @@ -183,7 +184,9 @@ func start(cliCtx *cli.Context) error {
}

func setupLog(c log.Config) {
log.Init(c)
if err := log.InitLogger(c); err != nil {
panic(fmt.Errorf("could not setup logger. Err: %w", err))
}
}

func createMetricProvider() (*metric.MeterProvider, error) {
Expand Down
21 changes: 13 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"path/filepath"
"strings"

"github.com/0xPolygon/agglayer/log"
jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/mitchellh/mapstructure"
Expand All @@ -27,13 +27,13 @@ type FullNodeRPCs map[uint32]string

// Config represents the full configuration of the data node
type Config struct {
FullNodeRPCs FullNodeRPCs `mapstructure:"FullNodeRPCs"`
RPC jRPC.Config `mapstructure:"RPC"`
Log log.Config `mapstructure:"Log"`
DB db.Config `mapstructure:"DB"`
EthTxManager ethtxmanager.Config `mapstructure:"EthTxManager"`
L1 L1Config `mapstructure:"L1"`
Telemetry Telemetry `mapstructure:"Telemetry"`
FullNodeRPCs FullNodeRPCs `mapstructure:"FullNodeRPCs"`
RPC jRPC.Config `mapstructure:"RPC"`
Log log.Config `mapstructure:"Log"`
DB db.Config `mapstructure:"DB"`
EthTxManager EthTxManagerConfig `mapstructure:"EthTxManager"`
L1 L1Config `mapstructure:"L1"`
Telemetry Telemetry `mapstructure:"Telemetry"`
}

type L1Config struct {
Expand All @@ -46,6 +46,11 @@ type Telemetry struct {
PrometheusAddr string
}

type EthTxManagerConfig struct {
ethtxmanager.Config `mapstructure:",squash"`
GasOffset uint64 `mapstructure:"GasOffset"`
}

// Load loads the configuration baseed on the cli context
func Load(ctx *cli.Context) (*Config, error) {
cfg, err := Default()
Expand Down
53 changes: 48 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
package config

import (
"flag"
"testing"

"github.com/stretchr/testify/assert"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
)

func TestLoad(t *testing.T) {
ctx := cli.NewContext(nil, nil, nil)
_ = ctx.Set(FlagCfg, "/path/to/config.yaml")
t.Run("default config", func(t *testing.T) {
ctx := cli.NewContext(nil, nil, nil)
_ = ctx.Set(FlagCfg, "/path/to/config.yaml")

_, err := Load(ctx)
assert.NoError(t, err)
cfg, err := Load(ctx)
require.NoError(t, err)

defaultCfg, err := Default()
require.NoError(t, err)
require.Equal(t, defaultCfg, cfg)
})

t.Run("the agglayer.toml file config", func(t *testing.T) {
const (
cfgFile = "../docker/data/agglayer/agglayer.toml"
ethTxManagerCfgKey = "EthTxManager"
)

// simulate command with the cfg flag
flags := new(flag.FlagSet)
cfgPath := ""
flags.StringVar(&cfgPath,
FlagCfg,
cfgFile,
"config file for the agglayer")
ctx := cli.NewContext(nil, flags, nil)

// read the config independently from the Load function
viper.SetConfigFile(cfgFile)
err := viper.ReadInConfig()
require.NoError(t, err)

decodeOpts := []viper.DecoderConfigOption{
viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(mapstructure.TextUnmarshallerHookFunc())),
}

var ethTxManagerCfg EthTxManagerConfig
err = viper.UnmarshalKey(ethTxManagerCfgKey, &ethTxManagerCfg, decodeOpts...)
require.NoError(t, err)

cfg, err := Load(ctx)
require.NoError(t, err)
require.NotNil(t, cfg)
require.Equal(t, ethTxManagerCfg, cfg.EthTxManager)
})
}
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const DefaultValues = `
PrivateKeys = [
{Path = "/pk/agglayer.keystore", Password = "testonly"},
]
GasOffset = 100000
[L1]
ChainID = 1337
Expand Down
2 changes: 2 additions & 0 deletions db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/0xPolygonHermez/zkevm-node/log"
migrate "github.com/rubenv/sql-migrate"

"github.com/0xPolygon/agglayer/log"
)

const migrationsPath = "migrations"
Expand Down
1 change: 1 addition & 0 deletions docker/data/agglayer/agglayer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
PrivateKeys = [
{Path = "/pk/agglayer.keystore", Password = "testonly"},
]
GasOffset = 100000

[L1]
ChainID = 1337
Expand Down
7 changes: 6 additions & 1 deletion etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/0xPolygon/agglayer/config"
"github.com/0xPolygon/agglayer/tx"

"github.com/0xPolygon/agglayer/log"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonrollupmanager"
"github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/test/operations"
"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -137,6 +137,11 @@ func (e *Etherman) CheckTxWasMined(ctx context.Context, txHash common.Hash) (boo
return true, receipt, nil
}

// PendingNonce returns the pending nonce for the provided account
func (e *Etherman) PendingNonce(ctx context.Context, account common.Address) (uint64, error) {
return e.ethClient.PendingNonceAt(ctx, account)
}

// CurrentNonce returns the current nonce for the provided account
func (e *Etherman) CurrentNonce(ctx context.Context, account common.Address) (uint64, error) {
return e.ethClient.NonceAt(ctx, account, nil)
Expand Down
45 changes: 45 additions & 0 deletions etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,51 @@ func TestCheckTxWasMined(t *testing.T) {
})
}

func TestPendingNonce(t *testing.T) {
t.Parallel()
assert := assert.New(t)

t.Run("Returns the expected nonce value", func(t *testing.T) {
ethClient := mocks.NewEthereumClientMock(t)
ethman := getEtherman(ethClient)

ethClient.On(
"PendingNonceAt",
context.TODO(),
common.Address{},
).Return(
uint64(1),
nil,
).Once()

result, err := ethman.PendingNonce(context.TODO(), common.Address{})

assert.Equal(uint64(1), result)
assert.Nil(err)
ethClient.AssertExpectations(t)
})

t.Run("Returns the expected error", func(t *testing.T) {
ethClient := mocks.NewEthereumClientMock(t)
ethman := getEtherman(ethClient)

ethClient.On(
"PendingNonceAt",
context.TODO(),
common.Address{},
).Return(
uint64(0),
errors.New("NA NA NA!"),
).Once()

result, err := ethman.PendingNonce(context.TODO(), common.Address{})

assert.Equal(uint64(0), result)
assert.ErrorContains(err, "NA NA NA!")
ethClient.AssertExpectations(t)
})
}

func TestCurrentNonce(t *testing.T) {
t.Parallel()
assert := assert.New(t)
Expand Down
31 changes: 15 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/0xPolygon/cdk-data-availability v0.0.5
github.com/0xPolygonHermez/zkevm-node v0.5.12
github.com/0xPolygonHermez/zkevm-node v0.0.0-20240222104536-0204affc7436
github.com/ethereum/go-ethereum v1.13.11
github.com/jackc/pgconn v1.14.1
github.com/jackc/pgx/v4 v4.18.1
Expand All @@ -13,13 +13,13 @@ require (
github.com/rubenv/sql-migrate v1.6.1
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.26.0
github.com/urfave/cli/v2 v2.27.1
go.opentelemetry.io/otel/exporters/prometheus v0.44.0
go.opentelemetry.io/otel/sdk/metric v1.21.0
)

require (
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.18 // indirect
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.19 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
Expand Down Expand Up @@ -66,14 +66,14 @@ require (
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hermeznetwork/tracerr v0.3.2 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/iden3/go-iden3-crypto v0.0.15 // indirect
github.com/iden3/go-iden3-crypto v0.0.16 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand All @@ -95,15 +95,14 @@ require (
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/miguelmota/go-solidity-sha3 v0.1.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
Expand Down Expand Up @@ -134,19 +133,19 @@ require (
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 5214610

Please sign in to comment.