Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump cosmos-sdk v0.42.11 and token module #42

Merged
merged 6 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]

### Features
* (x/upgrade) [\#42](https://github.com/line/lbm/pull/42) add token module and bump cosmos-sdk v0.42.11

### Improvements

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ include sims.mk

test: test-unit test-build

test-all: check test-race test-cover
test-all: test-race test-cover

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./...
Expand Down
40 changes: 40 additions & 0 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package app

import (
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/x/auth/ante"
keeper2 "github.com/line/lbm-sdk/x/auth/keeper"
"github.com/line/lbm-sdk/x/auth/signing"
feegrantkeeper "github.com/line/lbm-sdk/x/feegrant/keeper"
types2 "github.com/line/lbm-sdk/x/feegrant/types"
"github.com/line/lbm-sdk/x/gov/types"
channelkeeper "github.com/line/lbm-sdk/x/ibc/core/04-channel/keeper"
ibcante "github.com/line/lbm-sdk/x/ibc/core/ante"
)

func NewAnteHandler(
ak ante.AccountKeeper,
bankKeeper types.BankKeeper, //nolint:interfacer
feegrantKeeper feegrantkeeper.Keeper,
sigGasConsumer ante.SignatureVerificationGasConsumer,
signModeHandler signing.SignModeHandler,
channelKeeper channelkeeper.Keeper,
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.TxTimeoutHeightDecorator{},
ante.NewValidateMemoDecorator(ak),
ante.NewConsumeGasForTxSizeDecorator(ak),
ante.NewDeductGrantedFeeDecorator(ak.(keeper2.AccountKeeper), bankKeeper.(types2.BankKeeper), feegrantKeeper),
ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(ak),
// ante.NewDeductFeeDecorator(ak, bankKeeper),
ante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
ante.NewSigVerificationDecorator(ak, signModeHandler),
ante.NewIncrementSequenceDecorator(ak, bankKeeper),
ibcante.NewAnteDecorator(channelKeeper),
)
}
20 changes: 17 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ import (
stakingkeeper "github.com/line/lbm-sdk/x/staking/keeper"
stakingtypes "github.com/line/lbm-sdk/x/staking/types"
"github.com/line/lbm-sdk/x/stakingplus"
"github.com/line/lbm-sdk/x/token"
"github.com/line/lbm-sdk/x/token/class"
classkeeper "github.com/line/lbm-sdk/x/token/class/keeper"
tokenkeeper "github.com/line/lbm-sdk/x/token/keeper"
tokenmodule "github.com/line/lbm-sdk/x/token/module"
"github.com/line/lbm-sdk/x/upgrade"
upgradeclient "github.com/line/lbm-sdk/x/upgrade/client"
upgradekeeper "github.com/line/lbm-sdk/x/upgrade/keeper"
Expand Down Expand Up @@ -141,6 +146,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
tokenmodule.AppModuleBasic{},
wasm.AppModuleBasic{},
)

Expand Down Expand Up @@ -198,6 +204,7 @@ type LinkApp struct { // nolint: golint
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
TokenKeeper tokenkeeper.Keeper
WasmKeeper wasm.Keeper

// make scoped keepers public for test purposes
Expand Down Expand Up @@ -251,6 +258,8 @@ func NewLinkApp(
capabilitytypes.StoreKey,
feegranttypes.StoreKey,
consortiumtypes.StoreKey,
class.StoreKey,
token.StoreKey,
wasm.StoreKey,
)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -303,6 +312,9 @@ func NewLinkApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)
app.ConsortiumKeeper = consortiumkeeper.NewKeeper(appCodec, keys[consortiumtypes.StoreKey], stakingKeeper)

classKeeper := classkeeper.NewKeeper(appCodec, keys[class.StoreKey])
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.AccountKeeper, classKeeper)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -418,6 +430,7 @@ func NewLinkApp(
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
tokenmodule.NewAppModule(appCodec, app.TokenKeeper),
transferModule,
)

