Skip to content

Commit 896b98c

Browse files
committed
feat: basic aggregator bump modelling
1 parent 27a9c6a commit 896b98c

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

aggregator/internal/pkg/aggregator.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (agg *Aggregator) sendAggregatedResponse(batchIdentifierHash [32]byte, batc
301301
"senderAddress", hex.EncodeToString(senderAddress[:]),
302302
"batchIdentifierHash", hex.EncodeToString(batchIdentifierHash[:]))
303303

304-
txHash, err := agg.avsWriter.SendAggregatedResponse(batchIdentifierHash, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
304+
receipt, err := agg.avsWriter.SendAggregatedResponse(batchIdentifierHash, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
305305
if err != nil {
306306
agg.walletMutex.Unlock()
307307
agg.logger.Infof("- Unlocked Wallet Resources: Error sending aggregated response for batch %s. Error: %s", hex.EncodeToString(batchIdentifierHash[:]), err)
@@ -312,13 +312,6 @@ func (agg *Aggregator) sendAggregatedResponse(batchIdentifierHash [32]byte, batc
312312
agg.walletMutex.Unlock()
313313
agg.logger.Infof("- Unlocked Wallet Resources: Sending aggregated response for batch %s", hex.EncodeToString(batchIdentifierHash[:]))
314314

315-
receipt, err := utils.WaitForTransactionReceipt(
316-
agg.AggregatorConfig.BaseConfig.EthRpcClient, context.Background(), *txHash)
317-
if err != nil {
318-
agg.telemetry.LogTaskError(batchMerkleRoot, err)
319-
return nil, err
320-
}
321-
322315
agg.metrics.IncAggregatedResponses()
323316

324317
return receipt, nil

core/chainio/avs_writer.go

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import (
1111
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
1212
"github.com/Layr-Labs/eigensdk-go/logging"
1313
"github.com/Layr-Labs/eigensdk-go/signer"
14+
"github.com/ethereum/go-ethereum"
1415
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1516
"github.com/ethereum/go-ethereum/common"
1617
"github.com/ethereum/go-ethereum/core/types"
1718
servicemanager "github.com/yetanotherco/aligned_layer/contracts/bindings/AlignedLayerServiceManager"
1819
"github.com/yetanotherco/aligned_layer/core/config"
20+
"github.com/yetanotherco/aligned_layer/core/utils"
1921
)
2022

2123
type AvsWriter struct {
@@ -70,7 +72,7 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
7072
}, nil
7173
}
7274

73-
func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature) (*common.Hash, error) {
75+
func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature) (*types.Receipt, error) {
7476
txOpts := *w.Signer.GetTxOpts()
7577
txOpts.NoSend = true // simulate the transaction
7678
tx, err := w.AvsContractBindings.ServiceManager.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
@@ -87,21 +89,55 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
8789
return nil, err
8890
}
8991

90-
// Send the transaction
92+
// Set the nonce, as we might have to replace the transaction with a higher fee
93+
txNonce := new(big.Int).SetUint64(tx.Nonce())
9194
txOpts.NoSend = false
92-
txOpts.GasLimit = tx.Gas() * 110 / 100 // Add 10% to the gas limit
93-
tx, err = w.AvsContractBindings.ServiceManager.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
94-
if err != nil {
95-
// Retry with fallback
96-
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
95+
txOpts.Nonce = txNonce
96+
97+
// Send the transaction
98+
var maxRetries uint64 = 5
99+
var i uint64
100+
for i = 1; i < maxRetries; i++ {
101+
// Add x% to the gas limit, where x 10 <= x <= 50
102+
txOpts.GasLimit = tx.Gas() * (100 + i*10) / 100
103+
w.logger.Debugf("Sending ResponseToTask transaction for %vth with a gas limit of %v", i, txOpts.GasLimit)
104+
err = w.checkRespondToTaskFeeLimit(tx, txOpts, batchIdentifierHash, senderAddress)
97105
if err != nil {
98106
return nil, err
99107
}
100-
}
101108

102-
txHash := tx.Hash()
109+
tx, err = w.AvsContractBindings.ServiceManager.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
110+
if err != nil {
111+
// Retry with fallback
112+
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskV2(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
113+
if err != nil {
114+
return nil, err
115+
}
116+
}
117+
ctx, _ := context.WithTimeout(context.Background(), time.Second*20)
118+
receipt, err := utils.WaitForTransactionReceipt(w.Client, ctx, tx.Hash())
119+
120+
if receipt != nil {
121+
if receipt.Status == 0 {
122+
return receipt, fmt.Errorf("transaction failed")
123+
} else {
124+
// transaction was included in block
125+
w.logger.Debugf("Sending ResponseToTask transaction for %vth with a gas limit of %v", i, txOpts.GasLimit)
126+
return receipt, nil
127+
}
128+
}
129+
130+
// transaction not included in block, try again
131+
if err == ethereum.NotFound {
132+
w.logger.Debugf("Transaction not included in block will try again")
133+
continue
134+
} else {
135+
return receipt, err
136+
}
137+
138+
}
103139

104-
return &txHash, nil
140+
return nil, fmt.Errorf("could not send transaction")
105141
}
106142

107143
func (w *AvsWriter) checkRespondToTaskFeeLimit(tx *types.Transaction, txOpts bind.TransactOpts, batchIdentifierHash [32]byte, senderAddress [20]byte) error {

0 commit comments

Comments
 (0)