Skip to content

Commit

Permalink
Start node only after the block containing rollup creation tx has bee…
Browse files Browse the repository at this point in the history
…n finalized (if supported)
  • Loading branch information
ganeshvanahalli committed Aug 16, 2024
1 parent d1fe9ab commit 2fe8f08
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,38 @@ func mainImpl() int {
}
}
}

// Before starting the node, wait until the transaction that deployed rollup is finalized
if nodeConfig.Node.ParentChainReader.Enable && rollupAddrs.DeployedAt > 0 {
currentFinalized, err := l1Reader.LatestFinalizedBlockNr(ctx)
if err != nil && errors.Is(err, headerreader.ErrBlockNumberNotSupported) {
log.Info("Finality not supported by parent chain, disabling the check to verify if rollup deployment tx was finalized", "err", err)
} else {
newHeaders, unsubscribe := l1Reader.Subscribe(false)
retriesOnError := 10
for currentFinalized < rollupAddrs.DeployedAt && retriesOnError > 0 {
select {
case <-newHeaders:
if finalized, err := l1Reader.LatestFinalizedBlockNr(ctx); err != nil {
if errors.Is(err, headerreader.ErrBlockNumberNotSupported) {
log.Error("Finality support was removed from parent chain mid way, disabling the check to verify if the rollup deployment tx was finalized", "err", err)
retriesOnError = 0 // Break out of for loop as well
break
}
log.Error("Error getting latestFinalizedBlockNr from l1Reader", "err", err)
retriesOnError--
} else {
currentFinalized = finalized
}
case <-ctx.Done():
log.Error("Context done while checking if the rollup deployment tx was finalized")
return 1
}
}
unsubscribe()
}
}

gqlConf := nodeConfig.GraphQL
if gqlConf.Enable {
if err := graphql.New(stack, execNode.Backend.APIBackend(), execNode.FilterSystem, gqlConf.CORSDomain, gqlConf.VHosts); err != nil {
Expand Down

0 comments on commit 2fe8f08

Please sign in to comment.