Skip to content

Commit

Permalink
Merge branch 'dev' into feat-improve-bls-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
taturosati authored Aug 5, 2024
2 parents 29f4d34 + 67787e9 commit 6440d21
Show file tree
Hide file tree
Showing 63 changed files with 5,395 additions and 2,693 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

bindings: ## generates contract bindings
cd contracts && rm -rf bindings/* && ./generate-bindings.sh
cd contracts && rm -rf bindings/* && ./generate-bindings.sh

eigenpod-bindings: ## generates contract bindings for eigenpod
cd chainio/clients/eigenpod && ./generate.sh

mocks: ## generates mocks
go install go.uber.org/mock/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions chainio/clients/avsregistry/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ContractBindings struct {
func NewAVSRegistryContractBindings(
registryCoordinatorAddr gethcommon.Address,
operatorStateRetrieverAddr gethcommon.Address,
ethclient eth.Client,
ethclient eth.HttpBackend,
logger logging.Logger,
) (*ContractBindings, error) {
contractBlsRegistryCoordinator, err := regcoordinator.NewContractRegistryCoordinator(
Expand Down Expand Up @@ -124,7 +124,7 @@ func NewAVSRegistryContractBindings(
// NewBindingsFromConfig creates a new instance of ContractBindings
func NewBindingsFromConfig(
cfg Config,
client eth.Client,
client eth.HttpBackend,
logger logging.Logger,
) (*ContractBindings, error) {
var (
Expand Down
4 changes: 2 additions & 2 deletions chainio/clients/avsregistry/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

func BuildClients(
config Config,
client eth.Client,
wsClient eth.Client,
client eth.HttpBackend,
wsClient eth.WsBackend,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ChainReader, *ChainSubscriber, *ChainWriter, *ContractBindings, error) {
Expand Down
74 changes: 4 additions & 70 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,6 @@ import (
// 10k is an arbitrary choice that should work for most
var DefaultQueryBlockRange = big.NewInt(10_000)

type Reader interface {
GetQuorumCount(opts *bind.CallOpts) (uint8, error)

GetOperatorsStakeInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsAtBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
blockNumber uint32,
) ([][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorAddrsInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]common.Address, error)

GetOperatorsStakeInQuorumsOfOperatorAtBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
blockNumber uint32,
) (types.QuorumNums, [][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
) (types.QuorumNums, [][]opstateretriever.OperatorStateRetrieverOperator, error)

GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
) (map[types.QuorumNum]types.StakeAmount, error)

GetCheckSignaturesIndices(
opts *bind.CallOpts,
referenceBlockNumber uint32,
quorumNumbers types.QuorumNums,
nonSignerOperatorIds []types.OperatorId,
) (opstateretriever.OperatorStateRetrieverCheckSignaturesIndices, error)

GetOperatorId(opts *bind.CallOpts, operatorAddress common.Address) ([32]byte, error)

GetOperatorFromId(opts *bind.CallOpts, operatorId types.OperatorId) (common.Address, error)

IsOperatorRegistered(opts *bind.CallOpts, operatorAddress common.Address) (bool, error)

QueryExistingRegisteredOperatorPubKeys(
ctx context.Context,
startBlock *big.Int,
stopBlock *big.Int,
blockRange *big.Int,
) ([]types.OperatorAddr, []types.OperatorPubkeys, error)

QueryExistingRegisteredOperatorSockets(
ctx context.Context,
startBlock *big.Int,
stopBlock *big.Int,
blockRange *big.Int,
) (map[types.OperatorId]types.Socket, error)
}

type Config struct {
RegistryCoordinatorAddress common.Address
OperatorStateRetrieverAddress common.Address
Expand All @@ -100,20 +37,17 @@ type ChainReader struct {
registryCoordinator *regcoord.ContractRegistryCoordinator
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever
stakeRegistry *stakeregistry.ContractStakeRegistry
ethClient eth.Client
ethClient eth.HttpBackend
}

// forces AvsReader to implement the clients.ReaderInterface interface
var _ Reader = (*ChainReader)(nil)

func NewChainReader(
registryCoordinatorAddr common.Address,
blsApkRegistryAddr common.Address,
registryCoordinator *regcoord.ContractRegistryCoordinator,
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever,
stakeRegistry *stakeregistry.ContractStakeRegistry,
logger logging.Logger,
ethClient eth.Client,
ethClient eth.HttpBackend,
) *ChainReader {
logger = logger.With(logging.ComponentKey, "avsregistry/ChainReader")

Expand All @@ -131,7 +65,7 @@ func NewChainReader(
// NewReaderFromConfig creates a new ChainReader
func NewReaderFromConfig(
cfg Config,
client eth.Client,
client eth.HttpBackend,
logger logging.Logger,
) (*ChainReader, error) {
bindings, err := NewBindingsFromConfig(cfg, client, logger)
Expand All @@ -155,7 +89,7 @@ func NewReaderFromConfig(
func BuildAvsRegistryChainReader(
registryCoordinatorAddr common.Address,
operatorStateRetrieverAddr common.Address,
ethClient eth.Client,
ethClient eth.HttpBackend,
logger logging.Logger,
) (*ChainReader, error) {
contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
Expand Down
12 changes: 2 additions & 10 deletions chainio/clients/avsregistry/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@ import (
"github.com/Layr-Labs/eigensdk-go/utils"
)

type Subscriber interface {
SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration, event.Subscription, error)
SubscribeToOperatorSocketUpdates() (chan *regcoord.ContractRegistryCoordinatorOperatorSocketUpdate, event.Subscription, error)
}

type ChainSubscriber struct {
logger logging.Logger
regCoord regcoord.ContractRegistryCoordinatorFilters
blsApkRegistry blsapkreg.ContractBLSApkRegistryFilters
}

// forces EthSubscriber to implement the chainio.Subscriber interface
var _ Subscriber = (*ChainSubscriber)(nil)

// NewChainSubscriber creates a new instance of ChainSubscriber
// The bindings must be created using websocket ETH Client
func NewChainSubscriber(
Expand All @@ -46,7 +38,7 @@ func NewChainSubscriber(
// Deprecated: Use NewSubscriberFromConfig instead
func BuildAvsRegistryChainSubscriber(
regCoordAddr common.Address,
ethWsClient eth.Client,
ethWsClient eth.WsBackend,
logger logging.Logger,
) (*ChainSubscriber, error) {
regCoord, err := regcoord.NewContractRegistryCoordinator(regCoordAddr, ethWsClient)
Expand All @@ -68,7 +60,7 @@ func BuildAvsRegistryChainSubscriber(
// A websocket ETH Client must be provided
func NewSubscriberFromConfig(
cfg Config,
wsClient eth.Client,
wsClient eth.WsBackend,
logger logging.Logger,
) (*ChainSubscriber, error) {
bindings, err := NewBindingsFromConfig(cfg, wsClient, logger)
Expand Down
96 changes: 31 additions & 65 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,14 @@ import (
"github.com/Layr-Labs/eigensdk-go/utils"
)

type Writer interface {

// RegisterOperatorInQuorumWithAVSRegistryCoordinator
// TODO(samlaf): an operator that is already registered in a quorum can register with another quorum without passing
// signatures perhaps we should add another sdk function for this purpose, that just takes in a quorumNumber and
// socket? RegisterOperatorInQuorumWithAVSRegistryCoordinator is used to register a single operator with the AVS's
// registry coordinator. - operatorEcdsaPrivateKey is the operator's ecdsa private key (used to sign a message to
// register operator in eigenlayer's delegation manager)
// - operatorToAvsRegistrationSigSalt is a random salt used to prevent replay attacks
// - operatorToAvsRegistrationSigExpiry is the expiry time of the signature
//
// Deprecated: use RegisterOperator instead.
// We will only keep high-level functionality such as RegisterOperator, and low level functionality
// such as this function should eventually all be done with bindings directly instead.
RegisterOperatorInQuorumWithAVSRegistryCoordinator(
ctx context.Context,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
type eLReader interface {
CalculateOperatorAVSRegistrationDigestHash(
opts *bind.CallOpts,
operatorAddr gethcommon.Address,
serviceManagerAddr gethcommon.Address,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
blsKeyPair *bls.KeyPair,
quorumNumbers types.QuorumNums,
socket string,
) (*gethtypes.Receipt, error)

// RegisterOperator is similar to RegisterOperatorInQuorumWithAVSRegistryCoordinator but
// generates a random salt and expiry for the signature.
RegisterOperator(
ctx context.Context,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
blsKeyPair *bls.KeyPair,
quorumNumbers types.QuorumNums,
socket string,
) (*gethtypes.Receipt, error)

// UpdateStakesOfEntireOperatorSetForQuorums is used by avs teams running https://github.com/Layr-Labs/avs-sync
// to updates the stake of their entire operator set.
// Because of high gas costs of this operation, it typically needs to be called for every quorum, or perhaps for a
// small grouping of quorums
// (highly dependent on number of operators per quorum)
UpdateStakesOfEntireOperatorSetForQuorums(
ctx context.Context,
operatorsPerQuorum [][]gethcommon.Address,
quorumNumbers types.QuorumNums,
) (*gethtypes.Receipt, error)

// UpdateStakesOfOperatorSubsetForAllQuorums is meant to be used by single operators (or teams of operators,
// possibly running https://github.com/Layr-Labs/avs-sync) to update the stake of their own operator(s). This might
// be needed in the case that they received a lot of new stake delegations, and want this to be reflected
// in the AVS's registry coordinator.
UpdateStakesOfOperatorSubsetForAllQuorums(
ctx context.Context,
operators []gethcommon.Address,
) (*gethtypes.Receipt, error)

DeregisterOperator(
ctx context.Context,
quorumNumbers types.QuorumNums,
pubkey regcoord.BN254G1Point,
) (*gethtypes.Receipt, error)
) ([32]byte, error)
}

type ChainWriter struct {
Expand All @@ -94,23 +43,21 @@ type ChainWriter struct {
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever
stakeRegistry *stakeregistry.ContractStakeRegistry
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry
elReader elcontracts.Reader
elReader eLReader
logger logging.Logger
ethClient eth.Client
ethClient eth.HttpBackend
txMgr txmgr.TxManager
}

var _ Writer = (*ChainWriter)(nil)

func NewChainWriter(
serviceManagerAddr gethcommon.Address,
registryCoordinator *regcoord.ContractRegistryCoordinator,
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever,
stakeRegistry *stakeregistry.ContractStakeRegistry,
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry,
elReader elcontracts.Reader,
elReader eLReader,
logger logging.Logger,
ethClient eth.Client,
ethClient eth.HttpBackend,
txMgr txmgr.TxManager,
) *ChainWriter {
logger = logger.With(logging.ComponentKey, "avsregistry/ChainWriter")
Expand All @@ -134,7 +81,7 @@ func BuildAvsRegistryChainWriter(
registryCoordinatorAddr gethcommon.Address,
operatorStateRetrieverAddr gethcommon.Address,
logger logging.Logger,
ethClient eth.Client,
ethClient eth.HttpBackend,
txMgr txmgr.TxManager,
) (*ChainWriter, error) {
registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
Expand Down Expand Up @@ -200,7 +147,7 @@ func BuildAvsRegistryChainWriter(
// NewWriterFromConfig creates a new ChainWriter from the provided config
func NewWriterFromConfig(
cfg Config,
client eth.Client,
client eth.HttpBackend,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ChainWriter, error) {
Expand Down Expand Up @@ -229,6 +176,18 @@ func NewWriterFromConfig(
), nil
}

// RegisterOperatorInQuorumWithAVSRegistryCoordinator
// TODO(samlaf): an operator that is already registered in a quorum can register with another quorum without passing
// signatures perhaps we should add another sdk function for this purpose, that just takes in a quorumNumber and
// socket? RegisterOperatorInQuorumWithAVSRegistryCoordinator is used to register a single operator with the AVS's
// registry coordinator. - operatorEcdsaPrivateKey is the operator's ecdsa private key (used to sign a message to
// register operator in eigenlayer's delegation manager)
// - operatorToAvsRegistrationSigSalt is a random salt used to prevent replay attacks
// - operatorToAvsRegistrationSigExpiry is the expiry time of the signature
//
// Deprecated: use RegisterOperator instead.
// We will only keep high-level functionality such as RegisterOperator, and low level functionality
// such as this function should eventually all be done with bindings directly instead.
func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
ctx context.Context,
// we need to pass the private key explicitly and can't use the signer because registering requires signing a
Expand Down Expand Up @@ -330,6 +289,8 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
return receipt, nil
}

// RegisterOperator is similar to RegisterOperatorInQuorumWithAVSRegistryCoordinator but
// generates a random salt and expiry for the signature.
func (w *ChainWriter) RegisterOperator(
ctx context.Context,
// we need to pass the private key explicitly and can't use the signer because registering requires signing a
Expand Down Expand Up @@ -447,6 +408,11 @@ func (w *ChainWriter) RegisterOperator(
return receipt, nil
}

// UpdateStakesOfEntireOperatorSetForQuorums is used by avs teams running https://github.com/Layr-Labs/avs-sync
// to updates the stake of their entire operator set.
// Because of high gas costs of this operation, it typically needs to be called for every quorum, or perhaps for a
// small grouping of quorums
// (highly dependent on number of operators per quorum)
func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
ctx context.Context,
operatorsPerQuorum [][]gethcommon.Address,
Expand Down
10 changes: 6 additions & 4 deletions chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"crypto/ecdsa"
"time"

"github.com/ethereum/go-ethereum/ethclient"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
Expand Down Expand Up @@ -39,8 +41,8 @@ type Clients struct {
AvsRegistryChainWriter *avsregistry.ChainWriter
ElChainReader *elcontracts.ChainReader
ElChainWriter *elcontracts.ChainWriter
EthHttpClient eth.Client
EthWsClient eth.Client
EthHttpClient eth.HttpBackend
EthWsClient eth.WsBackend
Wallet wallet.Wallet
TxManager txmgr.TxManager
AvsRegistryContractBindings *avsregistry.ContractBindings
Expand All @@ -61,12 +63,12 @@ func BuildAll(
eigenMetrics := metrics.NewEigenMetrics(config.AvsName, config.PromMetricsIpPortAddress, promReg, logger)

// creating two types of Eth clients: HTTP and WS
ethHttpClient, err := eth.NewClient(config.EthHttpUrl)
ethHttpClient, err := ethclient.Dial(config.EthHttpUrl)
if err != nil {
return nil, utils.WrapError("Failed to create Eth Http client", err)
}

ethWsClient, err := eth.NewClient(config.EthWsUrl)
ethWsClient, err := ethclient.Dial(config.EthWsUrl)
if err != nil {
return nil, utils.WrapError("Failed to create Eth WS client", err)
}
Expand Down
Loading

0 comments on commit 6440d21

Please sign in to comment.