Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Aggregator: use sequenceBatch maxTimestamp as TimestampLimit #84

Merged
merged 9 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 61 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"bytes"
"errors"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -52,6 +51,22 @@ const (
FlagOutputFile = "output"
// FlagMaxAmount is the flag to avoid to use the flag FlagAmount
FlagMaxAmount = "max-amount"

deprecatedFieldSyncDB = "Aggregator.Synchronizer.DB is deprecated use Aggregator.Synchronizer.SQLDB instead"
)

type ForbiddenField struct {
FieldName string
Reason string
}

var (
forbiddenFieldsOnConfig = []ForbiddenField{
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
{
FieldName: "aggregator.synchronizer.db.",
Reason: deprecatedFieldSyncDB,
},
}
)

/*
Expand Down Expand Up @@ -128,15 +143,18 @@ func Default() (*Config, error) {

return &cfg, nil
}
func Load(ctx *cli.Context) (*Config, error) {
configFilePath := ctx.String(FlagCfg)
return LoadFile(configFilePath)
}

// Load loads the configuration
func Load(ctx *cli.Context) (*Config, error) {
func LoadFile(configFilePath string) (*Config, error) {
cfg, err := Default()
if err != nil {
return nil, err
}

configFilePath := ctx.String(FlagCfg)
expectedKeys := viper.AllKeys()
if configFilePath != "" {
dirName, fileName := filepath.Split(configFilePath)

Expand All @@ -160,7 +178,6 @@ func Load(ctx *cli.Context) (*Config, error) {
log.Error("config file not found")
} else {
log.Errorf("error reading config file: ", err)

return nil, err
}
}
Expand All @@ -179,8 +196,45 @@ func Load(ctx *cli.Context) (*Config, error) {
if err != nil {
return nil, err
}
if expectedKeys != nil {
configKeys := viper.AllKeys()
unexpectedFields := getUnexpectedFields(configKeys, expectedKeys)
for _, field := range unexpectedFields {
forbbidenInfo := getForbiddenField(field)
if forbbidenInfo != nil {
log.Warnf("forbidden field %s in config file: %s", field, forbbidenInfo.Reason)
} else {
log.Debugf("field %s in config file doesnt have a default value", field)
}
}
}
return cfg, nil
}

fmt.Println("cfg", cfg.NetworkConfig.L1Config)
func getForbiddenField(fieldName string) *ForbiddenField {
for _, forbiddenField := range forbiddenFieldsOnConfig {
if forbiddenField.FieldName == fieldName || strings.HasPrefix(fieldName, forbiddenField.FieldName) {
return &forbiddenField
}
}
return nil
}

return cfg, nil
func getUnexpectedFields(keysOnFile, expectedConfigKeys []string) []string {
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
wrongFields := make([]string, 0)
for _, key := range keysOnFile {
if !contains(expectedConfigKeys, key) {
wrongFields = append(wrongFields, key)
}
}
return wrongFields
}

func contains(keys []string, key string) bool {
for _, k := range keys {
if k == key {
return true
}
}
return false
}
51 changes: 51 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package config

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestLoadDeafaultConfig(t *testing.T) {
tmpFile, err := os.CreateTemp("", "ut_config")
require.NoError(t, err)
defer os.Remove(tmpFile.Name())
_, err = tmpFile.Write([]byte(DefaultValues))
require.NoError(t, err)
cfg, err := LoadFile(tmpFile.Name())
require.NoError(t, err)
require.NotNil(t, cfg)
}

const configWithUnexpectedFields = `
[UnknownField]
Field = "value"
`

func TestLoadConfigWithUnexpectedFields(t *testing.T) {
tmpFile, err := os.CreateTemp("", "ut_config")
require.NoError(t, err)
defer os.Remove(tmpFile.Name())
_, err = tmpFile.Write([]byte(configWithUnexpectedFields))
require.NoError(t, err)
cfg, err := LoadFile(tmpFile.Name())
require.NoError(t, err)
require.NotNil(t, cfg)
}

const configWithForbiddenFields = `
[aggregator.synchronizer.db]
name = "value"
`

func TestLoadConfigWithForbiddenFields(t *testing.T) {
tmpFile, err := os.CreateTemp("", "ut_config")
require.NoError(t, err)
defer os.Remove(tmpFile.Name())
_, err = tmpFile.Write([]byte(configWithForbiddenFields))
require.NoError(t, err)
cfg, err := LoadFile(tmpFile.Name())
require.NoError(t, err)
require.NotNil(t, cfg)
}
27 changes: 18 additions & 9 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ SequencerPrivateKey = {}
L1ChainID = 11155111
HTTPHeaders = []
[Aggregator.Synchronizer]
[Aggregator.Synchronizer.DB]
Name = "sync_db"
User = "sync_user"
Password = "sync_password"
Host = "cdk-l1-sync-db"
Port = "5432"
EnableLog = false
MaxConns = 10
[Aggregator.Synchronizer.Log]
Environment = "development" # "production" or "development"
Level = "info"
Outputs = ["stderr"]
[Aggregator.Synchronizer.SQLDB]
DriverName = "sqlite3"
DataSourceName = "file:/tmp/aggregator_sync_db.sqlite"
[Aggregator.Synchronizer.Synchronizer]
SyncInterval = "10s"
SyncChunkSize = 1000
Expand All @@ -122,9 +121,19 @@ SequencerPrivateKey = {}
BlockFinality = "finalized"
OverrideStorageCheck = false
[Aggregator.Synchronizer.Etherman]
L1URL = "http://localhost:8545"
ForkIDChunkSize = 100
L1ChainID = 0
[Aggregator.Synchronizer.Etherman.Validium]
Enabled = false

TrustedSequencerURL = ""
RetryOnDACErrorInterval = "1m"
DataSourcePriority = ["trusted", "external"]
[Aggregator.Synchronizer.Etherman.Validium.Translator]
FullMatchRules = []
[Aggregator.Synchronizer.Etherman.Validium.RateLimit]
NumRequests = 900
Interval = "1s"
[ReorgDetectorL1]
DBPath = "/tmp/reorgdetectorl1"

Expand Down
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/0xPolygon/cdk-rpc v0.0.0-20240905074455-431d3c271fe8
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.6
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240716105056-c051c96d0234
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.7.0
github.com/ethereum/go-ethereum v1.14.5
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.1
github.com/ethereum/go-ethereum v1.14.8
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/hermeznetwork/tracerr v0.3.2
github.com/iden3/go-iden3-crypto v0.0.16
Expand All @@ -19,17 +19,17 @@ require (
github.com/ledgerwatch/erigon-lib v1.0.0
github.com/mattn/go-sqlite3 v1.14.23
github.com/mitchellh/mapstructure v1.5.0
github.com/rubenv/sql-migrate v1.6.1
github.com/rubenv/sql-migrate v1.7.0
github.com/russross/meddler v1.0.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.2
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/metric v1.24.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.24.0
golang.org/x/net v0.26.0
golang.org/x/sync v0.7.0
golang.org/x/crypto v0.27.0
golang.org/x/net v0.29.0
golang.org/x/sync v0.8.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.2
modernc.org/sqlite v1.32.0
Expand All @@ -44,13 +44,14 @@ require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
Expand All @@ -66,10 +67,9 @@ require (
github.com/erigontech/mdbx-go v0.27.14 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/fjl/memsize v0.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -87,7 +87,7 @@ require (
github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157 // indirect
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand Down Expand Up @@ -149,8 +149,8 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading
Loading