Skip to content

Commit

Permalink
fix some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Oct 24, 2024
1 parent 8c3649c commit b39619c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 40 deletions.
4 changes: 2 additions & 2 deletions precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ address constant AVSMANAGER_PRECOMPILE_ADDRESS = 0x00000000000000000000000000000
IAVSManager constant AVSMANAGER_CONTRACT = IAVSManager(
AVSMANAGER_PRECOMPILE_ADDRESS
);

/// @author Exocore Team
/// @title AVS-Manager Precompile Contract
/// @dev The interface through which solidity contracts will interact with AVS-Manager
Expand All @@ -28,6 +27,7 @@ interface IAVSManager {
event TaskSubmittedByOperator(address indexed sender, uint64 taskID, string taskResponse,
string blsSignature, string taskContractAddress, string stage, bool success);

enum SubmissionStage { Stage1, Stage2 }

/// @dev Register AVS contract to EXO.
/// @param sender The external address for calling this method.
Expand Down Expand Up @@ -173,7 +173,7 @@ interface IAVSManager {
bytes calldata taskResponse,
bytes calldata blsSignature,
address taskContractAddress,
string memory stage
SubmissionStage stage
) external returns (bool success);

/// QUERIES
Expand Down
1 change: 1 addition & 0 deletions precompiles/avs/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetOperatorOptedUSDValue() {
func (suite *AVSManagerPrecompileSuite) TestGetRegisteredPubkey() {
method := suite.precompile.Methods[avsManagerPrecompile.MethodGetRegisteredPubkey]
privateKey, err := blst.RandKey()
suite.NoError(err)
operatorAddr := "exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr"

publicKey := privateKey.PublicKey()
Expand Down
15 changes: 12 additions & 3 deletions precompiles/avs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (p Precompile) RegisterBLSPublicKey(

pubkeyBz, ok := args[2].([]byte)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 3, "[]byte", pubkeyBz)
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 2, "[]byte", pubkeyBz)
}
blsParams.PubKey = pubkeyBz

Expand Down Expand Up @@ -350,7 +350,7 @@ func (p Precompile) OperatorSubmitTask(

taskID, ok := args[1].(uint64)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "uint64", taskID)
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "uint64", args[1])
}
resultParams.TaskID = taskID

Expand Down Expand Up @@ -379,7 +379,16 @@ func (p Precompile) OperatorSubmitTask(
resultParams.Stage = stage

resultParams.OperatorAddress = resultParams.CallerAddress
err := p.avsKeeper.SubmitTaskResult(ctx, resultParams)

result := &avstypes.TaskResultInfo{
TaskId: resultParams.TaskID,
OperatorAddress: resultParams.OperatorAddress,
TaskContractAddress: resultParams.TaskContractAddress.String(),
TaskResponse: resultParams.TaskResponse,
BlsSignature: resultParams.BlsSignature,
Stage: resultParams.Stage,
}
err := p.avsKeeper.SetTaskResultInfo(ctx, resultParams.OperatorAddress, result)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (p Precompile) GetAVSParamsFromUpdateInputs(_ sdk.Context, args []interface

func (p Precompile) GetTaskParamsFromInputs(_ sdk.Context, args []interface{}) (*avstypes.TaskInfoParams, error) {
if len(args) != len(p.ABI.Methods[MethodCreateAVSTask].Inputs) {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 3, len(args))
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, len(p.ABI.Methods[MethodCreateAVSTask].Inputs), len(args))
}
taskParams := &avstypes.TaskInfoParams{}
callerAddress, ok := args[0].(common.Address)
Expand Down
20 changes: 5 additions & 15 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ func (k Keeper) CreateAVSTask(ctx sdk.Context, params *types.TaskInfoParams) (ui
return 0, errorsmod.Wrap(types.ErrCallerAddressUnauthorized, fmt.Sprintf("this caller not qualified to CreateAVSTask %s", params.CallerAddress))
}
taskPowerTotal, err := k.operatorKeeper.GetAVSUSDValue(ctx, avsInfo.AvsAddress)

if err != nil || taskPowerTotal.IsZero() || taskPowerTotal.IsNegative() {
return 0, errorsmod.Wrap(types.ErrVotingPowerIncorrect, fmt.Sprintf("the votingpower of avs is <<=0,avs addr is:%s", avsInfo.AvsAddress))
if err != nil {
return 0, errorsmod.Wrap(err, "failed to get AVS USD value")
}
if taskPowerTotal.IsZero() || taskPowerTotal.IsNegative() {
return 0, errorsmod.Wrap(types.ErrVotingPowerIncorrect, fmt.Sprintf("the voting power of AVS is zero or negative, AVS address: %s", avsInfo.AvsAddress))
}

epoch, found := k.epochsKeeper.GetEpochInfo(ctx, avsInfo.EpochIdentifier)
Expand Down Expand Up @@ -445,15 +447,3 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *types.Challeng
return k.SetTaskChallengedInfo(ctx, params.TaskID, params.OperatorAddress.String(), params.CallerAddress,
params.TaskContractAddress)
}

func (k Keeper) SubmitTaskResult(ctx sdk.Context, params *types.TaskResultParams) error {
result := &types.TaskResultInfo{
TaskId: params.TaskID,
OperatorAddress: params.OperatorAddress,
TaskContractAddress: params.TaskContractAddress.String(),
TaskResponse: params.TaskResponse,
BlsSignature: params.BlsSignature,
Stage: params.Stage,
}
return k.SetTaskResultInfo(ctx, params.OperatorAddress, result)
}
4 changes: 2 additions & 2 deletions x/avs/keeper/multi_operator_submit_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseOne_Mul() {
TaskResponseHash: "",
TaskResponse: nil,
BlsSignature: sig.Marshal(),
Stage: avstypes.TwoPhaseCommitOne,
Stage: avstypes.TwoPhaseCommitOne.String(),
}
err := suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, operatorAddress, info)
suite.Require().NoError(err)
Expand Down Expand Up @@ -229,7 +229,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseTwo_Mul() {
TaskResponseHash: hash.String(),
TaskResponse: jsonData,
BlsSignature: sig.Marshal(),
Stage: avstypes.TwoPhaseCommitTwo,
Stage: avstypes.TwoPhaseCommitTwo.String(),
}
err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, operatorAddress, info)
suite.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions x/avs/keeper/submit_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseOne() {
TaskResponseHash: "",
TaskResponse: nil,
BlsSignature: sig.Marshal(),
Stage: avstypes.TwoPhaseCommitOne,
Stage: avstypes.TwoPhaseCommitOne.String(),
}
err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, suite.operatorAddr.String(), info)
suite.NoError(err)
Expand Down Expand Up @@ -216,7 +216,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseTwo() {
TaskResponseHash: hash.String(),
TaskResponse: jsonData,
BlsSignature: sig.Marshal(),
Stage: avstypes.TwoPhaseCommitTwo,
Stage: avstypes.TwoPhaseCommitTwo.String(),
}
err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, suite.operatorAddr.String(), info)
suite.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions x/avs/keeper/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (k *Keeper) SetTaskResultInfo(
}