Expand All @@ -426,7 +439,7 @@ func NewLinkApp(
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
)
app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)
Expand Down Expand Up @@ -454,6 +467,7 @@ func NewLinkApp(
ibctransfertypes.ModuleName,
feegranttypes.ModuleName,
consortiumtypes.ModuleName,
token.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
)
Expand Down Expand Up @@ -493,10 +507,10 @@ func NewLinkApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(
ante.NewAnteHandler(
NewAnteHandler(
app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper,
ante.DefaultSigVerificationGasConsumer,
encodingConfig.TxConfig.SignModeHandler(),
encodingConfig.TxConfig.SignModeHandler(), app.IBCKeeper.ChannelKeeper,
),
)
app.SetEndBlocker(app.EndBlocker)
Expand Down
4 changes: 2 additions & 2 deletions app/params/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Package params defines the simulation parameters in the gaia.

It contains the default weights used for each transaction used on the module's
simulation. These weights define the chance for a transaction to be simulated at
any gived operation.
any given operation.

You can repace the default values for the weights by providing a params.json
You can replace the default values for the weights by providing a params.json
file with the weights defined for each of the transaction operations:

{
Expand Down
1 change: 1 addition & 0 deletions builders/scripts/build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go mod download

# build wasmvm static
cd "$(go list -f "{{ .Dir }}" -m github.com/line/wasmvm)" || exit 1
cd ./libwasmvm
brew0722 marked this conversation as resolved.
Show resolved Hide resolved
RUSTFLAGS='-C target-feature=-crt-static' cargo build --release --example staticlib
mv -f target/release/examples/libstaticlib.a /usr/lib/libwasmvm_static.a
rm -rf target
Expand Down
30 changes: 15 additions & 15 deletions cmd/lbm/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa

config.SetRoot(clientCtx.HomeDir)

var addr sdk.AccAddress
var kr keyring.Keyring
addr := sdk.AccAddress(args[0])
err := sdk.ValidateAccAddress(args[0])
if err != nil {
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
return err
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
if keyringBackend != "" && clientCtx.Keyring == nil {
var err error
kr, err = keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
if err != nil {
return err
}
} else {
kr = clientCtx.Keyring
}

// attempt to lookup address from Keybase if no address was provided
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
info, err := kr.Key(args[0])
if err != nil {
return err
return fmt.Errorf("failed to get address from Keyring: %w", err)
}

info, err := kb.Key(args[0])
if err != nil {
return fmt.Errorf("failed to get address from Keybase: %w", err)
}

addr = info.GetAddress()
} else {
addr = sdk.AccAddress(args[0])
Expand Down Expand Up @@ -100,7 +100,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
var genAccount authtypes.GenesisAccount

balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}
baseAccount := authtypes.NewBaseAccount(addr, nil, 0)
baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0)

if !vestingAmt.IsZero() {
baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)
Expand Down Expand Up @@ -163,7 +163,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa

appState[authtypes.ModuleName] = authGenStateBz

bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState)
bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState)
bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)
Expand Down
108 changes: 108 additions & 0 deletions cmd/lbm/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package cmd_test

import (
"context"
"fmt"
"github.com/line/lbm-sdk/crypto/hd"
"github.com/line/lbm-sdk/crypto/keyring"
sdk "github.com/line/lbm-sdk/types"
"testing"

"github.com/line/ostracon/libs/log"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"

"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/client/flags"
"github.com/line/lbm-sdk/server"
"github.com/line/lbm-sdk/simapp"
simcmd "github.com/line/lbm-sdk/simapp/simd/cmd"
"github.com/line/lbm-sdk/testutil/testdata"
"github.com/line/lbm-sdk/types/module"
"github.com/line/lbm-sdk/x/genutil"
genutiltest "github.com/line/lbm-sdk/x/genutil/client/testutil"
)

var testMbm = module.NewBasicManager(genutil.AppModuleBasic{})

func TestAddGenesisAccountCmd(t *testing.T) {
_, _, addr1 := testdata.KeyTestPubAddr()
tests := []struct {
name string
addr string
denom string
withKeyring bool
expectErr bool
}{
{
name: "invalid address",
addr: "",
denom: "1000atom",
withKeyring: false,
expectErr: true,
},
{
name: "valid address",
addr: addr1.String(),
denom: "1000atom",
withKeyring: false,
expectErr: false,
},
{
name: "multiple denoms",
addr: addr1.String(),
denom: "1000atom, 2000stake",
withKeyring: false,
expectErr: false,
},
{
name: "with keyring",
addr: "ser",
denom: "1000atom",
withKeyring: true,
expectErr: false,
},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

appCodec, _ := simapp.MakeCodecs()
err = genutiltest.ExecInitCmd(testMbm, home, appCodec)
require.NoError(t, err)

serverCtx := server.NewContext(viper.New(), cfg, logger)
clientCtx := client.Context{}.WithJSONMarshaler(appCodec).WithHomeDir(home)

if tc.withKeyring {
path := hd.CreateHDPath(118, 0, 0).String()
kr, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, home, nil)
require.NoError(t, err)
_, _, err = kr.NewMnemonic(tc.addr, keyring.English, path, hd.Secp256k1)
require.NoError(t, err)
clientCtx = clientCtx.WithKeyring(kr)
}

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)

cmd := simcmd.AddGenesisAccountCmd(home)
cmd.SetArgs([]string{
tc.addr,
tc.denom,
fmt.Sprintf("--%s=home", flags.FlagHome)})

if tc.expectErr {
require.Error(t, cmd.ExecuteContext(ctx))
} else {
require.NoError(t, cmd.ExecuteContext(ctx))
}
})
}
}
24 changes: 22 additions & 2 deletions cmd/lbm/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/line/lbm-sdk/baseapp"
"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/client/config"
"github.com/line/lbm-sdk/client/debug"
"github.com/line/lbm-sdk/client/flags"
"github.com/line/lbm-sdk/client/keys"
Expand Down Expand Up @@ -56,13 +57,27 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(app.DefaultNodeHome)
WithHomeDir(app.DefaultNodeHome).
WithViper("")

rootCmd := &cobra.Command{
Use: "lbm",
Short: "LINE Blockchain Mainnet (LBM) App",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())

initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
if err != nil {
return err
}

initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}

if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}
Expand All @@ -78,6 +93,10 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {

func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
authclient.Codec = encodingConfig.Marshaler
// Todo This is applied to https://github.com/cosmos/cosmos-sdk/pull/9299.
// But it is failed in `make localnet-start`. Let's check it later.
//cfg := sdk.GetConfig()
//cfg.Seal()

rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
Expand All @@ -88,6 +107,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
ostcli.NewCompletionCmd(rootCmd, true),
testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
config.Cmd(),
)

server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, createSimappAndExport, addModuleInitFlags)
Expand Down
Loading