Skip to content

Commit

Permalink
feat: expand config
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Jul 26, 2024
1 parent 28037c8 commit 29d599c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
11 changes: 5 additions & 6 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ type AggSender struct {

// New returns a new AggSender
func New(
originNetwork uint32,
cfg Config,
reorgDetector localbridgesync.ReorgDetector,
aggLayerClient agglayer.AggLayerClient,
l2Client localbridgesync.EthClienter,
syncerCfg localbridgesync.LocalBridgeSyncerConfig) (*AggSender, error) {
syncer, err := localbridgesync.New(syncerCfg, reorgDetector, l2Client)
l2Client localbridgesync.EthClienter) (*AggSender, error) {
syncer, err := localbridgesync.New(cfg.LocalBridgeSyncer, reorgDetector, l2Client)
if err != nil {
return nil, err
}

db, err := mdbx.NewMDBX(nil).
Path(filepath.Join(syncerCfg.DBPath, aggSenderDBFolder)).
Path(filepath.Join(cfg.LocalBridgeSyncer.DBPath, aggSenderDBFolder)).
WithTableCfg(tableCfgFunc).
Open()
if err != nil {
Expand All @@ -66,8 +65,8 @@ func New(
db: db,
syncer: syncer,
client: l2Client,
originNetwork: originNetwork,
aggLayerClient: aggLayerClient,
originNetwork: cfg.OriginNetwork,
}, nil
}

Expand Down
10 changes: 10 additions & 0 deletions aggsender/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package aggsender

import "github.com/0xPolygon/cdk/localbridgesync"

// Config is the configuration for the AggSender
type Config struct {
OriginNetwork uint32 `mapstructure:"OriginNetwork"`
AggLayerUrl string `mapstructure:"AggLayerUrl"`
LocalBridgeSyncer localbridgesync.Config `mapstructure:"LocalBridgeSyncer"`
}
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/0xPolygon/cdk/aggregator"
"github.com/0xPolygon/cdk/aggsender"
"github.com/0xPolygon/cdk/common"
ethermanconfig "github.com/0xPolygon/cdk/etherman/config"
"github.com/0xPolygon/cdk/log"
Expand Down Expand Up @@ -69,6 +70,8 @@ type Config struct {
SequenceSender sequencesender.Config
// Common Config that affects all the services
Common common.Config
// Configuration of the agg sender service
AggSender aggsender.Config
}

// Default parses the default configuration values.
Expand Down
9 changes: 9 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ SequencerPrivateKey = {}
[Aggregator.Synchronizer.Etherman]
[Aggregator.Synchronizer.Etherman.Validium]
Enabled = false
[AggSender]
OriginNetwork = 0
AggLayerUrl = ""
[AggSender.LocalBridgeSyncer]
DBPath = "./db"
BridgeAddr = ""
SyncBlockChunkSize = "10"
BlockFinalityType = "finalized"
`
14 changes: 14 additions & 0 deletions localbridgesync/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package localbridgesync

import (
"github.com/0xPolygon/cdk/etherman"
"github.com/ethereum/go-ethereum/common"
)

// Config struct for local bridge syncer
type Config struct {
DBPath string `mapstructure:"DBPath"`
BridgeAddr common.Address `mapstructure:"BridgeAddr"`
SyncBlockChunkSize uint64 `mapstructure:"SyncBlockChunkSize"`
BlockFinalityType etherman.BlockNumberFinality `mapstructure:"BlockFinalityType"`
}
4 changes: 2 additions & 2 deletions localbridgesync/localbridgesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type LocalBridgeSync struct {
}

func New(
cfg LocalBridgeSyncerConfig,
cfg Config,
rd ReorgDetector,
l2Client EthClienter,
) (*LocalBridgeSync, error) {
p, err := newProcessor(cfg.DBPath)
if err != nil {
return nil, err
}
dwn, err := newDownloader(cfg.Bridge, l2Client, cfg.SyncBlockChunkSize, cfg.BlockFinalityType)
dwn, err := newDownloader(cfg.BridgeAddr, l2Client, cfg.SyncBlockChunkSize, cfg.BlockFinalityType)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 29d599c

Please sign in to comment.