fix review issues

This commit is contained in:
0g-wh 2024-08-04 13:56:43 +08:00
parent 0e37d518ec
commit cb4e6e006e
10 changed files with 11 additions and 696 deletions

View File

@ -16,8 +16,6 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
) )
// d is an alias for sdk.MustNewDecFromStr // d is an alias for sdk.MustNewDecFromStr

View File

@ -47,7 +47,6 @@ func (ac appCreator) newApp(
traceStore io.Writer, traceStore io.Writer,
appOpts servertypes.AppOptions, appOpts servertypes.AppOptions,
) servertypes.Application { ) servertypes.Application {
fmt.Println("newApp")
var cache sdk.MultiStorePersistentCache var cache sdk.MultiStorePersistentCache
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
cache = store.NewCommitKVStoreCacheManager() cache = store.NewCommitKVStoreCacheManager()

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server"
@ -16,7 +15,6 @@ func main() {
if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, chaincfg.DefaultNodeHome); err != nil { if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, chaincfg.DefaultNodeHome); err != nil {
switch e := err.(type) { switch e := err.(type) {
case server.ErrorCode: case server.ErrorCode:
fmt.Println("error")
os.Exit(e.Code) os.Exit(e.Code)
default: default:

6
go.mod
View File

@ -34,7 +34,7 @@ require (
github.com/spf13/viper v1.18.2 github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
github.com/subosito/gotenv v1.6.0 github.com/subosito/gotenv v1.6.0
golang.org/x/crypto v0.22.0 golang.org/x/crypto v0.24.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 golang.org/x/exp v0.0.0-20230905200255-921286631fa9
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.2 google.golang.org/grpc v1.63.2
@ -245,9 +245,7 @@ replace (
// TODO: Tag before release // TODO: Tag before release
github.com/ethereum/go-ethereum => github.com/Kava-Labs/go-ethereum v1.10.27-0.20240513233504-6e038346780b github.com/ethereum/go-ethereum => github.com/Kava-Labs/go-ethereum v1.10.27-0.20240513233504-6e038346780b
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support // Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
// Tracking kava-labs/etheremint master branch github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.1.0
// TODO: Tag before release
github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.21.1-0.20240802224012-586960857184
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320 // See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors // Downgraded to avoid bugs in following commits which causes "version does not exist" errors

569
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/influxdata/influxdb/client"
"github.com/0glabs/0g-chain/client/grpc"
) )
// LiveNodeRunnerConfig implements NodeRunner. // LiveNodeRunnerConfig implements NodeRunner.
@ -50,21 +51,21 @@ func (r LiveNodeRunner) StartChains() Chains {
} }
// determine chain id // determine chain id
grpc, err := zgChain.GrpcConn() client, err := grpc.NewClient(zgChain.GrpcUrl)
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to establish grpc conn to %s: %s", r.config.ZgChainGrpcUrl, err)) panic(fmt.Sprintf("failed to create 0g-chain grpc client: %s", err))
} }
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{}) nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to fetch 0-chain node info: %s", err)) panic(fmt.Sprintf("failed to fetch 0g-chain node info: %s", err))
} }
zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network
// determine staking denom // determine staking denom
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{}) stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to fetch 0gchain staking params: %s", err)) panic(fmt.Sprintf("failed to fetch 0g-chain staking params: %s", err))
} }
zgChain.StakingDenom = stakingParams.Params.BondDenom zgChain.StakingDenom = stakingParams.Params.BondDenom

View File

@ -1,23 +0,0 @@
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v2 "github.com/kava-labs/kava/x/cdp/migrations/v2"
)
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}
// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{
keeper: keeper,
}
}
// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.paramSubspace)
}

View File

@ -1,21 +0,0 @@
package v2
import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// MigrateStore performs in-place store migrations for consensus version 2
// V2 adds the begin_blocker_execution_block_interval param to parameters.
func MigrateStore(ctx sdk.Context, paramstore paramtypes.Subspace) error {
migrateParamsStore(ctx, paramstore)
return nil
}
// migrateParamsStore ensures the param key table exists and has the begin_blocker_execution_block_interval property
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
if !paramstore.HasKeyTable() {
paramstore.WithKeyTable(types.ParamKeyTable())
}
paramstore.Set(ctx, types.KeyBeginBlockerExecutionBlockInterval, types.DefaultBeginBlockerExecutionBlockInterval)
}

View File

@ -1,62 +0,0 @@
package v2_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
v2cdp "github.com/kava-labs/kava/x/cdp/migrations/v2"
)
func TestStoreMigrationAddsKeyTableIncludingNewParam(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig()
cdpKey := sdk.NewKVStoreKey(types.ModuleName)
tcdpKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(cdpKey, tcdpKey)
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, cdpKey, tcdpKey, types.ModuleName)
// Check param doesn't exist before
require.False(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
// Run migrations.
err := v2cdp.MigrateStore(ctx, paramstore)
require.NoError(t, err)
// Make sure the new params are set.
require.True(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
// Assert the value is what we expect
result := types.DefaultBeginBlockerExecutionBlockInterval
paramstore.Get(ctx, types.KeyBeginBlockerExecutionBlockInterval, &result)
require.Equal(t, result, types.DefaultBeginBlockerExecutionBlockInterval)
}
func TestStoreMigrationSetsNewParamOnExistingKeyTable(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig()
cdpKey := sdk.NewKVStoreKey(types.ModuleName)
tcdpKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(cdpKey, tcdpKey)
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, cdpKey, tcdpKey, types.ModuleName)
paramstore.WithKeyTable(types.ParamKeyTable())
// expect it to have key table
require.True(t, paramstore.HasKeyTable())
// expect it to not have new param
require.False(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
// Run migrations.
err := v2cdp.MigrateStore(ctx, paramstore)
require.NoError(t, err)
// Make sure the new params are set.
require.True(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
// Assert the value is what we expect
result := types.DefaultBeginBlockerExecutionBlockInterval
paramstore.Get(ctx, types.KeyBeginBlockerExecutionBlockInterval, &result)
require.Equal(t, result, types.DefaultBeginBlockerExecutionBlockInterval)
}

View File

@ -2,21 +2,11 @@ package keeper_test
import ( import (
"testing" "testing"
"time"
sdkmath "cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/0glabs/0g-chain/app" "github.com/0glabs/0g-chain/app"
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
"github.com/0glabs/0g-chain/x/committee/types"
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
) )
type PermissionTestSuite struct { type PermissionTestSuite struct {