Skip to content

Commit

Permalink
updated sdk to master head and fixed all resulting bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Apr 26, 2024
1 parent 29cbdbe commit d4dea7b
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 193 deletions.
16 changes: 10 additions & 6 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
sdkclients "github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/services/avsregistry"
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"
oppubkeysserv "github.com/Layr-Labs/eigensdk-go/services/operatorpubkeys"
oprsinfoserv "github.com/Layr-Labs/eigensdk-go/services/operatorsinfo"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/Layr-Labs/incredible-squaring-avs/aggregator/types"
"github.com/Layr-Labs/incredible-squaring-avs/core"
Expand Down Expand Up @@ -99,13 +99,13 @@ func NewAggregator(c *config.Config) (*Aggregator, error) {
AvsName: avsName,
PromMetricsIpPortAddress: ":9090",
}
clients, err := clients.BuildAll(chainioConfig, c.AggregatorAddress, c.SignerFn, c.Logger)
clients, err := clients.BuildAll(chainioConfig, c.EcdsaPrivateKey, c.Logger)
if err != nil {
c.Logger.Errorf("Cannot create sdk clients", "err", err)
return nil, err
}

operatorPubkeysService := oppubkeysserv.NewOperatorPubkeysServiceInMemory(context.Background(), clients.AvsRegistryChainSubscriber, clients.AvsRegistryChainReader, c.Logger)
operatorPubkeysService := oprsinfoserv.NewOperatorsInfoServiceInMemory(context.Background(), clients.AvsRegistryChainSubscriber, clients.AvsRegistryChainReader, c.Logger)
avsRegistryService := avsregistry.NewAvsRegistryServiceChainCaller(avsReader, operatorPubkeysService, c.Logger)
blsAggregationService := blsagg.NewBlsAggregatorService(avsRegistryService, c.Logger)

