From db58152218ff39fa0cb5c916e195b6280d590412 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 14 Aug 2024 00:36:41 +0000 Subject: [PATCH] Fill bot: fallback to filling each message individually. --- CHANGELOG.md | 1 + .../orderbookfiller/context/tx/tx_context.go | 8 ++++++ .../ordebook_filler_ingest_plugin.go | 26 +++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7063e675c..6ce3e7dab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - Ingest tracing - Apply taker fee and spread factor for fill bot amount estimation - Reduce fill bot slippage bound by one ulp +- Fallback to filling each message individually. ## v25.9.0 diff --git a/ingest/usecase/plugins/orderbookfiller/context/tx/tx_context.go b/ingest/usecase/plugins/orderbookfiller/context/tx/tx_context.go index c2dd42235..4131a15e3 100644 --- a/ingest/usecase/plugins/orderbookfiller/context/tx/tx_context.go +++ b/ingest/usecase/plugins/orderbookfiller/context/tx/tx_context.go @@ -19,6 +19,9 @@ type TxContextI interface { // GetSDKMsgs returns chain messages associated with this transaction context as sdk.Msg. GetSDKMsgs() []sdk.Msg + // GetMsgs returns message contexts + GetMsgs() []msgctx.MsgContextI + // GetAdjustedGasUsedTotal returns the gas used after simulating this transaction // against chain and adjusting the gas by a constant pre-configured multiplier. GetAdjustedGasUsedTotal() uint64 @@ -145,3 +148,8 @@ func (t *txContext) RankAndFilterMsgs() { func (t *txContext) GetMaxTxFeeCap() osmomath.Dec { return t.maxTxFeeCap } + +// GetMsgs implements TxContextI. +func (t *txContext) GetMsgs() []msgctx.MsgContextI { + return t.msgs +} diff --git a/ingest/usecase/plugins/orderbookfiller/ordebook_filler_ingest_plugin.go b/ingest/usecase/plugins/orderbookfiller/ordebook_filler_ingest_plugin.go index 8300b46f5..1f6ed6a1b 100644 --- a/ingest/usecase/plugins/orderbookfiller/ordebook_filler_ingest_plugin.go +++ b/ingest/usecase/plugins/orderbookfiller/ordebook_filler_ingest_plugin.go @@ -163,11 +163,33 @@ func (o *orderbookFillerIngestPlugin) ProcessEndBlock(ctx context.Context, block } } - // Execute tx txCtx := blockCtx.GetTxCtx() + originalMsgs := blockCtx.GetTxCtx().GetMsgs() + blockGasPrice := blockCtx.GetGasPrice() if err := o.tryFill(ctx, txCtx, blockGasPrice); err != nil { - o.logger.Error("failed to fill", zap.Error(err)) + + if len(originalMsgs) == 1 { + o.logger.Error("failed to fill", zap.Error(err)) + return err + } else { + o.logger.Error("failed to fill batch of arbs as one tx - falling back to executing each message as separate tx", zap.Error(err)) + + // Try to fill each message indivdually + for _, msg := range originalMsgs { + + // Create a new transaction context for each message + curTxCtx := txctx.New() + + // Add the message to the transaction context + curTxCtx.AddMsg(msg) + + // Try to fill the message + if err := o.tryFill(ctx, txCtx, blockGasPrice); err != nil { + o.logger.Error("failed to fill individual msg tx", zap.Error(err)) + } + } + } } o.logger.Info("processed end block in orderbook filler ingest plugin", zap.Uint64("block_height", blockHeight))