Skip to content

Commit

Permalink
Update eigen-sdk to 0.1.4 (#110)
Browse files Browse the repository at this point in the history
* chore: Update eigen-sdk to 0.1.4

* feat: Set gas limit multipliers to 1.5

* refactor: Fix packages imported more than once

* fix: Remove unnecessary gas limit multiplier
  • Loading branch information
Hyodar authored Apr 29, 2024
1 parent 26b29af commit 42dd24b
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 410 deletions.
21 changes: 10 additions & 11 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"sync"
"time"

"github.com/Layr-Labs/eigensdk-go/chainio/clients"
sdkclients "github.com/Layr-Labs/eigensdk-go/chainio/clients"
eigenclients "github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
Expand All @@ -17,7 +16,7 @@ import (
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"
oppubkeysserv "github.com/Layr-Labs/eigensdk-go/services/operatorpubkeys"
"github.com/Layr-Labs/eigensdk-go/signerv2"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
eigentypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/prometheus/client_golang/prometheus"

"github.com/NethermindEth/near-sffl/aggregator/database"
Expand Down Expand Up @@ -93,7 +92,7 @@ type Aggregator struct {
operatorSetUpdateBlsAggregationService MessageBlsAggregationService
tasks map[coretypes.TaskIndex]taskmanager.CheckpointTask
tasksLock sync.RWMutex
taskResponses map[coretypes.TaskIndex]map[sdktypes.TaskResponseDigest]messages.CheckpointTaskResponse
taskResponses map[coretypes.TaskIndex]map[eigentypes.TaskResponseDigest]messages.CheckpointTaskResponse
taskResponsesLock sync.RWMutex
msgDb database.Databaser
stateRootUpdates map[coretypes.MessageDigest]messages.StateRootUpdateMessage
Expand All @@ -108,15 +107,15 @@ var _ core.Metricable = (*Aggregator)(nil)
// TODO: Remove this context once OperatorPubkeysServiceInMemory's API is
// changed and we can gracefully exit otherwise
func NewAggregator(ctx context.Context, config *config.Config, logger logging.Logger) (*Aggregator, error) {
chainioConfig := sdkclients.BuildAllConfig{
chainioConfig := eigenclients.BuildAllConfig{
EthHttpUrl: config.EthHttpRpcUrl,
EthWsUrl: config.EthWsRpcUrl,
RegistryCoordinatorAddr: config.SFFLRegistryCoordinatorAddr.String(),
OperatorStateRetrieverAddr: config.OperatorStateRetrieverAddr.String(),
AvsName: avsName,
PromMetricsIpPortAddress: config.MetricsIpPortAddress,
}
clients, err := clients.BuildAll(chainioConfig, config.EcdsaPrivateKey, logger)
clients, err := eigenclients.BuildAll(chainioConfig, config.EcdsaPrivateKey, logger)
if err != nil {
logger.Errorf("Cannot create sdk clients", "err", err)
return nil, err
Expand Down Expand Up @@ -171,7 +170,7 @@ func NewAggregator(ctx context.Context, config *config.Config, logger logging.Lo
return nil, err
}

txMgr := txmgr.NewSimpleTxManager(txSender, ethHttpClient, logger, signerV2, config.AggregatorAddress)
txMgr := txmgr.NewSimpleTxManager(txSender, ethHttpClient, logger, config.AggregatorAddress).WithGasLimitMultiplier(1.5)

avsWriter, err := chainio.BuildAvsWriterFromConfig(txMgr, config, ethHttpClient, logger)
if err != nil {
Expand Down Expand Up @@ -217,7 +216,7 @@ func NewAggregator(ctx context.Context, config *config.Config, logger logging.Lo
operatorSetUpdateBlsAggregationService: operatorSetUpdateBlsAggregationService,
msgDb: msgDb,
tasks: make(map[coretypes.TaskIndex]taskmanager.CheckpointTask),
taskResponses: make(map[coretypes.TaskIndex]map[sdktypes.TaskResponseDigest]messages.CheckpointTaskResponse),
taskResponses: make(map[coretypes.TaskIndex]map[eigentypes.TaskResponseDigest]messages.CheckpointTaskResponse),
stateRootUpdates: make(map[coretypes.MessageDigest]messages.StateRootUpdateMessage),
operatorSetUpdates: make(map[coretypes.MessageDigest]messages.OperatorSetUpdateMessage),
restListener: &SelectiveRestListener{},
Expand Down Expand Up @@ -378,14 +377,14 @@ func (agg *Aggregator) sendNewCheckpointTask() error {
agg.tasks[taskIndex] = newTask
agg.tasksLock.Unlock()

quorumThresholds := make([]uint32, len(newTask.QuorumNumbers))
quorumThresholds := make([]eigentypes.QuorumThresholdPercentage, len(newTask.QuorumNumbers))
for i, _ := range newTask.QuorumNumbers {
quorumThresholds[i] = newTask.QuorumThreshold
quorumThresholds[i] = eigentypes.QuorumThresholdPercentage(newTask.QuorumThreshold)
}
// TODO(samlaf): we use seconds for now, but we should ideally pass a blocknumber to the blsAggregationService
// and it should monitor the chain and only expire the task aggregation once the chain has reached that block number.
taskTimeToExpiry := taskChallengeWindowBlock * blockTimeSeconds
agg.taskBlsAggregationService.InitializeNewTask(taskIndex, newTask.TaskCreatedBlock, newTask.QuorumNumbers, quorumThresholds, taskTimeToExpiry)
agg.taskBlsAggregationService.InitializeNewTask(taskIndex, newTask.TaskCreatedBlock, core.ConvertBytesToQuorumNumbers(newTask.QuorumNumbers), quorumThresholds, taskTimeToExpiry)
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
blsaggservmock "github.com/Layr-Labs/eigensdk-go/services/mocks/blsagg"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
eigentypes "github.com/Layr-Labs/eigensdk-go/types"
gethtypes "github.com/ethereum/go-ethereum/core/types"

dbmocks "github.com/NethermindEth/near-sffl/aggregator/database/mocks"
Expand All @@ -32,9 +32,9 @@ var MOCK_OPERATOR_BLS_PRIVATE_KEY, _ = bls.NewPrivateKey(MOCK_OPERATOR_BLS_PRIVA
var MOCK_OPERATOR_KEYPAIR = bls.NewKeyPair(MOCK_OPERATOR_BLS_PRIVATE_KEY)
var MOCK_OPERATOR_G1PUBKEY = MOCK_OPERATOR_KEYPAIR.GetPubKeyG1()
var MOCK_OPERATOR_G2PUBKEY = MOCK_OPERATOR_KEYPAIR.GetPubKeyG2()
var MOCK_OPERATOR_PUBKEY_DICT = map[bls.OperatorId]types.OperatorInfo{
var MOCK_OPERATOR_PUBKEY_DICT = map[eigentypes.OperatorId]types.OperatorInfo{
MOCK_OPERATOR_ID: {
OperatorPubkeys: sdktypes.OperatorPubkeys{
OperatorPubkeys: eigentypes.OperatorPubkeys{
G1Pubkey: MOCK_OPERATOR_G1PUBKEY,
G2Pubkey: MOCK_OPERATOR_G2PUBKEY,
},
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestSendNewTask(t *testing.T) {
// make sure that initializeNewTask was called on the blsAggService
// maybe there's a better way to do this? There's a saying "don't mock 3rd party code"
// see https://hynek.me/articles/what-to-mock-in-5-mins/
mockTaskBlsAggService.EXPECT().InitializeNewTask(TASK_INDEX, BLOCK_NUMBER, coretypes.QUORUM_NUMBERS, []uint32{types.QUORUM_THRESHOLD_NUMERATOR}, taskTimeToExpiry)
mockTaskBlsAggService.EXPECT().InitializeNewTask(TASK_INDEX, BLOCK_NUMBER, coretypes.QUORUM_NUMBERS, []eigentypes.QuorumThresholdPercentage{types.QUORUM_THRESHOLD_NUMERATOR}, taskTimeToExpiry)

err = aggregator.sendNewCheckpointTask()
assert.Nil(t, err)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestHandleOperatorSetUpdateAggregationReachedQuorum(t *testing.T) {
}

func createMockAggregator(
mockCtrl *gomock.Controller, operatorPubkeyDict map[bls.OperatorId]types.OperatorInfo,
mockCtrl *gomock.Controller, operatorPubkeyDict map[eigentypes.OperatorId]types.OperatorInfo,
) (*Aggregator, *chainiomocks.MockAvsReaderer, *chainiomocks.MockAvsWriterer, *blsaggservmock.MockBlsAggregationService, *aggmocks.MockMessageBlsAggregationService, *aggmocks.MockMessageBlsAggregationService, *dbmocks.MockDatabaser, *aggmocks.MockRollupBroadcasterer, *aggmocks.MockClient, error) {
logger := sdklogging.NewNoopLogger()
mockAvsWriter := chainiomocks.NewMockAvsWriterer(mockCtrl)
Expand All @@ -169,7 +169,7 @@ func createMockAggregator(
operatorSetUpdateBlsAggregationService: mockOperatorSetUpdateBlsAggregationService,
msgDb: mockMsgDb,
tasks: make(map[coretypes.TaskIndex]taskmanager.CheckpointTask),
taskResponses: make(map[coretypes.TaskIndex]map[sdktypes.TaskResponseDigest]messages.CheckpointTaskResponse),
taskResponses: make(map[coretypes.TaskIndex]map[eigentypes.TaskResponseDigest]messages.CheckpointTaskResponse),
stateRootUpdates: make(map[coretypes.MessageDigest]messages.StateRootUpdateMessage),
operatorSetUpdates: make(map[coretypes.MessageDigest]messages.OperatorSetUpdateMessage),
rollupBroadcaster: mockRollupBroadcaster,
Expand Down
60 changes: 30 additions & 30 deletions aggregator/message_blsagg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/services/avsregistry"
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"
eigensdktypes "github.com/Layr-Labs/eigensdk-go/types"
eigentypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"

"github.com/NethermindEth/near-sffl/aggregator/types"
Expand All @@ -31,7 +31,7 @@ var (
MessageNotFoundErrorFn = func(messageDigest coretypes.MessageDigest) error {
return fmt.Errorf("message %x not initialized or already completed", messageDigest)
}
OperatorNotPartOfMessageQuorumErrorFn = func(operatorId eigensdktypes.OperatorId, messageDigest coretypes.MessageDigest) error {
OperatorNotPartOfMessageQuorumErrorFn = func(operatorId eigentypes.OperatorId, messageDigest coretypes.MessageDigest) error {
return fmt.Errorf("operator %x not part of message %x's quorum", operatorId, messageDigest)
}
SignatureVerificationError = func(err error) error {
Expand All @@ -43,33 +43,33 @@ var (
type AggregatedOperators struct {
signersApkG2 *bls.G2Point
signersAggSigG1 *bls.Signature
signersTotalStakePerQuorum map[eigensdktypes.QuorumNum]*big.Int
signersOperatorIdsSet map[eigensdktypes.OperatorId]bool
signersTotalStakePerQuorum map[eigentypes.QuorumNum]*big.Int
signersOperatorIdsSet map[eigentypes.OperatorId]bool
}

type SignedMessageDigest struct {
MessageDigest coretypes.MessageDigest
BlsSignature *bls.Signature
OperatorId bls.OperatorId
OperatorId eigentypes.OperatorId
SignatureVerificationErrorC chan error
}

type signedMessageDigestValidationInfo struct {
operatorsAvsStateDict map[[32]byte]eigensdktypes.OperatorAvsState
quorumsAvsStakeDict map[uint8]eigensdktypes.QuorumAvsState
totalStakePerQuorum map[uint8]*big.Int
operatorsAvsStateDict map[eigentypes.OperatorId]eigentypes.OperatorAvsState
quorumsAvsStakeDict map[eigentypes.QuorumNum]eigentypes.QuorumAvsState
totalStakePerQuorum map[eigentypes.QuorumNum]*big.Int
quorumApksG1 []*bls.G1Point
aggregatedOperatorsDict map[eigensdktypes.TaskResponseDigest]AggregatedOperators
quorumThresholdPercentagesMap map[uint8]uint32
quorumNumbers []eigensdktypes.QuorumNum
aggregatedOperatorsDict map[eigentypes.TaskResponseDigest]AggregatedOperators
quorumThresholdPercentagesMap map[eigentypes.QuorumNum]eigentypes.QuorumThresholdPercentage
quorumNumbers []eigentypes.QuorumNum
ethBlockNumber uint64
}

type MessageBlsAggregationService interface {
InitializeMessageIfNotExists(
messageDigest coretypes.MessageDigest,
quorumNumbers []eigensdktypes.QuorumNum,
quorumThresholdPercentages []eigensdktypes.QuorumThresholdPercentage,
quorumNumbers []eigentypes.QuorumNum,
quorumThresholdPercentages []eigentypes.QuorumThresholdPercentage,
timeToExpiry time.Duration,
ethBlockNumber uint64,
) error
Expand All @@ -78,7 +78,7 @@ type MessageBlsAggregationService interface {
ctx context.Context,
messageDigest coretypes.MessageDigest,
blsSignature *bls.Signature,
operatorId bls.OperatorId,
operatorId eigentypes.OperatorId,
) error

GetResponseChannel() <-chan types.MessageBlsAggregationServiceResponse
Expand Down Expand Up @@ -112,8 +112,8 @@ func (mbas *MessageBlsAggregatorService) GetResponseChannel() <-chan types.Messa

func (mbas *MessageBlsAggregatorService) InitializeMessageIfNotExists(
messageDigest coretypes.MessageDigest,
quorumNumbers []eigensdktypes.QuorumNum,
quorumThresholdPercentages []eigensdktypes.QuorumThresholdPercentage,
quorumNumbers []eigentypes.QuorumNum,
quorumThresholdPercentages []eigentypes.QuorumThresholdPercentage,
timeToExpiry time.Duration,
ethBlockNumber uint64,
) error {
Expand All @@ -135,7 +135,7 @@ func (mbas *MessageBlsAggregatorService) ProcessNewSignature(
ctx context.Context,
messageDigest coretypes.MessageDigest,
blsSignature *bls.Signature,
operatorId bls.OperatorId,
operatorId eigentypes.OperatorId,
) error {
mbas.messageChansLock.RLock()
messageC, taskInitialized := mbas.signedMessageDigestsCs[messageDigest]
Expand All @@ -161,8 +161,8 @@ func (mbas *MessageBlsAggregatorService) ProcessNewSignature(

func (mbas *MessageBlsAggregatorService) singleMessageAggregatorGoroutineFunc(
messageDigest coretypes.MessageDigest,
quorumNumbers []eigensdktypes.QuorumNum,
quorumThresholdPercentages []eigensdktypes.QuorumThresholdPercentage,
quorumNumbers []eigentypes.QuorumNum,
quorumThresholdPercentages []eigentypes.QuorumThresholdPercentage,
timeToExpiry time.Duration,
signedMessageDigestsC <-chan SignedMessageDigest,
ethBlockNumber uint64,
Expand All @@ -189,7 +189,7 @@ func (mbas *MessageBlsAggregatorService) singleMessageAggregatorGoroutineFunc(
}
}

func (mbas *MessageBlsAggregatorService) fetchValidationInfo(quorumNumbers []eigensdktypes.QuorumNum, quorumThresholdPercentages []eigensdktypes.QuorumThresholdPercentage, ethBlockNumber uint64) signedMessageDigestValidationInfo {
func (mbas *MessageBlsAggregatorService) fetchValidationInfo(quorumNumbers []eigentypes.QuorumNum, quorumThresholdPercentages []eigentypes.QuorumThresholdPercentage, ethBlockNumber uint64) signedMessageDigestValidationInfo {
if ethBlockNumber == 0 {
curEthBlockNumber, err := mbas.ethClient.BlockNumber(context.Background())
if err != nil {
Expand All @@ -210,7 +210,7 @@ func (mbas *MessageBlsAggregatorService) fetchValidationInfo(quorumNumbers []eig
mbas.logger.Fatal("Aggregator failed to get quorums state from avs registry", "err", err)
}

totalStakePerQuorum := make(map[eigensdktypes.QuorumNum]*big.Int)
totalStakePerQuorum := make(map[eigentypes.QuorumNum]*big.Int)
for quorumNum, quorumAvsState := range quorumsAvsStakeDict {
totalStakePerQuorum[quorumNum] = quorumAvsState.TotalStake
}
Expand All @@ -220,7 +220,7 @@ func (mbas *MessageBlsAggregatorService) fetchValidationInfo(quorumNumbers []eig
quorumApksG1 = append(quorumApksG1, quorumsAvsStakeDict[quorumNumber].AggPubkeyG1)
}

quorumThresholdPercentagesMap := make(map[eigensdktypes.QuorumNum]eigensdktypes.QuorumThresholdPercentage)
quorumThresholdPercentagesMap := make(map[eigentypes.QuorumNum]eigentypes.QuorumThresholdPercentage)
for i, quorumNumber := range quorumNumbers {
quorumThresholdPercentagesMap[quorumNumber] = quorumThresholdPercentages[i]
}
Expand All @@ -230,7 +230,7 @@ func (mbas *MessageBlsAggregatorService) fetchValidationInfo(quorumNumbers []eig
quorumsAvsStakeDict: quorumsAvsStakeDict,
totalStakePerQuorum: totalStakePerQuorum,
quorumApksG1: quorumApksG1,
aggregatedOperatorsDict: make(map[eigensdktypes.TaskResponseDigest]AggregatedOperators),
aggregatedOperatorsDict: make(map[eigentypes.TaskResponseDigest]AggregatedOperators),
quorumThresholdPercentagesMap: quorumThresholdPercentagesMap,
quorumNumbers: quorumNumbers,
ethBlockNumber: ethBlockNumber,
Expand All @@ -251,7 +251,7 @@ func (mbas *MessageBlsAggregatorService) handleSignedMessageDigest(signedMessage
// we've already verified that the operator is part of the task's quorum, so we don't need checks here
signersApkG2: bls.NewZeroG2Point().Add(validationInfo.operatorsAvsStateDict[signedMessageDigest.OperatorId].Pubkeys.G2Pubkey),
signersAggSigG1: signedMessageDigest.BlsSignature,
signersOperatorIdsSet: map[eigensdktypes.OperatorId]bool{signedMessageDigest.OperatorId: true},
signersOperatorIdsSet: map[eigentypes.OperatorId]bool{signedMessageDigest.OperatorId: true},
signersTotalStakePerQuorum: validationInfo.operatorsAvsStateDict[signedMessageDigest.OperatorId].StakePerQuorum,
}
} else {
Expand All @@ -273,7 +273,7 @@ func (mbas *MessageBlsAggregatorService) handleSignedMessageDigest(signedMessage
return false
}

nonSignersOperatorIds := []eigensdktypes.OperatorId{}
nonSignersOperatorIds := []eigentypes.OperatorId{}
for operatorId := range validationInfo.operatorsAvsStateDict {
if _, operatorSigned := digestAggregatedOperators.signersOperatorIdsSet[operatorId]; !operatorSigned {
nonSignersOperatorIds = append(nonSignersOperatorIds, operatorId)
Expand Down Expand Up @@ -329,7 +329,7 @@ func (mbas *MessageBlsAggregatorService) closeMessageGoroutine(messageDigest cor

func (mbas *MessageBlsAggregatorService) verifySignature(
signedMessageDigest SignedMessageDigest,
operatorsAvsStateDict map[eigensdktypes.OperatorId]eigensdktypes.OperatorAvsState,
operatorsAvsStateDict map[eigentypes.OperatorId]eigentypes.OperatorAvsState,
) error {
_, ok := operatorsAvsStateDict[signedMessageDigest.OperatorId]
if !ok {
Expand Down Expand Up @@ -360,9 +360,9 @@ func (mbas *MessageBlsAggregatorService) verifySignature(
}

func checkIfStakeThresholdsMet(
signedStakePerQuorum map[eigensdktypes.QuorumNum]*big.Int,
totalStakePerQuorum map[eigensdktypes.QuorumNum]*big.Int,
quorumThresholdPercentagesMap map[eigensdktypes.QuorumNum]eigensdktypes.QuorumThresholdPercentage,
signedStakePerQuorum map[eigentypes.QuorumNum]*big.Int,
totalStakePerQuorum map[eigentypes.QuorumNum]*big.Int,
quorumThresholdPercentagesMap map[eigentypes.QuorumNum]eigentypes.QuorumThresholdPercentage,
) bool {
for quorumNum, quorumThresholdPercentage := range quorumThresholdPercentagesMap {
signedStake := big.NewInt(0).Mul(signedStakePerQuorum[quorumNum], big.NewInt(100))
Expand All @@ -374,7 +374,7 @@ func checkIfStakeThresholdsMet(
return true
}

func getG1PubkeysOfNonSigners(signersOperatorIdsSet map[eigensdktypes.OperatorId]bool, operatorAvsStateDict map[[32]byte]eigensdktypes.OperatorAvsState) []*bls.G1Point {
func getG1PubkeysOfNonSigners(signersOperatorIdsSet map[eigentypes.OperatorId]bool, operatorAvsStateDict map[eigentypes.OperatorId]eigentypes.OperatorAvsState) []*bls.G1Point {
nonSignersG1Pubkeys := []*bls.G1Point{}
for operatorId, operator := range operatorAvsStateDict {
if _, operatorSigned := signersOperatorIdsSet[operatorId]; !operatorSigned {
Expand Down
4 changes: 2 additions & 2 deletions aggregator/mocks/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func MockSendNewCheckpointTask(blockNum, taskNum uint32, fromTimestamp, toTimest
FromTimestamp: fromTimestamp,
ToTimestamp: toTimestamp,
TaskCreatedBlock: blockNum,
QuorumNumbers: coretypes.QUORUM_NUMBERS,
QuorumThreshold: types.QUORUM_THRESHOLD_NUMERATOR,
QuorumNumbers: coretypes.QUORUM_NUMBERS_BYTES,
QuorumThreshold: uint32(types.QUORUM_THRESHOLD_NUMERATOR),
}

return task, taskNum, nil
Expand Down
Loading

0 comments on commit 42dd24b

Please sign in to comment.