From 40cee945579dc520c12116a6d4cd7938544873da Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 23 Feb 2024 16:28:19 -0500 Subject: [PATCH] Adds a dumb 64 block wait before processing blocks. --- cmd/main.go | 9 +++++++++ pkg/l1Listener/l1Listener.go | 9 ++++++++- pkg/l1Listener/l1Listener_test.go | 2 +- pkg/node/node.go | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 3e0b83f..2ea5c53 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -154,6 +154,13 @@ var ( EnvVars: []string{"MEV_ORACLE_KEYSTORE_PATH"}, Value: filepath.Join(defaultConfigDir, defaultKeystore), }) + + optionWaitOnFinality = altsrc.NewBoolFlag(&cli.BoolFlag{ + Name: "wait-on-finality", + Usage: "wait for finality before sending settlement", + EnvVars: []string{"MEV_ORACLE_WAIT_ON_FINALITY"}, + Value: true, + }) ) func main() { @@ -175,6 +182,7 @@ func main() { optionOverrideWinners, optionKeystorePath, optionKeystorePassword, + optionWaitOnFinality, } app := &cli.App{ Name: "mev-oracle", @@ -308,6 +316,7 @@ func launchOracleWithConfig(c *cli.Context) error { PgDbname: c.String(optionPgDbname.Name), LaggerdMode: c.Int(optionLaggerdMode.Name), OverrideWinners: c.StringSlice(optionOverrideWinners.Name), + WaitOnFinality: c.Bool(optionWaitOnFinality.Name), }) if err != nil { return fmt.Errorf("failed starting node: %w", err) diff --git a/pkg/l1Listener/l1Listener.go b/pkg/l1Listener/l1Listener.go index ad6d981..52c86e3 100644 --- a/pkg/l1Listener/l1Listener.go +++ b/pkg/l1Listener/l1Listener.go @@ -26,16 +26,19 @@ type L1Listener struct { l1Client EthClient winnerRegister WinnerRegister metrics *metrics + waitOnFinality bool } func NewL1Listener( l1Client EthClient, winnerRegister WinnerRegister, + waitOnFinality bool, ) *L1Listener { return &L1Listener{ l1Client: l1Client, winnerRegister: winnerRegister, metrics: newMetrics(), + waitOnFinality: waitOnFinality, } } @@ -63,7 +66,11 @@ func (l *L1Listener) Start(ctx context.Context) <-chan struct{} { log.Error().Err(err).Msg("failed to get block number") continue } - + if l.waitOnFinality && blockNum > 64 { + // This is a weak proxy for finaility to limit exposure to reorgs + // TODO(@ckartik): Interact with Finality gadget to give a more robust implementation. + blockNum -= 64 + } if blockNum <= uint64(currentBlockNo) { continue } diff --git a/pkg/l1Listener/l1Listener_test.go b/pkg/l1Listener/l1Listener_test.go index 69c327b..de01f4d 100644 --- a/pkg/l1Listener/l1Listener_test.go +++ b/pkg/l1Listener/l1Listener_test.go @@ -25,7 +25,7 @@ func TestL1Listener(t *testing.T) { errC: make(chan error, 1), } - l := l1Listener.NewL1Listener(ethClient, reg) + l := l1Listener.NewL1Listener(ethClient, reg, true) ctx, cancel := context.WithCancel(context.Background()) cl := l1Listener.SetCheckInterval(100 * time.Millisecond) diff --git a/pkg/node/node.go b/pkg/node/node.go index 592eccc..ca701ec 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -38,6 +38,7 @@ type Options struct { PgDbname string LaggerdMode int OverrideWinners []string + WaitOnFinality bool } type Node struct { @@ -127,7 +128,7 @@ func NewNode(opts *Options) (*Node, error) { } } - l1Lis := l1Listener.NewL1Listener(listenerL1Client, st) + l1Lis := l1Listener.NewL1Listener(listenerL1Client, st, opts.WaitOnFinality) l1LisClosed := l1Lis.Start(ctx) callOpts := bind.CallOpts{