Skip to content

Commit

Permalink
feat: blocked addrs (#210)
Browse files Browse the repository at this point in the history
* wip

* remove logging

* add blocked addr impl

* rollback bechmark test

* bump movevm
  • Loading branch information
beer-1 authored Jun 20, 2024
1 parent 4705e2d commit 43cfa4a
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.22-alpine3.19 AS go-builder
#ARG arch=x86_64

# See https://github.com/initia-labs/movevm/releases
ENV LIBMOVEVM_VERSION=v0.3.1
ENV LIBMOVEVM_VERSION=v0.3.2

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"golang.org/x/exp/maps"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
Expand Down Expand Up @@ -878,7 +879,7 @@ func NewInitiaApp(
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, *app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, *app.ConsensusParamsKeeper),
move.NewAppModule(appCodec, *app.MoveKeeper, vc),
move.NewAppModule(appCodec, *app.MoveKeeper, vc, maps.Keys(maccPerms)),
auction.NewAppModule(app.appCodec, *app.AuctionKeeper),
ophost.NewAppModule(appCodec, *app.OPHostKeeper),
// slinky modules
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ require (
github.com/hashicorp/go-metrics v0.5.3
github.com/initia-labs/OPinit v0.3.1
// we also need to update `LIBMOVEVM_VERSION` of images/private/Dockerfile#5
github.com/initia-labs/movevm v0.3.1
// we also need to update `LIBMOVEVM_VERSION` of Dockerfile#5
github.com/initia-labs/movevm v0.3.2
github.com/noble-assets/forwarding/v2 v2.0.0-20240514101621-172acc02aac6
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ github.com/initia-labs/cosmos-sdk v0.0.0-20240617110109-8f40e8e336e1 h1:d8nw7Ey/
github.com/initia-labs/cosmos-sdk v0.0.0-20240617110109-8f40e8e336e1/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40=
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e h1:1gkMWkAgVhYFhEv7K4tX+8uJJLdiTKlQhl5+wGaxdMg=
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
github.com/initia-labs/movevm v0.3.1 h1:vydw0mdqsLyPN9W2DVq1/gDXDR3snbr6c4Wy/sTYVxY=
github.com/initia-labs/movevm v0.3.1/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
github.com/initia-labs/movevm v0.3.2 h1:JRmLVJ4wPVXB05y8CBvX63zFnYu68dlrv/rct4dhS38=
github.com/initia-labs/movevm v0.3.2/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
2 changes: 1 addition & 1 deletion images/private/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.22-alpine3.19 AS go-builder
#ARG arch=x86_64

# See https://github.com/initia-labs/movevm/releases
ARG LIBMOVEVM_VERSION=v0.3.1
ARG LIBMOVEVM_VERSION=v0.3.2

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
Expand Down
7 changes: 4 additions & 3 deletions x/move/keeper/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewApi(k Keeper, ctx context.Context) GoApi {
}

// GetAccountInfo return account info (account number, sequence)
func (api GoApi) GetAccountInfo(addr vmtypes.AccountAddress) (bool /* found */, uint64 /* account number */, uint64 /* sequence */, uint8 /* account_type */) {
func (api GoApi) GetAccountInfo(addr vmtypes.AccountAddress) (bool /* found */, uint64 /* account number */, uint64 /* sequence */, uint8 /* account_type */, bool /* is_blocked */) {
sdkAddr := types.ConvertVMAddressToSDKAddress(addr)
if api.authKeeper.HasAccount(api.ctx, sdkAddr) {
acc := api.authKeeper.GetAccount(api.ctx, sdkAddr)
Expand All @@ -47,10 +47,11 @@ func (api GoApi) GetAccountInfo(addr vmtypes.AccountAddress) (bool /* found */,
accType = vmtypes.AccountType_Module
}

return true, acc.GetAccountNumber(), acc.GetSequence(), accType
isBlocked := api.bankKeeper.BlockedAddr(sdkAddr)
return true, acc.GetAccountNumber(), acc.GetSequence(), accType, isBlocked
}

return false, 0, 0, 0
return false, 0, 0, 0, false
}

// AmountToShare convert amount to share
Expand Down
13 changes: 8 additions & 5 deletions x/move/keeper/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func Test_GetAccountInfo(t *testing.T) {

// base account
input.AccountKeeper.SetAccount(ctx, input.AccountKeeper.NewAccountWithAddress(ctx, addrs[0]))
found, accountNumber, sequence, accountType := api.GetAccountInfo(vmaddr)
found, accountNumber, sequence, accountType, isBlocked := api.GetAccountInfo(vmaddr)
require.True(t, found)
require.False(t, isBlocked)

acc := input.AccountKeeper.GetAccount(ctx, addrs[0])
require.Equal(t, acc.GetAccountNumber(), accountNumber)
Expand All @@ -45,8 +46,9 @@ func Test_GetAccountInfo(t *testing.T) {
govAddr := govAcc.GetAddress()
govVmAddr, err := vmtypes.NewAccountAddressFromBytes(govAddr.Bytes())
require.NoError(t, err)
found, accountNumber, sequence, accountType = api.GetAccountInfo(govVmAddr)
found, accountNumber, sequence, accountType, isBlocked = api.GetAccountInfo(govVmAddr)
require.True(t, found)
require.True(t, isBlocked)

acc = input.AccountKeeper.GetAccount(ctx, govAddr)
require.Equal(t, acc.GetAccountNumber(), accountNumber)
Expand All @@ -57,8 +59,9 @@ func Test_GetAccountInfo(t *testing.T) {
vmaddr, err = vmtypes.NewAccountAddress("0x3")
require.NoError(t, err)

found, _, _, _ = api.GetAccountInfo(vmaddr)
found, _, _, _, isBlocked = api.GetAccountInfo(vmaddr)
require.False(t, found)
require.False(t, isBlocked)
}

func Test_CreateTypedAccounts(t *testing.T) {
Expand All @@ -70,7 +73,7 @@ func Test_CreateTypedAccounts(t *testing.T) {
api := keeper.NewApi(input.MoveKeeper, ctx)

input.AccountKeeper.SetAccount(ctx, input.AccountKeeper.NewAccountWithAddress(ctx, addrs[0]))
found, accountNumber, sequence, accountType := api.GetAccountInfo(vmaddr)
found, accountNumber, sequence, accountType, _ := api.GetAccountInfo(vmaddr)
require.True(t, found)

acc := input.AccountKeeper.GetAccount(ctx, addrs[0])
Expand All @@ -81,7 +84,7 @@ func Test_CreateTypedAccounts(t *testing.T) {
vmaddr, err = vmtypes.NewAccountAddress("0x3")
require.NoError(t, err)

found, _, _, _ = api.GetAccountInfo(vmaddr)
found, _, _, _, _ = api.GetAccountInfo(vmaddr)
require.False(t, found)
}

Expand Down
9 changes: 5 additions & 4 deletions x/move/keeper/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (k MoveBankKeeper) MintCoins(
vmtypes.StdAddress,
vmtypes.StdAddress,
types.MoveModuleNameManagedCoin,
types.FunctionNameManagedCoinMint,
types.FunctionNameManagedCoinSudoMint,
[]vmtypes.TypeTag{},
[][]byte{recipientAddr[:], metadata[:], amountBz},
)
Expand Down Expand Up @@ -520,13 +520,14 @@ func (k MoveBankKeeper) SendCoin(
return err
}

return k.ExecuteEntryFunction(
return k.executeEntryFunction(
ctx,
fromVmAddr,
[]vmtypes.AccountAddress{vmtypes.StdAddress, fromVmAddr},
vmtypes.StdAddress,
types.MoveModuleNameCoin,
types.FunctionNameCoinTransfer,
types.FunctionNameCoinSudoTransfer,
[]vmtypes.TypeTag{},
[][]byte{toVmAddr[:], metadata[:], amountBz},
false,
)
}
9 changes: 7 additions & 2 deletions x/move/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -57,8 +58,12 @@ func (k Keeper) Initialize(
}

// InitGenesis sets supply information for genesis.
func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error {
k.authKeeper.GetModuleAccount(ctx, types.MoveStakingModuleName)
func (k Keeper) InitGenesis(ctx context.Context, moduleNames []string, genState types.GenesisState) error {
// create all module addresses
sort.StringSlice(moduleNames).Sort()
for _, moduleName := range moduleNames {
k.authKeeper.GetModuleAccount(ctx, moduleName)
}

params := genState.GetParams()
if err := k.SetRawParams(ctx, params.ToRaw()); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions x/move/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry)
// AppModule implements an application module for the move module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
vc address.Codec

keeper keeper.Keeper
vc address.Codec
moduleNames []string
}

// IsAppModule implements the appmodule.AppModule interface.
Expand All @@ -111,11 +113,13 @@ func NewAppModule(
cdc codec.Codec,
k keeper.Keeper,
vc address.Codec,
moduleNames []string,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc},
keeper: k,
vc: vc,
moduleNames: moduleNames,
}
}

Expand All @@ -133,7 +137,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)

if err := am.keeper.InitGenesis(ctx, genesisState); err != nil {
if err := am.keeper.InitGenesis(ctx, am.moduleNames, genesisState); err != nil {
panic(err)
}
}
Expand Down
11 changes: 6 additions & 5 deletions x/move/types/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (

// function names for managed_coin
FunctionNameManagedCoinInitialize = "initialize"
FunctionNameManagedCoinMint = "mint"
FunctionNameManagedCoinSudoMint = "sudo_mint"
FunctionNameManagedCoinBurn = "burn"

// function names for simple_nft
Expand All @@ -37,10 +37,11 @@ const (
FunctionNameSimpleNftBurn = "burn"

// function names for coin
FunctionNameCoinBalance = "balance"
FunctionNameCoinRegister = "register"
FunctionNameCoinTransfer = "transfer"
FunctionNameCoinWhitelist = "whitelist"
FunctionNameCoinBalance = "balance"
FunctionNameCoinRegister = "register"
FunctionNameCoinTransfer = "transfer"
FunctionNameCoinSudoTransfer = "sudo_transfer"
FunctionNameCoinWhitelist = "whitelist"

// function names for staking
FunctionNameStakingInitialize = "initialize_for_chain"
Expand Down

0 comments on commit 43cfa4a

Please sign in to comment.