Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry support for the SDK #384

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/telemetry"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/Layr-Labs/eigensdk-go/utils"
)
Expand Down Expand Up @@ -50,6 +51,7 @@ func NewChainReader(
ethClient eth.HttpBackend,
) *ChainReader {
logger = logger.With(logging.ComponentKey, "avsregistry/ChainReader")
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.newchainreader")

return &ChainReader{
blsApkRegistryAddr: blsApkRegistryAddr,
Expand All @@ -68,6 +70,8 @@ func NewReaderFromConfig(
client eth.HttpBackend,
logger logging.Logger,
) (*ChainReader, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.newreaderfromconfig")

bindings, err := NewBindingsFromConfig(cfg, client, logger)
if err != nil {
return nil, err
Expand All @@ -92,6 +96,8 @@ func BuildAvsRegistryChainReader(
ethClient eth.HttpBackend,
logger logging.Logger,
) (*ChainReader, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.buildavsregistrychainreader")

contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
if err != nil {
return nil, utils.WrapError("Failed to create contractRegistryCoordinator", err)
Expand Down Expand Up @@ -127,6 +133,8 @@ func BuildAvsRegistryChainReader(
}

func (r *ChainReader) GetQuorumCount(opts *bind.CallOpts) (uint8, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getquorumcount")

if r.registryCoordinator == nil {
return 0, errors.New("RegistryCoordinator contract not provided")
}
Expand All @@ -137,6 +145,8 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]opstateretriever.OperatorStateRetrieverOperator, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsatcurrentblock")

if opts.Context == nil {
opts.Context = context.Background()
}
Expand All @@ -157,6 +167,8 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsAtBlock(
quorumNumbers types.QuorumNums,
blockNumber uint32,
) ([][]opstateretriever.OperatorStateRetrieverOperator, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsatblock")

if r.operatorStateRetriever == nil {
return nil, errors.New("OperatorStateRetriever contract not provided")
}
Expand All @@ -176,6 +188,8 @@ func (r *ChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(
opts *bind.CallOpts,
quorumNumbers types.QuorumNums,
) ([][]common.Address, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatoraddrsinquorumsatcurrentblock")

if r.operatorStateRetriever == nil {
return nil, errors.New("OperatorStateRetriever contract not provided")
}
Expand Down Expand Up @@ -216,6 +230,8 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
operatorId types.OperatorId,
blockNumber uint32,
) (types.QuorumNums, [][]opstateretriever.OperatorStateRetrieverOperator, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsofoperatoratblock")

if r.operatorStateRetriever == nil {
return nil, nil, errors.New("OperatorStateRetriever contract not provided")
}
Expand All @@ -238,6 +254,9 @@ func (r *ChainReader) GetOperatorsStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
) (types.QuorumNums, [][]opstateretriever.OperatorStateRetrieverOperator, error) {
_ = telemetry.GetTelemetry().
CaptureEvent("avsregistry.chainreader.getoperatorsstakeinquorumsofoperatoratcurrentblock")

if opts.Context == nil {
opts.Context = context.Background()
}
Expand All @@ -261,6 +280,9 @@ func (r *ChainReader) GetOperatorStakeInQuorumsOfOperatorAtCurrentBlock(
opts *bind.CallOpts,
operatorId types.OperatorId,
) (map[types.QuorumNum]types.StakeAmount, error) {
_ = telemetry.GetTelemetry().
CaptureEvent("avsregistry.chainreader.getoperatorstakeinquorumsofoperatoratcurrentblock")

if r.registryCoordinator == nil {
return nil, errors.New("RegistryCoordinator contract not provided")
}
Expand Down Expand Up @@ -309,6 +331,8 @@ func (r *ChainReader) GetCheckSignaturesIndices(
quorumNumbers types.QuorumNums,
nonSignerOperatorIds []types.OperatorId,
) (opstateretriever.OperatorStateRetrieverCheckSignaturesIndices, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getchecksignaturesindices")

if r.operatorStateRetriever == nil {
return opstateretriever.OperatorStateRetrieverCheckSignaturesIndices{}, errors.New(
"OperatorStateRetriever contract not provided",
Expand Down Expand Up @@ -339,6 +363,8 @@ func (r *ChainReader) GetOperatorId(
opts *bind.CallOpts,
operatorAddress common.Address,
) ([32]byte, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorid")

if r.registryCoordinator == nil {
return [32]byte{}, errors.New("RegistryCoordinator contract not provided")
}
Expand All @@ -357,6 +383,8 @@ func (r *ChainReader) GetOperatorFromId(
opts *bind.CallOpts,
operatorId types.OperatorId,
) (common.Address, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.getoperatorfromid")

if r.registryCoordinator == nil {
return common.Address{}, errors.New("RegistryCoordinator contract not provided")
}
Expand All @@ -375,6 +403,8 @@ func (r *ChainReader) QueryRegistrationDetail(
opts *bind.CallOpts,
operatorAddress common.Address,
) ([]bool, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.queryregistrationdetail")

operatorId, err := r.GetOperatorId(opts, operatorAddress)
if err != nil {
return nil, utils.WrapError("Failed to get operator id", err)
Expand Down Expand Up @@ -404,6 +434,8 @@ func (r *ChainReader) IsOperatorRegistered(
opts *bind.CallOpts,
operatorAddress common.Address,
) (bool, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.isoperatorregistered")

if r.registryCoordinator == nil {
return false, errors.New("RegistryCoordinator contract not provided")
}
Expand All @@ -424,6 +456,8 @@ func (r *ChainReader) QueryExistingRegisteredOperatorPubKeys(
stopBlock *big.Int,
blockRange *big.Int,
) ([]types.OperatorAddr, []types.OperatorPubkeys, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.queryexistingregisteredoperatorpubkeys")

blsApkRegistryAbi, err := apkreg.ContractBLSApkRegistryMetaData.GetAbi()
if err != nil {
return nil, nil, utils.WrapError("Cannot get Abi", err)
Expand Down Expand Up @@ -523,6 +557,8 @@ func (r *ChainReader) QueryExistingRegisteredOperatorSockets(
stopBlock *big.Int,
blockRange *big.Int,
) (map[types.OperatorId]types.Socket, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainreader.queryexistingregisteredoperatorpubkeys")

if r.registryCoordinator == nil {
return nil, errors.New("RegistryCoordinator contract not provided")
}
Expand Down
11 changes: 11 additions & 0 deletions chainio/clients/avsregistry/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
blsapkreg "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSApkRegistry"
regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/telemetry"
"github.com/Layr-Labs/eigensdk-go/utils"
)

Expand All @@ -25,6 +26,8 @@ func NewChainSubscriber(
blsApkRegistry blsapkreg.ContractBLSApkRegistryFilters,
logger logging.Logger,
) *ChainSubscriber {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.newchainsubscriber")

logger = logger.With(logging.ComponentKey, "avsregistry/ChainSubscriber")

return &ChainSubscriber{
Expand All @@ -41,6 +44,8 @@ func BuildAvsRegistryChainSubscriber(
ethWsClient eth.WsBackend,
logger logging.Logger,
) (*ChainSubscriber, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.newchainsubscriber")

regCoord, err := regcoord.NewContractRegistryCoordinator(regCoordAddr, ethWsClient)
if err != nil {
return nil, utils.WrapError("Failed to create RegistryCoordinator contract", err)
Expand All @@ -63,6 +68,8 @@ func NewSubscriberFromConfig(
wsClient eth.WsBackend,
logger logging.Logger,
) (*ChainSubscriber, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.newsubscriberFromConfig")

bindings, err := NewBindingsFromConfig(cfg, wsClient, logger)
if err != nil {
return nil, err
Expand All @@ -72,6 +79,8 @@ func NewSubscriberFromConfig(
}

func (s *ChainSubscriber) SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration, event.Subscription, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.subscribetonewpubkeyregistrations")

newPubkeyRegistrationChan := make(chan *blsapkreg.ContractBLSApkRegistryNewPubkeyRegistration)
sub, err := s.blsApkRegistry.WatchNewPubkeyRegistration(
&bind.WatchOpts{}, newPubkeyRegistrationChan, nil,
Expand All @@ -83,6 +92,8 @@ func (s *ChainSubscriber) SubscribeToNewPubkeyRegistrations() (chan *blsapkreg.C
}

func (s *ChainSubscriber) SubscribeToOperatorSocketUpdates() (chan *regcoord.ContractRegistryCoordinatorOperatorSocketUpdate, event.Subscription, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.subscriber.subscribetooperatorsocketupdates")

operatorSocketUpdateChan := make(chan *regcoord.ContractRegistryCoordinatorOperatorSocketUpdate)
sub, err := s.regCoord.WatchOperatorSocketUpdate(
&bind.WatchOpts{}, operatorSocketUpdateChan, nil,
Expand Down
20 changes: 20 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/telemetry"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/Layr-Labs/eigensdk-go/utils"
)
Expand Down Expand Up @@ -60,6 +61,8 @@ func NewChainWriter(
ethClient eth.HttpBackend,
txMgr txmgr.TxManager,
) *ChainWriter {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.newchainwriter")

logger = logger.With(logging.ComponentKey, "avsregistry/ChainWriter")

return &ChainWriter{
Expand All @@ -84,6 +87,8 @@ func BuildAvsRegistryChainWriter(
ethClient eth.HttpBackend,
txMgr txmgr.TxManager,
) (*ChainWriter, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.buildavsregistrychainwriter")

registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
if err != nil {
return nil, utils.WrapError("Failed to create RegistryCoordinator contract", err)
Expand Down Expand Up @@ -151,6 +156,8 @@ func NewWriterFromConfig(
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ChainWriter, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.newwriterfromconfig")

bindings, err := NewBindingsFromConfig(cfg, client, logger)
if err != nil {
return nil, err
Expand Down Expand Up @@ -203,6 +210,9 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator(
socket string,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
_ = telemetry.GetTelemetry().
CaptureEvent("avsregistry.chainwriter.registeroperatorinquorumwithavsregistrycoordinator")

operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey)
w.logger.Info(
"registering operator with the AVS's registry coordinator",
Expand Down Expand Up @@ -305,6 +315,8 @@ func (w *ChainWriter) RegisterOperator(
socket string,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.registeroperator")

operatorAddr := crypto.PubkeyToAddress(operatorEcdsaPrivateKey.PublicKey)
w.logger.Info(
"registering operator with the AVS's registry coordinator",
Expand Down Expand Up @@ -423,6 +435,8 @@ func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums(
quorumNumbers types.QuorumNums,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.updatestakesofentireoperatorsetforquorums")

w.logger.Info("updating stakes for entire operator set", "quorumNumbers", quorumNumbers)
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
Expand Down Expand Up @@ -456,6 +470,8 @@ func (w *ChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums(
operators []gethcommon.Address,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.updatestakesofoperatorsubsetforallquorums")

w.logger.Info("updating stakes of operator subset for all quorums", "operators", operators)
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
Expand Down Expand Up @@ -485,6 +501,8 @@ func (w *ChainWriter) DeregisterOperator(
pubkey regcoord.BN254G1Point,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.deregisteroperator")

w.logger.Info("deregistering operator with the AVS's registry coordinator")
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
Expand All @@ -511,6 +529,8 @@ func (w *ChainWriter) UpdateSocket(
socket types.Socket,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
_ = telemetry.GetTelemetry().CaptureEvent("avsregistry.chainwriter.updatesocket")

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions chainio/clients/elcontracts/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/metrics"
"github.com/Layr-Labs/eigensdk-go/telemetry"
)

// Returns a tuple of reader clients with the given:
Expand All @@ -15,6 +16,8 @@ func BuildReadClients(
logger logging.Logger,
eigenMetrics *metrics.EigenMetrics,
) (*ChainReader, *ContractBindings, error) {
_ = telemetry.GetTelemetry().CaptureEvent("elcontracts.builder.buildreadclients")

elContractBindings, err := NewBindingsFromConfig(
config,
client,
Expand Down Expand Up @@ -44,6 +47,8 @@ func BuildClients(
logger logging.Logger,
eigenMetrics *metrics.EigenMetrics,
) (*ChainReader, *ChainWriter, *ContractBindings, error) {
_ = telemetry.GetTelemetry().CaptureEvent("elcontracts.builder.buildclients")

elContractBindings, err := NewBindingsFromConfig(
config,
client,
Expand Down
Loading