Skip to content

Commit

Permalink
fix:fix some error of github action
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Apr 11, 2024
1 parent 85151f0 commit 20c766c
Show file tree
Hide file tree
Showing 38 changed files with 296 additions and 1,031 deletions.
23 changes: 12 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/ExocoreNetwork/exocore/x/avs_task"
taskKeeper "github.com/ExocoreNetwork/exocore/x/avs_task/keeper"
taskTypes "github.com/ExocoreNetwork/exocore/x/avs_task/types"
"io"
"net/http"
"os"
"path/filepath"
"sort"

"github.com/ExocoreNetwork/exocore/x/avstask"
avsTaskKeeper "github.com/ExocoreNetwork/exocore/x/avstask/keeper"
avsTaskTypes "github.com/ExocoreNetwork/exocore/x/avstask/types"

"github.com/ExocoreNetwork/exocore/x/avs"
"github.com/ExocoreNetwork/exocore/x/operator"
operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper"
Expand Down Expand Up @@ -277,7 +278,7 @@ var (
reward.AppModuleBasic{},
exoslash.AppModuleBasic{},
avs.AppModuleBasic{},
avs_task.AppModuleBasic{},
avstask.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -362,7 +363,7 @@ type ExocoreApp struct {
OperatorKeeper operatorKeeper.Keeper
ExoSlashKeeper slashKeeper.Keeper
AVSManagerKeeper avsManagerKeeper.Keeper
TaskKeeper taskKeeper.Keeper
TaskKeeper avsTaskKeeper.Keeper
// the module manager
mm *module.Manager

Expand Down Expand Up @@ -446,7 +447,7 @@ func NewExocoreApp(
exoslashTypes.StoreKey,
operatorTypes.StoreKey,
avsManagerTypes.StoreKey,
taskTypes.StoreKey,
avsTaskTypes.StoreKey,
)

// Add the EVM transient store key
Expand Down Expand Up @@ -664,7 +665,7 @@ func NewExocoreApp(
app.RewardKeeper = *rewardKeeper.NewKeeper(appCodec, keys[rewardTypes.StoreKey], app.AssetsKeeper)
app.ExoSlashKeeper = slashKeeper.NewKeeper(appCodec, keys[exoslashTypes.StoreKey], app.AssetsKeeper)
app.AVSManagerKeeper = *avsManagerKeeper.NewKeeper(appCodec, keys[avsManagerTypes.StoreKey], &app.OperatorKeeper, app.AssetsKeeper)
app.TaskKeeper = taskKeeper.NewKeeper(appCodec, keys[taskTypes.StoreKey], taskTypes.AvsKeeperMock{})
app.TaskKeeper = avsTaskKeeper.NewKeeper(appCodec, keys[avsTaskTypes.StoreKey], app.AVSManagerKeeper)
// We call this after setting the hooks to ensure that the hooks are set on the keeper
evmKeeper.WithPrecompiles(
evmkeeper.AvailablePrecompiles(
Expand Down Expand Up @@ -853,7 +854,7 @@ func NewExocoreApp(
reward.NewAppModule(appCodec, app.RewardKeeper),
exoslash.NewAppModule(appCodec, app.ExoSlashKeeper),
avs.NewAppModule(appCodec, app.AVSManagerKeeper),
avs_task.NewAppModule(appCodec, app.TaskKeeper),
avstask.NewAppModule(appCodec, app.TaskKeeper),
)

// During begin block slashing happens after reward.BeginBlocker so that
Expand Down Expand Up @@ -898,7 +899,7 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
taskTypes.ModuleName,
avsTaskTypes.ModuleName,
)

// NOTE: fee market module must go last in order to retrieve the block gas used.
Expand Down Expand Up @@ -938,7 +939,7 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
taskTypes.ModuleName,
avsTaskTypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -984,7 +985,7 @@ func NewExocoreApp(
crisistypes.ModuleName,
consensusparamtypes.ModuleName,
avsManagerTypes.ModuleName,
taskTypes.ModuleName,
avsTaskTypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/armon/go-metrics v0.4.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/btcutil v1.0.5
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/go-bip39 v1.0.0
Expand Down Expand Up @@ -83,7 +84,6 @@ require (
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions precompiles/avsTask/avsTask.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ IAVSTask constant AVSTASK_CONTRACT = IAVSTask(
interface IAVSTask {
/// TRANSACTIONS
/// @dev IAVSTask the oprator, that will change the state in AVSTask module
/// @param TaskContractAddress task Contract Address
/// @param Name task name
/// @param MetaInfo task desc
/// @param TaskContractAddress avstask Contract Address
/// @param Name avstask name
/// @param MetaInfo avstask desc
function registerAVSTask(
string memory TaskContractAddress,
string memory Name,
Expand All @@ -40,7 +40,7 @@ interface IAVSTask {
function getRegisteredPubkey(address operator) external returns (bytes32);

/// TRANSACTIONS
/// @dev Get the count of the current task
/// @dev Get the count of the current avstask
function checkSignatures(
bytes32 msgHash,
bytes calldata signature,
Expand Down
2 changes: 1 addition & 1 deletion precompiles/avsTask/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
// EventTypeNewTaskCreated defines the event type for the task create transaction.
// EventTypeNewTaskCreated defines the event type for the avstask create transaction.
EventTypeNewPubkeyRegistration = "NewPubkeyRegistration"
)

Expand Down
28 changes: 16 additions & 12 deletions precompiles/avsTask/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package task

import (
"fmt"

exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
"github.com/cosmos/btcutil/bech32"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -12,15 +14,15 @@ import (
)

const (
// MethodRegisterAVSTask defines the ABI method name for the task
// MethodRegisterAVSTask defines the ABI method name for the avstask
// transaction.
MethodRegisterAVSTask = "registerAVSTask"
MethodRegisterBLSPublicKey = "registerBLSPublicKey"
MethodIGetRegisteredPubkey = "getRegisteredPubkey"
MethodICheckSignatures = "checkSignatures"
)

// RegisterAVSTask Middleware uses exocore's default task template to create tasks in task module.
// RegisterAVSTask Middleware uses exocore's default avstask template to create tasks in avstask module.
func (p Precompile) RegisterAVSTask(
ctx sdk.Context,
_ common.Address,
Expand All @@ -29,16 +31,18 @@ func (p Precompile) RegisterAVSTask(
args []interface{},
) ([]byte, error) {
// check the invalidation of caller contract
flag := p.avsKeeper.IsAVS(ctx, sdk.AccAddress(contract.CallerAddress.String()))
if !flag {
callerAddress, _ := bech32.EncodeFromBase256("exo", contract.CallerAddress.Bytes())

Check warning

Code scanning / gosec

Returned error is not propagated up the stack. Warning

Returned error is not propagated up the stack.
avs, _ := p.avsKeeper.GetAVSInfo(ctx, callerAddress)

Check warning

Code scanning / gosec

Returned error is not propagated up the stack. Warning

Returned error is not propagated up the stack.

if avs.GetInfo() == nil {
return nil, fmt.Errorf(ErrNotYetRegistered, contract.CallerAddress)
}

params, err := p.GetTaskParamsFromInputs(ctx, args)
if err != nil {
return nil, err
}
params.FromAddress = contract.CallerAddress.String()
params.FromAddress = callerAddress
_, err = p.taskKeeper.RegisterAVSTask(ctx, params)
if err != nil {
return nil, err
Expand All @@ -59,13 +63,13 @@ func (p Precompile) RegisterBLSPublicKey(
}

addr, ok := args[0].(string)
if !ok {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string")
if !ok || addr == "" {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string", addr)
}

pubkeyBz, ok := args[1].([]byte)
if !ok {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string")
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "[]byte", pubkeyBz)
}

err := p.taskKeeper.SetOperatorPubKey(ctx, addr, pubkeyBz)
Expand All @@ -84,8 +88,8 @@ func (p Precompile) RegisterBLSPublicKey(
}

func (p Precompile) CheckSignatures(
ctx sdk.Context,
contract *vm.Contract,
_ sdk.Context,
_ *vm.Contract,
method *abi.Method,
args []interface{},
) ([]byte, error) {
Expand All @@ -98,7 +102,7 @@ func (p Precompile) CheckSignatures(
// GetRegisteredPubkey
func (p Precompile) GetRegisteredPubkey(
ctx sdk.Context,
contract *vm.Contract,
_ *vm.Contract,
method *abi.Method,
args []interface{},
) ([]byte, error) {
Expand All @@ -108,7 +112,7 @@ func (p Precompile) GetRegisteredPubkey(

addr, ok := args[0].(string)
if !ok {
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string")
return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string", addr)
}

pubkey, err := p.taskKeeper.GetOperatorPubKey(ctx, addr)
Expand Down
5 changes: 3 additions & 2 deletions precompiles/avsTask/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package task

import (
"fmt"

exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
types "github.com/ExocoreNetwork/exocore/x/avs_task/types"
types "github.com/ExocoreNetwork/exocore/x/avstask/types"
sdk "github.com/cosmos/cosmos-sdk/types"
cmn "github.com/evmos/evmos/v14/precompiles/common"
"golang.org/x/xerrors"
)

func (p Precompile) GetTaskParamsFromInputs(ctx sdk.Context, args []interface{}) (*types.RegisterAVSTaskReq, error) {
func (p Precompile) GetTaskParamsFromInputs(_ sdk.Context, args []interface{}) (*types.RegisterAVSTaskReq, error) {
if len(args) != 3 {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 3, len(args))
}
Expand Down
5 changes: 2 additions & 3 deletions precompiles/avsTask/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package task_test

import (
"github.com/ExocoreNetwork/exocore/testutil"
tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types"
"testing"

"github.com/ExocoreNetwork/exocore/precompiles/avsTask"
"github.com/ExocoreNetwork/exocore/testutil"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -31,7 +30,7 @@ func TestPrecompileTestSuite(t *testing.T) {

func (s *TaskPrecompileTestSuite) SetupTest() {
s.DoSetupTest()
precompile, err := task.NewPrecompile(s.App.AuthzKeeper, s.App.TaskKeeper, tasktype.AvsKeeperMock{})
precompile, err := task.NewPrecompile(s.App.AuthzKeeper, s.App.TaskKeeper, s.App.AVSManagerKeeper)
s.Require().NoError(err)
s.precompile = precompile
}
22 changes: 12 additions & 10 deletions precompiles/avsTask/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"bytes"
"embed"
"fmt"
taskKeeper "github.com/ExocoreNetwork/exocore/x/avs_task/keeper"
tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types"

"github.com/ExocoreNetwork/exocore/x/avs/keeper"
taskKeeper "github.com/ExocoreNetwork/exocore/x/avstask/keeper"
"github.com/cometbft/cometbft/libs/log"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -23,23 +24,23 @@ var _ vm.PrecompiledContract = &Precompile{}
//go:embed abi.json
var f embed.FS

// Precompile defines the precompiled contract for task.
// Precompile defines the precompiled contract for avstask.
type Precompile struct {
cmn.Precompile
taskKeeper taskKeeper.Keeper
avsKeeper tasktype.AvsKeeperMock
avsKeeper keeper.Keeper
}

// NewPrecompile creates a new task Precompile instance as a
// NewPrecompile creates a new avstask Precompile instance as a
// PrecompiledContract interface.
func NewPrecompile(
authzKeeper authzkeeper.Keeper,
taskKeeper taskKeeper.Keeper,
avsKeeper tasktype.AvsKeeperMock,
avsKeeper keeper.Keeper,
) (*Precompile, error) {
abiBz, err := f.ReadFile("abi.json")
if err != nil {
return nil, fmt.Errorf("error loading the task ABI %s", err)
return nil, fmt.Errorf("error loading the avstask ABI %s", err)
}

newAbi, err := abi.JSON(bytes.NewReader(abiBz))
Expand All @@ -60,7 +61,7 @@ func NewPrecompile(
}, nil
}

// Address defines the address of the task compile contract.
// Address defines the address of the avstask compile contract.
// address: 0x0000000000000000000000000000000000000901
func (p Precompile) Address() common.Address {
return common.HexToAddress("0x0000000000000000000000000000000000000901")
Expand Down Expand Up @@ -116,7 +117,8 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [

// IsTransaction checks if the given methodID corresponds to a transaction or query.
//
// Available task transactions are:
// Available avstask transactions are:
// - RegisterAVSTask
func (Precompile) IsTransaction(methodID string) bool {
switch methodID {
case MethodRegisterAVSTask:
Expand All @@ -128,5 +130,5 @@ func (Precompile) IsTransaction(methodID string) bool {

// Logger returns a precompile-specific logger.
func (p Precompile) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("ExoCore module", "task")
return ctx.Logger().With("ExoCore module", "avstask")
}
Loading

0 comments on commit 20c766c

Please sign in to comment.