Expand Down Expand Up @@ -208,13 +208,17 @@ func (agg *Aggregator) sendNewTask(numToSquare *big.Int) error {
agg.tasks[taskIndex] = newTask
agg.tasksMu.Unlock()

quorumThresholdPercentages := make([]uint32, len(newTask.QuorumNumbers))
quorumThresholdPercentages := make(sdktypes.QuorumThresholdPercentages, len(newTask.QuorumNumbers))
for i := range newTask.QuorumNumbers {
quorumThresholdPercentages[i] = newTask.QuorumThresholdPercentage
quorumThresholdPercentages[i] = sdktypes.QuorumThresholdPercentage(newTask.QuorumThresholdPercentage)
}
// 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.blsAggregationService.InitializeNewTask(taskIndex, newTask.TaskCreatedBlock, newTask.QuorumNumbers, quorumThresholdPercentages, taskTimeToExpiry)
var quorumNums sdktypes.QuorumNums
for _, quorumNum := range newTask.QuorumNumbers {
quorumNums = append(quorumNums, sdktypes.QuorumNum(quorumNum))
}
agg.blsAggregationService.InitializeNewTask(taskIndex, newTask.TaskCreatedBlock, quorumNums, quorumThresholdPercentages, taskTimeToExpiry)
return nil
}
6 changes: 3 additions & 3 deletions aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestSendNewTask(t *testing.T) {
MOCK_OPERATOR_G1PUBKEY := MOCK_OPERATOR_KEYPAIR.GetPubKeyG1()
MOCK_OPERATOR_G2PUBKEY := MOCK_OPERATOR_KEYPAIR.GetPubKeyG2()

operatorPubkeyDict := map[bls.OperatorId]types.OperatorInfo{
operatorPubkeyDict := map[sdktypes.OperatorId]types.OperatorInfo{
MOCK_OPERATOR_ID: {
OperatorPubkeys: sdktypes.OperatorPubkeys{
G1Pubkey: MOCK_OPERATOR_G1PUBKEY,
Expand All @@ -70,14 +70,14 @@ 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/
mockBlsAggService.EXPECT().InitializeNewTask(TASK_INDEX, BLOCK_NUMBER, types.QUORUM_NUMBERS, []uint32{types.QUORUM_THRESHOLD_NUMERATOR}, taskTimeToExpiry)
mockBlsAggService.EXPECT().InitializeNewTask(TASK_INDEX, BLOCK_NUMBER, types.QUORUM_NUMBERS, sdktypes.QuorumThresholdPercentages{types.QUORUM_THRESHOLD_NUMERATOR}, taskTimeToExpiry)

err = aggregator.sendNewTask(NUMBER_TO_SQUARE_BIG_INT)
assert.Nil(t, err)
}

func createMockAggregator(
mockCtrl *gomock.Controller, operatorPubkeyDict map[bls.OperatorId]types.OperatorInfo,
mockCtrl *gomock.Controller, operatorPubkeyDict map[sdktypes.OperatorId]types.OperatorInfo,
) (*Aggregator, *chainiomocks.MockAvsWriterer, *blsaggservmock.MockBlsAggregationService, error) {
logger := sdklogging.NewNoopLogger()
mockAvsWriter := chainiomocks.NewMockAvsWriterer(mockCtrl)
Expand Down
4 changes: 2 additions & 2 deletions aggregator/mocks/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func MockSendNewTaskNumberToSquareCall(blockNum, taskNum, numberToSquare uint32)
task := cstaskmanager.IIncredibleSquaringTaskManagerTask{
NumberToBeSquared: big.NewInt(int64(numberToSquare)),
TaskCreatedBlock: blockNum,
QuorumNumbers: types.QUORUM_NUMBERS,
QuorumThresholdPercentage: types.QUORUM_THRESHOLD_NUMERATOR,
QuorumNumbers: types.QUORUM_NUMBERS.UnderlyingType(),
QuorumThresholdPercentage: uint32(types.QUORUM_THRESHOLD_NUMERATOR),
}

return task, taskNum, nil
Expand Down
3 changes: 2 additions & 1 deletion aggregator/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Layr-Labs/incredible-squaring-avs/core"

"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/types"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func (agg *Aggregator) startServer(ctx context.Context) error {
type SignedTaskResponse struct {
TaskResponse cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse
BlsSignature bls.Signature
OperatorId bls.OperatorId
OperatorId types.OperatorId
}

// rpc endpoint which is called by operator
Expand Down
2 changes: 1 addition & 1 deletion aggregator/rpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestProcessSignedTaskResponse(t *testing.T) {
MOCK_OPERATOR_G1PUBKEY := MOCK_OPERATOR_KEYPAIR.GetPubKeyG1()
MOCK_OPERATOR_G2PUBKEY := MOCK_OPERATOR_KEYPAIR.GetPubKeyG2()

operatorPubkeyDict := map[bls.OperatorId]types.OperatorInfo{
operatorPubkeyDict := map[sdktypes.OperatorId]types.OperatorInfo{
MOCK_OPERATOR_ID: {
OperatorPubkeys: sdktypes.OperatorPubkeys{
G1Pubkey: MOCK_OPERATOR_G1PUBKEY,
Expand Down
9 changes: 5 additions & 4 deletions aggregator/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"github.com/ethereum/go-ethereum/common"
)

// TODO: Hardcoded for now
// all operators in quorum0 must sign the task response in order for it to be accepted
const QUORUM_THRESHOLD_NUMERATOR = uint32(100)
const QUORUM_THRESHOLD_DENOMINATOR = uint32(100)
// TODO: our contracts require uint8 but right now sdktypes.QuorumThresholdPercentage is uint8
// prob need to update our inc-sq contracts to use uint8 as well?
const QUORUM_THRESHOLD_NUMERATOR = sdktypes.QuorumThresholdPercentage(100)
const QUORUM_THRESHOLD_DENOMINATOR = sdktypes.QuorumThresholdPercentage(100)

const QUERY_FILTER_FROM_BLOCK = uint64(1)

// we only use a single quorum (quorum 0) for incredible squaring
var QUORUM_NUMBERS = []byte{0}
var QUORUM_NUMBERS = sdktypes.QuorumNums{0}

type BlockNumber = uint32
type TaskIndex = uint32
Expand Down
2 changes: 1 addition & 1 deletion challenger/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type Challenger struct {
logger logging.Logger
ethClient ethclient.EthClient
ethClient ethclient.Client
avsReader chainio.AvsReaderer
avsWriter chainio.AvsWriterer
avsSubscriber chainio.AvsSubscriberer
Expand Down
12 changes: 6 additions & 6 deletions challenger/challenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func TestCallChallengeModule(t *testing.T) {
challenger.tasks[TASK_INDEX] = cstaskmanager.IIncredibleSquaringTaskManagerTask{
NumberToBeSquared: big.NewInt(3),
TaskCreatedBlock: 1000,
QuorumNumbers: aggtypes.QUORUM_NUMBERS,
QuorumThresholdPercentage: aggtypes.QUORUM_THRESHOLD_NUMERATOR,
QuorumNumbers: aggtypes.QUORUM_NUMBERS.UnderlyingType(),
QuorumThresholdPercentage: uint32(aggtypes.QUORUM_THRESHOLD_NUMERATOR),
}

challenger.taskResponses[TASK_INDEX] = chtypes.TaskResponseData{
Expand Down Expand Up @@ -84,8 +84,8 @@ func TestRaiseChallenge(t *testing.T) {
challenger.tasks[TASK_INDEX] = cstaskmanager.IIncredibleSquaringTaskManagerTask{
NumberToBeSquared: big.NewInt(3),
TaskCreatedBlock: 1000,
QuorumNumbers: aggtypes.QUORUM_NUMBERS,
QuorumThresholdPercentage: aggtypes.QUORUM_THRESHOLD_NUMERATOR,
QuorumNumbers: aggtypes.QUORUM_NUMBERS.UnderlyingType(),
QuorumThresholdPercentage: uint32(aggtypes.QUORUM_THRESHOLD_NUMERATOR),
}

challenger.taskResponses[TASK_INDEX] = chtypes.TaskResponseData{
Expand Down Expand Up @@ -124,8 +124,8 @@ func TestProcessTaskResponseLog(t *testing.T) {
challenger.tasks[TASK_INDEX] = cstaskmanager.IIncredibleSquaringTaskManagerTask{
NumberToBeSquared: big.NewInt(3),
TaskCreatedBlock: 1000,
QuorumNumbers: aggtypes.QUORUM_NUMBERS,
QuorumThresholdPercentage: aggtypes.QUORUM_THRESHOLD_NUMERATOR,
QuorumNumbers: aggtypes.QUORUM_NUMBERS.UnderlyingType(),
QuorumThresholdPercentage: uint32(aggtypes.QUORUM_THRESHOLD_NUMERATOR),
}

challenger.taskResponses[TASK_INDEX] = chtypes.TaskResponseData{
Expand Down
2 changes: 1 addition & 1 deletion core/chainio/avs_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ AvsReaderer = (*AvsReader)(nil)
func BuildAvsReaderFromConfig(c *config.Config) (*AvsReader, error) {
return BuildAvsReader(c.IncredibleSquaringRegistryCoordinatorAddr, c.OperatorStateRetrieverAddr, c.EthHttpClient, c.Logger)
}
func BuildAvsReader(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient eth.EthClient, logger logging.Logger) (*AvsReader, error) {
func BuildAvsReader(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient eth.Client, logger logging.Logger) (*AvsReader, error) {
avsManagersBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr, ethHttpClient, logger)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/chainio/avs_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func BuildAvsSubscriberFromConfig(config *config.Config) (*AvsSubscriber, error)
)
}

func BuildAvsSubscriber(registryCoordinatorAddr, blsOperatorStateRetrieverAddr gethcommon.Address, ethclient eth.EthClient, logger sdklogging.Logger) (*AvsSubscriber, error) {
func BuildAvsSubscriber(registryCoordinatorAddr, blsOperatorStateRetrieverAddr gethcommon.Address, ethclient eth.Client, logger sdklogging.Logger) (*AvsSubscriber, error) {
avsContractBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, blsOperatorStateRetrieverAddr, ethclient, logger)
if err != nil {
logger.Errorf("Failed to create contract bindings", "err", err)
Expand Down
13 changes: 7 additions & 6 deletions core/chainio/avs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
logging "github.com/Layr-Labs/eigensdk-go/logging"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"

cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
Expand All @@ -22,8 +23,8 @@ type AvsWriterer interface {
SendNewTaskNumberToSquare(
ctx context.Context,
numToSquare *big.Int,
quorumThresholdPercentage uint32,
quorumNumbers []byte,
quorumThresholdPercentage sdktypes.QuorumThresholdPercentage,
quorumNumbers sdktypes.QuorumNums,
) (cstaskmanager.IIncredibleSquaringTaskManagerTask, uint32, error)
RaiseChallenge(
ctx context.Context,
Expand All @@ -44,7 +45,7 @@ type AvsWriter struct {
AvsContractBindings *AvsManagersBindings
logger logging.Logger
TxMgr txmgr.TxManager
client eth.EthClient
client eth.Client
}

var _ AvsWriterer = (*AvsWriter)(nil)
Expand All @@ -53,7 +54,7 @@ func BuildAvsWriterFromConfig(c *config.Config) (*AvsWriter, error) {
return BuildAvsWriter(c.TxMgr, c.IncredibleSquaringRegistryCoordinatorAddr, c.OperatorStateRetrieverAddr, c.EthHttpClient, c.Logger)
}

func BuildAvsWriter(txMgr txmgr.TxManager, registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient eth.EthClient, logger logging.Logger) (*AvsWriter, error) {
func BuildAvsWriter(txMgr txmgr.TxManager, registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient eth.Client, logger logging.Logger) (*AvsWriter, error) {
avsServiceBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr, ethHttpClient, logger)
if err != nil {
logger.Error("Failed to create contract bindings", "err", err)
Expand All @@ -75,13 +76,13 @@ func NewAvsWriter(avsRegistryWriter avsregistry.AvsRegistryWriter, avsServiceBin
}

// returns the tx receipt, as well as the task index (which it gets from parsing the tx receipt logs)
func (w *AvsWriter) SendNewTaskNumberToSquare(ctx context.Context, numToSquare *big.Int, quorumThresholdPercentage uint32, quorumNumbers []byte) (cstaskmanager.IIncredibleSquaringTaskManagerTask, uint32, error) {
func (w *AvsWriter) SendNewTaskNumberToSquare(ctx context.Context, numToSquare *big.Int, quorumThresholdPercentage sdktypes.QuorumThresholdPercentage, quorumNumbers sdktypes.QuorumNums) (cstaskmanager.IIncredibleSquaringTaskManagerTask, uint32, error) {
txOpts, err := w.TxMgr.GetNoSendTxOpts()
if err != nil {
w.logger.Errorf("Error getting tx opts")
return cstaskmanager.IIncredibleSquaringTaskManagerTask{}, 0, err
}
tx, err := w.AvsContractBindings.TaskManager.CreateNewTask(txOpts, numToSquare, quorumThresholdPercentage, quorumNumbers)
tx, err := w.AvsContractBindings.TaskManager.CreateNewTask(txOpts, numToSquare, uint32(quorumThresholdPercentage), quorumNumbers.UnderlyingType())
if err != nil {
w.logger.Errorf("Error assembling CreateNewTask tx")
return cstaskmanager.IIncredibleSquaringTaskManagerTask{}, 0, err
Expand Down
4 changes: 2 additions & 2 deletions core/chainio/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
type AvsManagersBindings struct {
TaskManager *cstaskmanager.ContractIncredibleSquaringTaskManager
ServiceManager *csservicemanager.ContractIncredibleSquaringServiceManager
ethClient eth.EthClient
ethClient eth.Client
logger logging.Logger
}

func NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethclient eth.EthClient, logger logging.Logger) (*AvsManagersBindings, error) {
func NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethclient eth.Client, logger logging.Logger) (*AvsManagersBindings, error) {
contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethclient)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit d4dea7b

Please sign in to comment.