Skip to content

Commit a5d0893

Browse files
committed
fix: gas cost calculation
1 parent e997ed8 commit a5d0893

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

core/chainio/avs_writer.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
8686
return nil, err
8787
}
8888

89-
err = w.checkAggAndBatcherHaveEnoughBalance(tx, txOpts, batchIdentifierHash, senderAddress)
90-
if err != nil {
91-
return nil, err
92-
}
93-
9489
// Set the nonce, as we might have to replace the transaction with a higher gas price
9590
txNonce := big.NewInt(int64(tx.Nonce()))
9691
txOpts.Nonce = txNonce
@@ -131,7 +126,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
131126

132127
receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, tx.Hash(), timeToWaitBeforeBump)
133128
if receipt != nil {
134-
w.checkIfAggregatorHadToPaidForBatcher(receipt, txOpts, batchIdentifierHash)
129+
w.checkIfAggregatorHadToPaidForBatcher(tx, batchIdentifierHash)
135130
return receipt, nil
136131
}
137132

@@ -152,18 +147,18 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
152147
// Calculates the transaction cost from the receipt and compares it with the batcher respondToTaskFeeLimit
153148
// if the tx cost was higher, then it means the aggregator has paid the difference for the batcher (txCost - respondToTaskFeeLimit) and so metrics are updated accordingly.
154149
// otherwise nothing is done.
155-
func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(receipt *types.Receipt, txOpts bind.TransactOpts, batchIdentifierHash [32]byte) {
150+
func (w *AvsWriter) checkIfAggregatorHadToPaidForBatcher(tx *types.Transaction, batchIdentifierHash [32]byte) {
156151
batchState, err := w.BatchesStateRetryable(&bind.CallOpts{}, batchIdentifierHash)
157152
if err != nil {
158153
return
159154
}
160155
respondToTaskFeeLimit := batchState.RespondToTaskFeeLimit
161156

162-
txCost := new(big.Int).Mul(big.NewInt(int64(receipt.GasUsed)), txOpts.GasPrice)
157+
txCost := new(big.Int).Mul(big.NewInt(int64(tx.Gas())), tx.GasPrice())
163158
// todo: 70_000 should come from the config or at least be a constant
164159
txCost = txCost.Add(txCost, big.NewInt(70_0000))
165160

166-
if respondToTaskFeeLimit.Cmp(txCost) > 0 {
161+
if respondToTaskFeeLimit.Cmp(txCost) < 0 {
167162
aggregatorDifferencePaid := new(big.Int).Sub(txCost, respondToTaskFeeLimit)
168163
aggregatorDifferencePaidInEth := utils.WeiToEth(aggregatorDifferencePaid)
169164
w.metrics.AddAggregatorGasPaidForBatcher(aggregatorDifferencePaidInEth)

core/retry_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func TestRespondToTaskV2(t *testing.T) {
681681
}
682682

683683
aggregatorConfig := config.NewAggregatorConfig("../config-files/config-aggregator-test.yaml")
684-
w, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig)
684+
w, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig, nil)
685685
if err != nil {
686686
t.Errorf("Error killing process: %v\n", err)
687687
return
@@ -734,7 +734,7 @@ func TestBatchesStateWriter(t *testing.T) {
734734
}
735735

736736
aggregatorConfig := config.NewAggregatorConfig("../config-files/config-aggregator-test.yaml")
737-
avsWriter, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig)
737+
avsWriter, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig, nil)
738738
if err != nil {
739739
t.Errorf("Error killing process: %v\n", err)
740740
return
@@ -784,7 +784,7 @@ func TestBalanceAt(t *testing.T) {
784784
}
785785

786786
aggregatorConfig := config.NewAggregatorConfig("../config-files/config-aggregator-test.yaml")
787-
avsWriter, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig)
787+
avsWriter, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig, nil)
788788
if err != nil {
789789
return
790790
}
@@ -831,7 +831,7 @@ func TestBatchersBalances(t *testing.T) {
831831
}
832832

833833
aggregatorConfig := config.NewAggregatorConfig("../config-files/config-aggregator-test.yaml")
834-
avsWriter, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig)
834+
avsWriter, err := chainio.NewAvsWriterFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig, nil)
835835
if err != nil {
836836
return
837837
}

0 commit comments

Comments
 (0)