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

Wait 64 blocks before processing commitments #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -175,6 +182,7 @@ func main() {
optionOverrideWinners,
optionKeystorePath,
optionKeystorePassword,
optionWaitOnFinality,
}
app := &cli.App{
Name: "mev-oracle",
Expand Down Expand Up @@ -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),
ckartik marked this conversation as resolved.
Show resolved Hide resolved
})
if err != nil {
return fmt.Errorf("failed starting node: %w", err)
Expand Down
9 changes: 8 additions & 1 deletion pkg/l1Listener/l1Listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/l1Listener/l1Listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Options struct {
PgDbname string
LaggerdMode int
OverrideWinners []string
WaitOnFinality bool
}

type Node struct {
Expand Down Expand Up @@ -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{
Expand Down
Loading