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

feat: calculate network id #212

Open
wants to merge 6 commits into
base: release/v0.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions bridgesync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ type Config struct {
MaxRetryAttemptsAfterError int `mapstructure:"MaxRetryAttemptsAfterError"`
// WaitForNewBlocksPeriod time that will be waited when the synchronizer has reached the latest block
WaitForNewBlocksPeriod types.Duration `mapstructure:"WaitForNewBlocksPeriod"`
// OriginNetwork is the id of the network where the bridge is deployed
OriginNetwork uint32 `mapstructure:"OriginNetwork"`
}
24 changes: 18 additions & 6 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func start(cliCtx *cli.Context) error {

l1InfoTreeSync := runL1InfoTreeSyncerIfNeeded(cliCtx.Context, components, *c, l1Client, reorgDetectorL1)
claimSponsor := runClaimSponsorIfNeeded(cliCtx.Context, components, l2Client, c.ClaimSponsor)
l1BridgeSync := runBridgeSyncL1IfNeeded(cliCtx.Context, components, c.BridgeL1Sync, reorgDetectorL1, l1Client)
l2BridgeSync := runBridgeSyncL2IfNeeded(cliCtx.Context, components, c.BridgeL2Sync, reorgDetectorL2, l2Client)
l1BridgeSync := runBridgeSyncL1IfNeeded(cliCtx.Context, components, *c, reorgDetectorL1, l1Client)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that is not related to your PR, but renaming c for config or even for cfg would be really nice

l2BridgeSync := runBridgeSyncL2IfNeeded(cliCtx.Context, components, *c, reorgDetectorL2, l2Client)
lastGERSync := runLastGERSyncIfNeeded(
cliCtx.Context, components, c.LastGERSync, reorgDetectorL2, l2Client, l1InfoTreeSync,
)
Expand Down Expand Up @@ -683,13 +683,19 @@ func runLastGERSyncIfNeeded(
func runBridgeSyncL1IfNeeded(
ctx context.Context,
components []string,
cfg bridgesync.Config,
c config.Config,
reorgDetectorL1 *reorgdetector.ReorgDetector,
l1Client *ethclient.Client,
) *bridgesync.BridgeSync {
if !isNeeded([]string{cdkcommon.RPC}, components) {
return nil
}
ethermanClient, err := newEtherman(c)
if err != nil {
log.Fatal(err)
}

cfg := c.BridgeL1Sync
bridgeSyncL1, err := bridgesync.NewL1(
ctx,
cfg.DBPath,
Expand All @@ -702,7 +708,7 @@ func runBridgeSyncL1IfNeeded(
cfg.WaitForNewBlocksPeriod.Duration,
cfg.RetryAfterErrorPeriod.Duration,
cfg.MaxRetryAttemptsAfterError,
cfg.OriginNetwork,
ethermanClient.RollupID,
)
if err != nil {
log.Fatalf("error creating bridgeSyncL1: %s", err)
Expand All @@ -715,14 +721,20 @@ func runBridgeSyncL1IfNeeded(
func runBridgeSyncL2IfNeeded(
ctx context.Context,
components []string,
cfg bridgesync.Config,
c config.Config,
reorgDetectorL2 *reorgdetector.ReorgDetector,
l2Client *ethclient.Client,
) *bridgesync.BridgeSync {
if !isNeeded([]string{cdkcommon.RPC, cdkcommon.AGGSENDER}, components) {
return nil
}

ethermanClient, err := newEtherman(c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing c config.Config to be able to create a ethClient, inject the etherClient. There are 2 functions on run.go that create the common instance for all classes:

  • runL1ClientIfNeeded
  • runL2ClientIfNeeded

if err != nil {
log.Fatal(err)
}

cfg := c.BridgeL2Sync
bridgeSyncL2, err := bridgesync.NewL2(
ctx,
cfg.DBPath,
Expand All @@ -735,7 +747,7 @@ func runBridgeSyncL2IfNeeded(
cfg.WaitForNewBlocksPeriod.Duration,
cfg.RetryAfterErrorPeriod.Duration,
cfg.MaxRetryAttemptsAfterError,
cfg.OriginNetwork,
ethermanClient.RollupID,
)
if err != nil {
log.Fatalf("error creating bridgeSyncL2: %s", err)
Expand Down
2 changes: 0 additions & 2 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ SyncBlockChunkSize = 100
RetryAfterErrorPeriod = "1s"
MaxRetryAttemptsAfterError = -1
WaitForNewBlocksPeriod = "3s"
OriginNetwork=0

[BridgeL2Sync]
DBPath = "{{PathRWData}}/bridgel2sync.sqlite"
Expand All @@ -307,7 +306,6 @@ SyncBlockChunkSize = 100
RetryAfterErrorPeriod = "1s"
MaxRetryAttemptsAfterError = -1
WaitForNewBlocksPeriod = "3s"
OriginNetwork=1

[LastGERSync]
DBPath = "{{PathRWData}}/lastgersync.sqlite"
Expand Down
Loading