Skip to content

Commit

Permalink
chore: nits in avs writer
Browse files Browse the repository at this point in the history
  • Loading branch information
uri-99 committed Nov 13, 2024
1 parent b36763a commit 8330494
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/chainio/avs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
onGasPriceBumped(txOpts.GasPrice)
}

// We compare both Aggregator funds and Batcher balance in Aligned against respondToTaskFeeLimit
// Both are required to have some balance, more details inside the function
err = w.checkAggAndBatcherHaveEnoughBalance(tx, txOpts, batchIdentifierHash, senderAddress)
if err != nil {
return nil, retry.PermanentError{Inner: err}
Expand Down Expand Up @@ -154,17 +156,15 @@ func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(tx *types.Transaction,
}
respondToTaskFeeLimit := batchState.RespondToTaskFeeLimit

// NOTE we are not using tx.Cost() because tx.Cost() includes tx.Value()
txCost := new(big.Int).Mul(big.NewInt(int64(tx.Gas())), tx.GasPrice())
// todo: 70_000 should come from the config or at least be a constant
txCost = txCost.Add(txCost, big.NewInt(70_0000))

if respondToTaskFeeLimit.Cmp(txCost) < 0 {
aggregatorDifferencePaid := new(big.Int).Sub(txCost, respondToTaskFeeLimit)
aggregatorDifferencePaidInEth := utils.WeiToEth(aggregatorDifferencePaid)
w.metrics.AddAggregatorGasPaidForBatcher(aggregatorDifferencePaidInEth)
w.metrics.IncAggregatorPaidForBatcher()
w.logger.Warnf("cost of transaction was higher than Batch.RespondToTaskFeeLimit, aggregator has paid the for the difference, aprox: %vethers", aggregatorDifferencePaidInEth)
return
}
}

Expand All @@ -182,6 +182,9 @@ func (w *AvsWriter) checkAggAndBatcherHaveEnoughBalance(tx *types.Transaction, t
}
respondToTaskFeeLimit := batchState.RespondToTaskFeeLimit
w.logger.Info("Checking balance against Batch RespondToTaskFeeLimit", "RespondToTaskFeeLimit", respondToTaskFeeLimit)
// Note: we compare both Aggregator funds and Batcher balance in Aligned against respondToTaskFeeLimit
// Batcher will pay up to respondToTaskFeeLimit, for this he needs that amount of funds in Aligned
// Aggregator will pay any extra cost, for this he needs at least respondToTaskFeeLimit in his balance
return w.compareBalances(respondToTaskFeeLimit, aggregatorAddress, senderAddress)
}

Expand Down

0 comments on commit 8330494

Please sign in to comment.