From 545c003fdde17df06d654476b6bde879c7102546 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 19 Nov 2024 18:39:55 -0300 Subject: [PATCH 1/3] fix: nil dereference on aggregator retries `SendAggregatedResponse` would overwrite `tx`, which in the error case sets it to `nil`, causing the retry to dereference `nil`. This fix consists on using separate variables for the simulated tx and the real one. --- core/chainio/avs_writer.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index 012e069bb..27e2bf167 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -78,20 +78,20 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature, gasBumpPercentage uint, gasBumpIncrementalPercentage uint, timeToWaitBeforeBump time.Duration, onGasPriceBumped func(*big.Int)) (*types.Receipt, error) { txOpts := *w.Signer.GetTxOpts() txOpts.NoSend = true // simulate the transaction - tx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) + sim_tx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) if err != nil { return nil, err } - err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress) + err = w.checkRespondToTaskFeeLimit(sim_tx, txOpts, batchIdentifierHash, senderAddress) if err != nil { return nil, err } // Set the nonce, as we might have to replace the transaction with a higher gas price - txNonce := big.NewInt(int64(tx.Nonce())) + txNonce := big.NewInt(int64(sim_tx.Nonce())) txOpts.Nonce = txNonce - txOpts.GasPrice = tx.GasPrice() + txOpts.GasPrice = sim_tx.GasPrice() txOpts.NoSend = false i := 0 @@ -114,19 +114,19 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe onGasPriceBumped(txOpts.GasPrice) } - err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress) + err = w.checkRespondToTaskFeeLimit(sim_tx, txOpts, batchIdentifierHash, senderAddress) if err != nil { return nil, retry.PermanentError{Inner: err} } w.logger.Infof("Sending RespondToTask transaction with a gas price of %v", txOpts.GasPrice) - tx, err = w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) + real_tx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) if err != nil { return nil, err } - receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, tx.Hash(), timeToWaitBeforeBump) + receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, real_tx.Hash(), timeToWaitBeforeBump) if receipt != nil { return receipt, nil } From cd10c0270cf530731b655ebe2628c0e0c572306f Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 19 Nov 2024 19:00:32 -0300 Subject: [PATCH 2/3] fmt: don't change indent --- core/chainio/avs_writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index 28dc53899..e8dbe7b6a 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -114,7 +114,7 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe // 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(sim_tx, txOpts, batchIdentifierHash, senderAddress) + err = w.checkAggAndBatcherHaveEnoughBalance(sim_tx, txOpts, batchIdentifierHash, senderAddress) if err != nil { return nil, retry.PermanentError{Inner: err} } From 7b362a9df8dd595ab330a20d500f93e120f003c7 Mon Sep 17 00:00:00 2001 From: Julian Ventura Date: Wed, 20 Nov 2024 12:28:08 -0300 Subject: [PATCH 3/3] Rename variables to camelCase --- core/chainio/avs_writer.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/chainio/avs_writer.go b/core/chainio/avs_writer.go index e8dbe7b6a..f80de6627 100644 --- a/core/chainio/avs_writer.go +++ b/core/chainio/avs_writer.go @@ -81,15 +81,15 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature, gasBumpPercentage uint, gasBumpIncrementalPercentage uint, timeToWaitBeforeBump time.Duration, onGasPriceBumped func(*big.Int)) (*types.Receipt, error) { txOpts := *w.Signer.GetTxOpts() txOpts.NoSend = true // simulate the transaction - sim_tx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) + simTx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) if err != nil { return nil, err } // Set the nonce, as we might have to replace the transaction with a higher gas price - txNonce := big.NewInt(int64(sim_tx.Nonce())) + txNonce := big.NewInt(int64(simTx.Nonce())) txOpts.Nonce = txNonce - txOpts.GasPrice = sim_tx.GasPrice() + txOpts.GasPrice = simTx.GasPrice() txOpts.NoSend = false i := 0 @@ -114,21 +114,21 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe // 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(sim_tx, txOpts, batchIdentifierHash, senderAddress) + err = w.checkAggAndBatcherHaveEnoughBalance(simTx, txOpts, batchIdentifierHash, senderAddress) if err != nil { return nil, retry.PermanentError{Inner: err} } w.logger.Infof("Sending RespondToTask transaction with a gas price of %v", txOpts.GasPrice) - real_tx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) + realTx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature) if err != nil { return nil, err } - receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, real_tx.Hash(), timeToWaitBeforeBump) + receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, realTx.Hash(), timeToWaitBeforeBump) if receipt != nil { - w.checkIfAggregatorHadToPaidForBatcher(real_tx, batchIdentifierHash) + w.checkIfAggregatorHadToPaidForBatcher(realTx, batchIdentifierHash) return receipt, nil }