switch info.Stage {
case types.TwoPhaseCommitOne:
case types.TwoPhaseCommitOne.String():
if k.IsExistTaskResultInfo(ctx, info.OperatorAddress, info.TaskContractAddress, info.TaskId) {
return errorsmod.Wrap(
types.ErrResAlreadyExists,
Expand Down Expand Up @@ -221,7 +221,7 @@ func (k *Keeper) SetTaskResultInfo(
store.Set(infoKey, bz)
return nil

case types.TwoPhaseCommitTwo:
case types.TwoPhaseCommitTwo.String():
// check task response
if info.TaskResponse == nil {
return errorsmod.Wrap(
Expand Down
34 changes: 21 additions & 13 deletions x/avs/types/stage.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package types

import (
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
)

type CommitStage int

const (
// TwoPhaseCommitOne The first stage of the two-stage submission.
TwoPhaseCommitOne = "1"
TwoPhaseCommitOne CommitStage = iota
// TwoPhaseCommitTwo The second stage of submission.
TwoPhaseCommitTwo = "2"
TwoPhaseCommitTwo
)

func (s CommitStage) String() string {
return strconv.Itoa(int(s))
}

type OperatorOptParams struct {
Name string
BlsPublicKey string
IsRegistered bool
Action uint64
OperatorAddress string
Status string
AvsAddress string
Name string `json:"name"`
BlsPublicKey string `json:"bls_public_key"`
IsRegistered bool `json:"is_registered"`
Action uint64 `json:"action"`
OperatorAddress string `json:"operator_address"`
Status string `json:"status"`
AvsAddress string `json:"avs_address"`
}

type TaskInfoParams struct {
Expand Down Expand Up @@ -93,8 +101,8 @@ type TaskResultParams struct {
}

type OperatorParams struct {
EarningsAddr string `json:"earnings_addr"`
ApproveAddr string `json:"approve_addr"`
OperatorMetaInfo string `json:"operator_meta_info"`
CallerAddress string `json:"caller_address"`
EarningsAddr string `json:"earnings_addr"`
ApproveAddr string `json:"approve_addr"`
OperatorMetaInfo string `json:"operator_meta_info"`
CallerAddress sdk.AccAddress `json:"caller_address"`
}

0 comments on commit b39619c

Please sign in to comment.