Skip to content

Commit a2364dc

Browse files
committed
refactor: InitializeNewTask uses TaskMetadata
refactor: eigenLayerWriter now uses NewWriterFromConfig instead of BuildELChainWriter refactor: EDCDSA now uses SignerFn refactor: use TxManager to send transactions (bump logic does not work) refactor: ProcessNewSignature uses TaskSignature
1 parent 124eba8 commit a2364dc

9 files changed

Lines changed: 287 additions & 152 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export OPERATOR_ADDRESS ?= $(shell yq -r '.operator.address' $(CONFIG_FILE))
88
AGG_CONFIG_FILE?=config-files/config-aggregator.yaml
99

1010
OPERATOR_VERSION=v0.15.2
11-
EIGEN_SDK_GO_VERSION_DEVNET=v0.2.0-beta.1
11+
EIGEN_SDK_GO_VERSION_DEVNET=v0.3.0
1212
EIGEN_SDK_GO_VERSION_TESTNET=v0.2.0-beta.1
1313
EIGEN_SDK_GO_VERSION_MAINNET=v0.2.0-beta.1
1414

aggregator/pkg/aggregator.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,14 @@ func (agg *Aggregator) AddNewTask(batchMerkleRoot [32]byte, senderAddress [20]by
410410
quorumNums := eigentypes.QuorumNums{eigentypes.QuorumNum(QUORUM_NUMBER)}
411411
quorumThresholdPercentages := eigentypes.QuorumThresholdPercentages{eigentypes.QuorumThresholdPercentage(QUORUM_THRESHOLD)}
412412

413-
err := agg.blsAggregationService.InitializeNewTaskWithWindow(batchIndex, taskCreatedBlock, quorumNums, quorumThresholdPercentages, agg.AggregatorConfig.Aggregator.BlsServiceTaskTimeout, 15*time.Second)
413+
taskMetadata := blsagg.NewTaskMetadata(
414+
batchIndex,
415+
taskCreatedBlock,
416+
quorumNums,
417+
quorumThresholdPercentages,
418+
agg.AggregatorConfig.Aggregator.BlsServiceTaskTimeout,
419+
).WithWindowDuration(15 * time.Second)
420+
err := agg.blsAggregationService.InitializeNewTask(taskMetadata)
414421
if err != nil {
415422
agg.logger.Fatalf("BLS aggregation service error when initializing new task: %s", err)
416423
}

aggregator/pkg/server.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"errors"
77
"fmt"
8+
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"
89
"net/http"
910
"net/rpc"
1011
"time"
@@ -85,18 +86,24 @@ func (agg *Aggregator) ProcessOperatorSignedTaskResponseV2(signedTaskResponse *t
8586

8687
agg.logger.Info("Starting bls signature process")
8788
go func() {
89+
taskSignature := blsagg.NewTaskSignature(
90+
taskIndex,
91+
signedTaskResponse.BatchIdentifierHash,
92+
&signedTaskResponse.BlsSignature,
93+
signedTaskResponse.OperatorId,
94+
)
8895
err := agg.blsAggregationService.ProcessNewSignature(
89-
context.Background(), taskIndex, signedTaskResponse.BatchIdentifierHash,
90-
&signedTaskResponse.BlsSignature, signedTaskResponse.OperatorId,
96+
context.Background(),
97+
taskSignature,
9198
)
9299

93100
if err != nil {
94101
agg.logger.Warnf("BLS aggregation service error: %s", err)
95-
done<- 1
102+
done <- 1
96103
// todo shouldn't we here close the channel with a reply = 1?
97104
} else {
98105
agg.logger.Info("BLS process succeeded")
99-
done<- 0
106+
done <- 0
100107
}
101108

102109
close(done)

core/chainio/avs_writer.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"context"
55
"encoding/hex"
66
"fmt"
7+
"github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
8+
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
79
"math/big"
810
"time"
911

1012
"github.com/Layr-Labs/eigensdk-go/chainio/clients"
1113
"github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry"
1214
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
1315
"github.com/Layr-Labs/eigensdk-go/logging"
14-
"github.com/Layr-Labs/eigensdk-go/signer"
1516
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1617
"github.com/ethereum/go-ethereum/common"
1718
"github.com/ethereum/go-ethereum/core/types"
@@ -26,7 +27,8 @@ type AvsWriter struct {
2627
*avsregistry.ChainWriter
2728
AvsContractBindings *AvsServiceBindings
2829
logger logging.Logger
29-
Signer signer.Signer
30+
TxManager txmgr.SimpleTxManager
31+
TxManagerFallback txmgr.SimpleTxManager
3032
Client eth.InstrumentedClient
3133
ClientFallback eth.InstrumentedClient
3234
metrics *metrics.Metrics
@@ -41,6 +43,7 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
4143
OperatorStateRetrieverAddr: baseConfig.AlignedLayerDeploymentConfig.AlignedLayerOperatorStateRetrieverAddr.String(),
4244
AvsName: "AlignedLayer",
4345
PromMetricsIpPortAddress: baseConfig.EigenMetricsIpPortAddress,
46+
ServiceManagerAddress: baseConfig.AlignedLayerDeploymentConfig.AlignedLayerServiceManagerAddr.String(),
4447
}
4548

4649
clients, err := clients.BuildAll(buildAllConfig, ecdsaConfig.PrivateKey, baseConfig.Logger)
@@ -57,19 +60,24 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
5760
return nil, err
5861
}
5962

60-
privateKeySigner, err := signer.NewPrivateKeySigner(ecdsaConfig.PrivateKey, baseConfig.ChainId)
63+
privateKeyWallet, err := wallet.NewPrivateKeyWallet(&baseConfig.EthRpcClient, ecdsaConfig.SignerFn, ecdsaConfig.Address, baseConfig.Logger)
6164
if err != nil {
62-
baseConfig.Logger.Error("Cannot create signer", "err", err)
65+
baseConfig.Logger.Error("Cannot create private key wallet", "err", err)
6366
return nil, err
6467
}
6568

69+
txManager := txmgr.NewSimpleTxManager(privateKeyWallet, &baseConfig.EthRpcClient, baseConfig.Logger, ecdsaConfig.Address)
70+
71+
txManagerFallback := txmgr.NewSimpleTxManager(privateKeyWallet, &baseConfig.EthRpcClientFallback, baseConfig.Logger, ecdsaConfig.Address)
72+
6673
chainWriter := clients.AvsRegistryChainWriter
6774

6875
return &AvsWriter{
6976
ChainWriter: chainWriter,
7077
AvsContractBindings: avsServiceBindings,
7178
logger: baseConfig.Logger,
72-
Signer: privateKeySigner,
79+
TxManager: *txManager,
80+
TxManagerFallback: *txManagerFallback,
7381
Client: baseConfig.EthRpcClient,
7482
ClientFallback: baseConfig.EthRpcClientFallback,
7583
metrics: metrics,
@@ -90,12 +98,14 @@ func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
9098
// without an error (returning `nil, nil`).
9199
// - An error if the process encounters a fatal issue (e.g., permanent failure in verifying balances or state).
92100
func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature, gasBumpPercentage uint, gasBumpIncrementalPercentage uint, gasBumpPercentageLimit uint, timeToWaitBeforeBump time.Duration, metrics *metrics.Metrics, onSetGasPrice func(*big.Int)) (*types.Receipt, error) {
93-
txOpts := *w.Signer.GetTxOpts()
101+
txOpts, err := w.TxManager.GetNoSendTxOpts()
94102
txOpts.NoSend = true // simulate the transaction
95-
simTx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature, retry.SendToChainRetryParams())
103+
simTx, err := w.RespondToTaskV2Retryable(txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature, retry.SendToChainRetryParams())
96104
if err != nil {
105+
w.logger.Errorf("Failed to simulate transaction: %v", err)
97106
return nil, err
98107
}
108+
w.logger.Infof("Simulated transaction: %v", simTx.Hash().Hex())
99109

100110
// Set the nonce, as we might have to replace the transaction with a higher gas price
101111
txNonce := big.NewInt(int64(simTx.Nonce()))
@@ -168,22 +178,23 @@ func (w *AvsWriter) SendAggregatedResponse(batchIdentifierHash [32]byte, batchMe
168178

169179
// We compare both Aggregator funds and Batcher balance in Aligned against respondToTaskFeeLimit
170180
// Both are required to have some balance, more details inside the function
171-
err = w.checkAggAndBatcherHaveEnoughBalance(simTx, txOpts, batchIdentifierHash, senderAddress)
181+
err = w.checkAggAndBatcherHaveEnoughBalance(simTx, *txOpts, batchIdentifierHash, senderAddress)
172182
if err != nil {
173183
w.logger.Errorf("Permanent error when checking aggregator and batcher balances, err %v", err, "merkle root", batchMerkleRootHashString)
174184
return nil, retry.PermanentError{Inner: err}
175185
}
176186

177187
w.logger.Infof("Sending RespondToTask transaction with a gas price of %v", txOpts.GasPrice, "merkle root", batchMerkleRootHashString)
178-
realTx, err := w.RespondToTaskV2Retryable(&txOpts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature, retry.SendToChainRetryParams())
188+
//realTx, err := w.RespondToTaskV2Retryable(txOpts, batchMerkleRoot, senderAddress, quorumNums, nonSignerStakesAndSignature, retry.SendToChainRetryParams())
189+
receipt, err := w.SendTransactionRetryable(context.Background(), simTx, false, retry.SendToChainRetryParams())
179190
if err != nil {
180191
w.logger.Errorf("Respond to task transaction err, %v", err, "merkle root", batchMerkleRootHashString)
181192
return nil, err
182193
}
183-
sentTxs = append(sentTxs, realTx)
194+
sentTxs = append(sentTxs, simTx)
184195

185196
w.logger.Infof("Transaction sent, waiting for receipt", "merkle root", batchMerkleRootHashString)
186-
receipt, err := utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, realTx.Hash(), retry.WaitForTxRetryParams(timeToWaitBeforeBump))
197+
receipt, err = utils.WaitForTransactionReceiptRetryable(w.Client, w.ClientFallback, receipt.TxHash, retry.WaitForTxRetryParams(timeToWaitBeforeBump))
187198
if receipt != nil {
188199
w.updateAggregatorGasCostMetrics(receipt, batchIdentifierHash)
189200
return receipt, nil

core/chainio/retryable.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ import (
1515

1616
// |---AVS_WRITER---|
1717

18+
func (w *AvsWriter) SendTransactionRetryable(ctx context.Context, tx *types.Transaction, waitForReceipt bool, config *retry.RetryParams) (*types.Receipt, error) {
19+
sendTransaction_func := func() (*types.Receipt, error) {
20+
// Try with main txManager
21+
receipt, err := w.TxManager.Send(ctx, tx, waitForReceipt)
22+
if err != nil {
23+
// If error try with fallback txManager
24+
receipt, err = w.TxManagerFallback.Send(ctx, tx, waitForReceipt)
25+
}
26+
return receipt, err
27+
}
28+
return retry.RetryWithData(sendTransaction_func, config)
29+
}
30+
1831
/*
1932
RespondToTaskV2Retryable
2033
Send a transaction to the AVS contract to respond to a task.

core/config/ecdsa.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ package config
33
import (
44
"crypto/ecdsa"
55
"errors"
6+
"github.com/ethereum/go-ethereum/common"
67
"log"
78
"math/big"
89
"os"
910

1011
ecdsa2 "github.com/Layr-Labs/eigensdk-go/crypto/ecdsa"
11-
"github.com/Layr-Labs/eigensdk-go/signer"
12+
signer "github.com/Layr-Labs/eigensdk-go/signerv2"
1213
"github.com/yetanotherco/aligned_layer/core/utils"
1314
)
1415

1516
type EcdsaConfig struct {
17+
Address common.Address
1618
PrivateKey *ecdsa.PrivateKey
17-
Signer signer.Signer
19+
SignerFn signer.SignerFn
1820
}
1921

2022
type EcdsaConfigFromYaml struct {
@@ -44,13 +46,17 @@ func NewEcdsaConfig(ecdsaConfigFilePath string, chainId *big.Int) *EcdsaConfig {
4446
log.Fatal("Error reading ecdsa private key from file: ", err)
4547
}
4648

47-
privateKeySigner, err := signer.NewPrivateKeySigner(ecdsaKeyPair, chainId)
49+
signerConfig := signer.Config{
50+
PrivateKey: ecdsaKeyPair,
51+
}
52+
signerFn, address, err := signer.SignerFromConfig(signerConfig, chainId)
4853
if err != nil {
49-
log.Fatal("Error creating private key signer: ", err)
54+
log.Fatal("Cannot create signer", "err", err)
5055
}
5156

5257
return &EcdsaConfig{
58+
Address: address,
5359
PrivateKey: ecdsaKeyPair,
54-
Signer: privateKeySigner,
60+
SignerFn: signerFn,
5561
}
5662
}

go.mod

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@ module github.com/yetanotherco/aligned_layer
33
go 1.22.2
44

55
require (
6-
github.com/Layr-Labs/eigensdk-go v0.2.0-beta.1
7-
github.com/ethereum/go-ethereum v1.14.0
8-
github.com/prometheus/client_golang v1.19.1
6+
github.com/Layr-Labs/eigensdk-go v0.3.0
7+
github.com/ethereum/go-ethereum v1.15.0
8+
github.com/prometheus/client_golang v1.20.5
99
github.com/urfave/cli/v2 v2.27.5
10-
golang.org/x/crypto v0.22.0
10+
golang.org/x/crypto v0.32.0
1111
)
1212

1313
require (
1414
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6
1515
github.com/cenkalti/backoff/v4 v4.3.0
16-
github.com/consensys/gnark v0.10.0
17-
github.com/consensys/gnark-crypto v0.12.2-0.20240215234832-d72fcb379d3e
16+
github.com/consensys/gnark v0.12.0
17+
github.com/consensys/gnark-crypto v0.16.0
1818
github.com/fxamacker/cbor/v2 v2.7.0
1919
github.com/ugorji/go/codec v1.2.12
2020
gopkg.in/yaml.v3 v3.0.1
2121
)
2222

2323
require (
24+
dario.cat/mergo v1.0.0 // indirect
25+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
2426
github.com/DataDog/zstd v1.5.2 // indirect
2527
github.com/Microsoft/go-winio v0.6.2 // indirect
2628
github.com/StackExchange/wmi v1.2.1 // indirect
@@ -39,55 +41,90 @@ require (
3941
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
4042
github.com/aws/smithy-go v1.20.2 // indirect
4143
github.com/beorn7/perks v1.0.1 // indirect
42-
github.com/bits-and-blooms/bitset v1.10.0 // indirect
44+
github.com/bits-and-blooms/bitset v1.20.0 // indirect
4345
github.com/blang/semver/v4 v4.0.0 // indirect
44-
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
4546
github.com/cespare/xxhash/v2 v2.3.0 // indirect
46-
github.com/consensys/bavard v0.1.13 // indirect
47+
github.com/consensys/bavard v0.1.27 // indirect
48+
github.com/containerd/containerd v1.7.18 // indirect
49+
github.com/containerd/log v0.1.0 // indirect
50+
github.com/containerd/platforms v0.2.1 // indirect
51+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
4752
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
48-
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
53+
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
54+
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
4955
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5056
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
5157
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
58+
github.com/distribution/reference v0.6.0 // indirect
59+
github.com/docker/docker v27.1.1+incompatible // indirect
60+
github.com/docker/go-connections v0.5.0 // indirect
61+
github.com/docker/go-units v0.5.0 // indirect
5262
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
63+
github.com/ethereum/go-verkle v0.2.2 // indirect
64+
github.com/felixge/httpsnoop v1.0.4 // indirect
5365
github.com/fsnotify/fsnotify v1.7.0 // indirect
66+
github.com/go-logr/logr v1.4.1 // indirect
67+
github.com/go-logr/stdr v1.2.2 // indirect
5468
github.com/go-ole/go-ole v1.3.0 // indirect
69+
github.com/gogo/protobuf v1.3.2 // indirect
5570
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
56-
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
71+
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
5772
github.com/google/uuid v1.6.0 // indirect
5873
github.com/gorilla/websocket v1.5.1 // indirect
59-
github.com/holiman/uint256 v1.2.4 // indirect
60-
github.com/ingonyama-zk/icicle v0.0.0-20230928131117-97f0079e5c71 // indirect
61-
github.com/ingonyama-zk/iciclegnark v0.1.0 // indirect
62-
github.com/klauspost/compress v1.17.7 // indirect
74+
github.com/holiman/uint256 v1.3.2 // indirect
75+
github.com/ingonyama-zk/icicle/v3 v3.1.1-0.20241118092657-fccdb2f0921b // indirect
76+
github.com/klauspost/compress v1.17.9 // indirect
6377
github.com/lmittmann/tint v1.0.4 // indirect
78+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
79+
github.com/magiconair/properties v1.8.7 // indirect
6480
github.com/mattn/go-colorable v0.1.13 // indirect
6581
github.com/mattn/go-isatty v0.0.20 // indirect
6682
github.com/mitchellh/mapstructure v1.5.0 // indirect
6783
github.com/mmcloughlin/addchain v0.4.0 // indirect
84+
github.com/moby/docker-image-spec v1.3.1 // indirect
85+
github.com/moby/patternmatcher v0.6.0 // indirect
86+
github.com/moby/sys/sequential v0.5.0 // indirect
87+
github.com/moby/sys/user v0.1.0 // indirect
88+
github.com/moby/term v0.5.0 // indirect
89+
github.com/morikuni/aec v1.0.0 // indirect
90+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
91+
github.com/opencontainers/go-digest v1.0.0 // indirect
92+
github.com/opencontainers/image-spec v1.1.0 // indirect
93+
github.com/pkg/errors v0.9.1 // indirect
6894
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
95+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
6996
github.com/prometheus/client_model v0.6.1 // indirect
70-
github.com/prometheus/common v0.52.2 // indirect
71-
github.com/prometheus/procfs v0.13.0 // indirect
97+
github.com/prometheus/common v0.55.0 // indirect
98+
github.com/prometheus/procfs v0.15.1 // indirect
7299
github.com/rivo/uniseg v0.4.4 // indirect
100+
github.com/ronanh/intcomp v1.1.0 // indirect
73101
github.com/rs/cors v1.8.3 // indirect
74-
github.com/rs/zerolog v1.32.0 // indirect
102+
github.com/rs/zerolog v1.33.0 // indirect
75103
github.com/russross/blackfriday/v2 v2.1.0 // indirect
76104
github.com/shirou/gopsutil v3.21.6+incompatible // indirect
105+
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
106+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
77107
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
78-
github.com/stretchr/testify v1.9.0 // indirect
79-
github.com/supranational/blst v0.3.11 // indirect
108+
github.com/sirupsen/logrus v1.9.3 // indirect
109+
github.com/stretchr/testify v1.10.0 // indirect
110+
github.com/supranational/blst v0.3.13 // indirect
80111
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
112+
github.com/testcontainers/testcontainers-go v0.35.0 // indirect
81113
github.com/tklauser/go-sysconf v0.3.12 // indirect
82114
github.com/tklauser/numcpus v0.6.1 // indirect
83115
github.com/x448/float16 v0.8.4 // indirect
84116
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
117+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
118+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
119+
go.opentelemetry.io/otel v1.24.0 // indirect
120+
go.opentelemetry.io/otel/metric v1.24.0 // indirect
121+
go.opentelemetry.io/otel/trace v1.24.0 // indirect
85122
go.uber.org/multierr v1.11.0 // indirect
86123
go.uber.org/zap v1.27.0 // indirect
87-
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
88-
golang.org/x/net v0.24.0 // indirect
89-
golang.org/x/sync v0.7.0 // indirect
90-
golang.org/x/sys v0.19.0 // indirect
124+
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect
125+
golang.org/x/net v0.34.0 // indirect
126+
golang.org/x/sync v0.10.0 // indirect
127+
golang.org/x/sys v0.29.0 // indirect
91128
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect
92129
google.golang.org/protobuf v1.34.2 // indirect
93130
rsc.io/tmplfunc v0.0.3 // indirect

0 commit comments

Comments
 (0)