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

added error logs for avs reader/writer clients #115

Merged
merged 3 commits into from
Feb 14, 2024
Merged
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
71 changes: 24 additions & 47 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package avsregistry
import (
"bytes"
"context"
"errors"
"math"
"math/big"

Expand Down Expand Up @@ -119,26 +120,26 @@ func BuildAvsRegistryChainReader(
) (*AvsRegistryChainReader, error) {
contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create contractRegistryCoordinator"), err)
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved
}
blsApkRegistryAddr, err := contractRegistryCoordinator.BlsApkRegistry(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get blsApkRegistryAddr"), err)
}
stakeRegistryAddr, err := contractRegistryCoordinator.StakeRegistry(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get stakeRegistryAddr"), err)
}
contractStakeRegistry, err := stakeregistry.NewContractStakeRegistry(stakeRegistryAddr, ethClient)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create contractStakeRegistry"), err)
}
contractOperatorStateRetriever, err := contractOperatorStateRetriever.NewContractOperatorStateRetriever(
operatorStateRetrieverAddr,
ethClient,
)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create contractOperatorStateRetriever"), err)
}
return NewAvsRegistryChainReader(
registryCoordinatorAddr,
Expand All @@ -164,12 +165,10 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsAtCurrentBlock(
}
curBlock, err := r.ethClient.BlockNumber(opts.Context)
if err != nil {
r.logger.Error("Failed to get current block number", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Cannot get current block number"), err)
}
if curBlock > math.MaxUint32 {
r.logger.Error("Current block number is too large to be converted to uint32")
return nil, err
return nil, types.WrapError(errors.New("Current block number is too large to be converted to uint32"), err)
}
return r.GetOperatorsStakeInQuorumsAtBlock(opts, quorumNumbers, uint32(curBlock))
}
Expand All @@ -187,8 +186,7 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsAtBlock(
quorumNumbers,
blockNumber)
if err != nil {
r.logger.Error("Failed to get operators state", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Failed to get operators state"), err)
}
return operatorStakes, nil
}
Expand All @@ -202,12 +200,10 @@ func (r *AvsRegistryChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(
}
curBlock, err := r.ethClient.BlockNumber(opts.Context)
if err != nil {
r.logger.Error("Failed to get current block number", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Failed to get current block number"), err)
}
if curBlock > math.MaxUint32 {
r.logger.Error("Current block number is too large to be converted to uint32")
return nil, err
return nil, types.WrapError(errors.New("Current block number is too large to be converted to uint32"), err)
}
operatorStakes, err := r.operatorStateRetriever.GetOperatorState(
opts,
Expand All @@ -216,8 +212,7 @@ func (r *AvsRegistryChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(
uint32(curBlock),
)
if err != nil {
r.logger.Error("Failed to get operators state", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Failed to get operators state"), err)
}
var quorumOperatorAddrs [][]common.Address
for _, quorum := range operatorStakes {
Expand All @@ -242,14 +237,7 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtBlock(
operatorId,
blockNumber)
if err != nil {
r.logger.Error(
"Failed to get operators state",
"err",
err,
"fn",
"AvsRegistryChainReader.GetOperatorsStakeInQuorumsOfOperatorAtBlock",
)
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Failed to get operators state"), err)
}
quorums := types.BitmapToQuorumIds(quorumBitmap)
return quorums, operatorStakes, nil
Expand All @@ -266,12 +254,10 @@ func (r *AvsRegistryChainReader) GetOperatorsStakeInQuorumsOfOperatorAtCurrentBl
}
curBlock, err := r.ethClient.BlockNumber(opts.Context)
if err != nil {
r.logger.Error("Failed to get current block number", "err", err)
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Failed to get current block number"), err)
}
if curBlock > math.MaxUint32 {
r.logger.Error("Current block number is too large to be converted to uint32")
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Current block number is too large to be converted to uint32"), err)
}
opts.BlockNumber = big.NewInt(int64(curBlock))
return r.GetOperatorsStakeInQuorumsOfOperatorAtBlock(opts, operatorId, uint32(curBlock))
Expand All @@ -286,8 +272,7 @@ func (r *AvsRegistryChainReader) GetOperatorStakeInQuorumsOfOperatorAtCurrentBlo
) (map[types.QuorumNum]types.StakeAmount, error) {
quorumBitmap, err := r.registryCoordinator.GetCurrentQuorumBitmap(opts, operatorId)
if err != nil {
r.logger.Error("Failed to get operator quorums", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Failed to get operator quorums"), err)
}
quorums := types.BitmapToQuorumIds(quorumBitmap)
quorumStakes := make(map[types.QuorumNum]types.StakeAmount)
Expand All @@ -298,8 +283,7 @@ func (r *AvsRegistryChainReader) GetOperatorStakeInQuorumsOfOperatorAtCurrentBlo
quorum,
)
if err != nil {
r.logger.Error("Failed to get operator stake", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Failed to get operator stake"), err)
}
quorumStakes[quorum] = stake
}
Expand All @@ -320,8 +304,7 @@ func (r *AvsRegistryChainReader) GetCheckSignaturesIndices(
nonSignerOperatorIds,
)
if err != nil {
r.logger.Error("Failed to get check signatures indices", "err", err)
return opstateretriever.OperatorStateRetrieverCheckSignaturesIndices{}, err
return opstateretriever.OperatorStateRetrieverCheckSignaturesIndices{}, types.WrapError(errors.New("Failed to get check signatures indices"), err)
}
return checkSignatureIndices, nil
}
Expand All @@ -335,8 +318,7 @@ func (r *AvsRegistryChainReader) GetOperatorId(
operatorAddress,
)
if err != nil {
r.logger.Error("Failed to get operator id", "err", err)
return [32]byte{}, err
return [32]byte{}, types.WrapError(errors.New("Failed to get operator id"), err)
}
return operatorId, nil
}
Expand All @@ -350,8 +332,7 @@ func (r *AvsRegistryChainReader) GetOperatorFromId(
operatorId,
)
if err != nil {
r.logger.Error("Failed to get operator address", "err", err)
return gethcommon.Address{}, err
return gethcommon.Address{}, types.WrapError(errors.New("Failed to get operator address"), err)
}
return operatorAddress, nil
}
Expand All @@ -362,8 +343,7 @@ func (r *AvsRegistryChainReader) IsOperatorRegistered(
) (bool, error) {
operatorStatus, err := r.registryCoordinator.GetOperatorStatus(opts, operatorAddress)
if err != nil {
r.logger.Error("Cannot get operator status", "err", err)
return false, err
return false, types.WrapError(errors.New("Failed to get operator status"), err)
}

// 0 = NEVER_REGISTERED, 1 = REGISTERED, 2 = DEREGISTERED
Expand All @@ -379,8 +359,7 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(

blsApkRegistryAbi, err := abi.JSON(bytes.NewReader(eigenabi.BLSApkRegistryAbi))
if err != nil {
r.logger.Error("Error getting Abi", "err", err)
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Cannot get Abi"), err)
}

query := ethereum.FilterQuery{
Expand All @@ -394,8 +373,7 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(

logs, err := r.ethClient.FilterLogs(ctx, query)
if err != nil {
r.logger.Error("Error filtering logs", "err", err)
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Cannot filter logs"), err)
}
r.logger.Info("avsRegistryChainReader.QueryExistingRegisteredOperatorPubKeys", "transactionLogs", logs)

Expand All @@ -410,8 +388,7 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(

event, err := blsApkRegistryAbi.Unpack("NewPubkeyRegistration", vLog.Data)
if err != nil {
r.logger.Error("Error unpacking event data", "err", err)
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Cannot unpack event data"), err)
}

G1Pubkey := event[0].(struct {
Expand Down
9 changes: 5 additions & 4 deletions chainio/clients/avsregistry/subscriber.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package avsregistry

import (
"errors"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
blsapkreg "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSApkRegistry"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/types"
)

type AvsRegistrySubscriber interface {
Expand Down Expand Up @@ -39,8 +42,7 @@ func BuildAvsRegistryChainSubscriber(
) (*AvsRegistryChainSubscriber, error) {
blsapkreg, err := blsapkreg.NewContractBLSApkRegistry(blsApkRegistryAddr, ethWsClient)
if err != nil {
logger.Error("Failed to create BLSApkRegistry contract", "err", err)
return nil, err
return nil, types.WrapError(errors.New("Failed to create BLSApkRegistry contract"), err)
}
return NewAvsRegistryChainSubscriber(blsapkreg, logger)
}
Expand All @@ -51,8 +53,7 @@ func (s *AvsRegistryChainSubscriber) SubscribeToNewPubkeyRegistrations() (chan *
&bind.WatchOpts{}, newPubkeyRegistrationChan, nil,
)
if err != nil {
s.logger.Error("Failed to subscribe to NewPubkeyRegistration events", "err", err)
return nil, nil, err
return nil, nil, types.WrapError(errors.New("Failed to subscribe to NewPubkeyRegistration events"), err)
}
return newPubkeyRegistrationChan, sub, nil
}
23 changes: 12 additions & 11 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -116,50 +117,50 @@ func BuildAvsRegistryChainWriter(
) (*AvsRegistryChainWriter, error) {
registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create RegistryCoordinator contract"), err)
}
operatorStateRetriever, err := opstateretriever.NewContractOperatorStateRetriever(
operatorStateRetrieverAddr,
ethClient,
)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create OperatorStateRetriever contract"), err)
}
serviceManagerAddr, err := registryCoordinator.ServiceManager(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get ServiceManager address"), err)
}
serviceManager, err := smbase.NewContractServiceManagerBase(serviceManagerAddr, ethClient)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create ServiceManager contract"), err)
}
blsApkRegistryAddr, err := registryCoordinator.BlsApkRegistry(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get BLSApkRegistry address"), err)
}
blsApkRegistry, err := blsapkregistry.NewContractBLSApkRegistry(blsApkRegistryAddr, ethClient)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create BLSApkRegistry contract"), err)
}
stakeRegistryAddr, err := registryCoordinator.StakeRegistry(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get StakeRegistry address"), err)
}
stakeRegistry, err := stakeregistry.NewContractStakeRegistry(stakeRegistryAddr, ethClient)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create StakeRegistry contract"), err)
}
delegationManagerAddr, err := stakeRegistry.Delegation(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get DelegationManager address"), err)
}
avsDirectoryAddr, err := serviceManager.AvsDirectory(&bind.CallOpts{})
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to get AvsDirectory address"), err)
}
elReader, err := elcontracts.BuildELChainReader(delegationManagerAddr, avsDirectoryAddr, ethClient, logger)
if err != nil {
return nil, err
return nil, types.WrapError(errors.New("Failed to create ELChainReader"), err)
}
return NewAvsRegistryChainWriter(
serviceManagerAddr,
Expand Down
Loading
Loading