Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bandprotocol/chain into v…
Browse files Browse the repository at this point in the history
…0.47-refactor-testdata
  • Loading branch information
RogerKSI committed Dec 4, 2023
2 parents 0440d0f + c61d769 commit e1d22b6
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 40 deletions.
4 changes: 3 additions & 1 deletion app/upgrades/v2_6/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand All @@ -24,7 +26,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{group.StoreKey, globalfeetypes.StoreKey},
Added: []string{group.StoreKey, globalfeetypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey},
},
}

Expand Down
50 changes: 50 additions & 0 deletions app/upgrades/v2_6/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package v2_6

import (
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/bandprotocol/chain/v2/app/keepers"
"github.com/bandprotocol/chain/v2/app/upgrades"
Expand All @@ -18,6 +30,44 @@ func CreateUpgradeHandler(
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Set param key table for params module migration
for _, subspace := range keepers.ParamsKeeper.GetSubspaces() {
subspace := subspace

var keyTable paramstypes.KeyTable
switch subspace.Name() {
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
case slashingtypes.ModuleName:
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
case govtypes.ModuleName:
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
// ibc types
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck
case oracletypes.ModuleName:
keyTable = oracletypes.ParamKeyTable() //nolint:staticcheck
default:
continue
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}

hostParams := icahosttypes.Params{
HostEnabled: true,
// specifying the whole list instead of adding and removing. Less fragile.
Expand Down
2 changes: 1 addition & 1 deletion client/grpc/oracle/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func getProofsByKey(
}
}
default:
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("Unknown proof ops found")
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("unknown proof ops found")
}
}

Expand Down
5 changes: 2 additions & 3 deletions client/grpc/oracle/proof/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/runtime"

"github.com/bandprotocol/chain/v2/x/oracle/types"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
)

// RegisterProofService registers the node gRPC service on the provided gRPC router.
Expand Down Expand Up @@ -89,7 +88,7 @@ func (s proofServer) Proof(ctx context.Context, req *QueryProofRequest) (*QueryP
}

// Unmarshal the value into a Result object
var rs oracletypes.Result
var rs types.Result
types.ModuleCdc.MustUnmarshal(value, &rs)

// Create an OracleDataProof object with the relevant information
Expand Down Expand Up @@ -195,7 +194,7 @@ func (s proofServer) MultiProof(ctx context.Context, req *QueryMultiProofRequest
}

// Unmarshal the value into a Result object
var rs oracletypes.Result
var rs types.Result
types.ModuleCdc.MustUnmarshal(value, &rs)

// Create an OracleDataProof object with the relevant information
Expand Down
4 changes: 2 additions & 2 deletions client/grpc/oracle/proof/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func recoverETHAddress(msg, sig, signer []byte) ([]byte, uint8, error) {
return crypto.PubkeyToAddress(*pubuc).Bytes(), 27 + i, nil
}
}
return nil, 0, fmt.Errorf("No match address found")
return nil, 0, fmt.Errorf("no match address found")
}

func GetPrefix(t tmproto.SignedMsgType, height int64, round int64) ([]byte, error) {
Expand Down Expand Up @@ -126,7 +126,7 @@ func GetSignaturesAndPrefix(info *types.SignedHeader) ([]TMSignature, CommonEnco
}
}
if len(addrs) == 0 {
return nil, CommonEncodedVotePart{}, fmt.Errorf("No valid precommit")
return nil, CommonEncodedVotePart{}, fmt.Errorf("no valid precommit")
}

signatures := make([]TMSignature, len(addrs))
Expand Down
2 changes: 1 addition & 1 deletion pkg/gzip/gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestUncompress(t *testing.T) {
require.NoError(t, err)
require.Equal(t, file1, accFile)

accFile, err = gzip.Uncompress(gzipFile, 2)
_, err = gzip.Uncompress(gzipFile, 2)
require.Error(t, err)

_, err = gzip.Uncompress(file1, 999)
Expand Down
10 changes: 6 additions & 4 deletions testing/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
ibchost "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/ibc-go/v7/testing/mock"
Expand Down Expand Up @@ -325,7 +324,7 @@ func (chain *TestChain) SendReport(

// GetClientState retrieves the client state for the provided clientID. The client is
// expected to exist otherwise testing will fail.
func (chain *TestChain) GetClientState(clientID string) exported.ClientState {
func (chain *TestChain) GetClientState(clientID string) ibcexported.ClientState {
clientState, found := chain.App.GetIBCKeeper().ClientKeeper.GetClientState(chain.GetContext(), clientID)
require.True(chain.t, found)

Expand All @@ -334,7 +333,10 @@ func (chain *TestChain) GetClientState(clientID string) exported.ClientState {

// GetConsensusState retrieves the consensus state for the provided clientID and height.
// It will return a success boolean depending on if consensus state exists or not.
func (chain *TestChain) GetConsensusState(clientID string, height exported.Height) (exported.ConsensusState, bool) {
func (chain *TestChain) GetConsensusState(
clientID string,
height ibcexported.Height,
) (ibcexported.ConsensusState, bool) {
return chain.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(chain.GetContext(), clientID, height)
}

Expand All @@ -357,7 +359,7 @@ func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bo

// GetAcknowledgement retrieves an acknowledgement for the provided packet. If the
// acknowledgement does not exist then testing will fail.
func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte {
func (chain *TestChain) GetAcknowledgement(packet ibcexported.PacketI) []byte {
ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(
chain.GetContext(),
packet.GetDestPort(),
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (k *WrappedBankKeeper) SetDistrKeeper(dk types.DistributionKeeper) {

// Logger returns a module-specific logger.
func (k WrappedBankKeeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprint("x/wrappedbank"))
return ctx.Logger().With("module", "x/wrappedbank")
}

// BurnCoins moves the specified amount of coins from the given module name to
Expand Down
4 changes: 4 additions & 0 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
panic(fmt.Sprintf("failed to migrate x/bank from version 2 to 3: %v", err))
}

if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
panic(fmt.Sprintf("failed to migrate x/bank from version 3 to 4: %v", err))
}
}
4 changes: 4 additions & 0 deletions x/globalfee/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ const (
// ModuleName is the name of the this module
ModuleName = "globalfee"

// QuerierRoute is the querier route for the globalfee module
QuerierRoute = ModuleName

// StoreKey to be used when creating the KVStore.
StoreKey = ModuleName

// RouterKey is the msg router key for the globalfee module
RouterKey = ModuleName
)

var (
Expand Down
10 changes: 10 additions & 0 deletions x/globalfee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
TypeMsgUpdateParams = "update_params"
)

var _ sdk.Msg = &MsgUpdateParams{}

// Route returns the route of MsgUpdateParams - "oracle" (sdk.Msg interface).
func (m MsgUpdateParams) Route() string { return RouterKey }

// Type returns the message type of MsgUpdateParams (sdk.Msg interface).
func (m MsgUpdateParams) Type() string { return TypeMsgUpdateParams }

// GetSignBytes implements the LegacyMsg interface.
func (m MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (k Querier) RequestVerification(
// Provided signature should be valid, which means this query request should be signed by the provided reporter
pk, err := hex.DecodeString(req.Reporter)
if err != nil || len(pk) != secp256k1.PubKeySize {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("unable to get reporter's public key"))
return nil, status.Error(codes.InvalidArgument, "unable to get reporter's public key")
}
reporterPubKey := secp256k1.PubKey(pk[:])

Expand Down
22 changes: 12 additions & 10 deletions x/oracle/keeper/owasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ func ConvertToOwasmGas(cosmos uint64) uint64 {

// GetSpanSize return maximum value between MaxReportDataSize and MaxCallDataSize
func (k Keeper) GetSpanSize(ctx sdk.Context) uint64 {
if k.GetParams(ctx).MaxReportDataSize > k.GetParams(ctx).MaxCalldataSize {
return k.GetParams(ctx).MaxReportDataSize
params := k.GetParams(ctx)
if params.MaxReportDataSize > params.MaxCalldataSize {
return params.MaxReportDataSize
}
return k.GetParams(ctx).MaxCalldataSize
return params.MaxCalldataSize
}

// GetRandomValidators returns a pseudorandom subset of active validators. Each validator has
Expand Down Expand Up @@ -71,12 +72,13 @@ func (k Keeper) PrepareRequest(
}

askCount := r.GetAskCount()
if askCount > k.GetParams(ctx).MaxAskCount {
return 0, types.WrapMaxError(types.ErrInvalidAskCount, int(askCount), int(k.GetParams(ctx).MaxAskCount))
params := k.GetParams(ctx)
if askCount > params.MaxAskCount {
return 0, types.WrapMaxError(types.ErrInvalidAskCount, int(askCount), int(params.MaxAskCount))
}

// Consume gas for data requests.
ctx.GasMeter().ConsumeGas(askCount*k.GetParams(ctx).PerValidatorRequestGas, "PER_VALIDATOR_REQUEST_FEE")
ctx.GasMeter().ConsumeGas(askCount*params.PerValidatorRequestGas, "PER_VALIDATOR_REQUEST_FEE")

// Get a random validator set to perform this request.
validators, err := k.GetRandomValidators(ctx, int(askCount), k.GetRequestCount(ctx)+1)
Expand All @@ -93,8 +95,8 @@ func (k Keeper) PrepareRequest(
// Create an execution environment and call Owasm prepare function.
env := types.NewPrepareEnv(
req,
int64(k.GetParams(ctx).MaxCalldataSize),
int64(k.GetParams(ctx).MaxRawRequestCount),
int64(params.MaxCalldataSize),
int64(params.MaxRawRequestCount),
int64(k.GetSpanSize(ctx)),
)
script, err := k.GetOracleScript(ctx, req.OracleScriptID)
Expand All @@ -103,7 +105,7 @@ func (k Keeper) PrepareRequest(
}

// Consume fee and execute owasm code
ctx.GasMeter().ConsumeGas(k.GetParams(ctx).BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(params.BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(r.GetPrepareGas(), "OWASM_PREPARE_FEE")
code := k.GetFile(script.Filename)
output, err := k.owasmVM.Prepare(code, ConvertToOwasmGas(r.GetPrepareGas()), env)
Expand Down Expand Up @@ -142,7 +144,7 @@ func (k Keeper) PrepareRequest(
ctx.EventManager().EmitEvent(event)

// Subtract execute fee
ctx.GasMeter().ConsumeGas(k.GetParams(ctx).BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(params.BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(r.GetExecuteGas(), "OWASM_EXECUTE_FEE")

// Emit an event for each of the raw data requests.
Expand Down
3 changes: 3 additions & 0 deletions x/oracle/keeper/owasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestPrepareRequestSuccessBasic(t *testing.T) {
sdk.WrapSDKContext(ctx),
authtypes.NewQueryAllBalancesRequest(bandtesting.FeePayer.Address, &query.PageRequest{}),
)
require.NoError(t, err)
feePayerBalances := balancesRes.Balances

// OracleScript#1: Prepare asks for DS#1,2,3 with ExtID#1,2,3 and calldata "beeb"
Expand Down Expand Up @@ -1072,6 +1073,7 @@ func TestCollectFeeBasicSuccess(t *testing.T) {
sdk.WrapSDKContext(ctx),
authtypes.NewQueryAllBalancesRequest(bandtesting.FeePayer.Address, &query.PageRequest{}),
)
require.NoError(t, err)
feePayerBalances := balancesRes.Balances
feePayerBalances[0].Amount = feePayerBalances[0].Amount.Sub(sdk.NewInt(3000000))

Expand Down Expand Up @@ -1105,6 +1107,7 @@ func TestCollectFeeBasicSuccessWithOtherAskCount(t *testing.T) {
sdk.WrapSDKContext(ctx),
authtypes.NewQueryAllBalancesRequest(bandtesting.FeePayer.Address, &query.PageRequest{}),
)
require.NoError(t, err)
feePayerBalances := balancesRes.Balances
feePayerBalances[0].Amount = feePayerBalances[0].Amount.Sub(sdk.NewInt(12000000))

Expand Down
3 changes: 0 additions & 3 deletions x/oracle/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

// AccountKeeper defines the expected account keeper.
Expand Down Expand Up @@ -47,8 +46,6 @@ type DistrKeeper interface {

// ChannelKeeper defines the expected IBC channel keeper
type ChannelKeeper interface {
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel ibcchanneltypes.Channel, found bool)
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
SendPacket(
ctx sdk.Context,
chanCap *capabilitytypes.Capability,
Expand Down
4 changes: 2 additions & 2 deletions yoda/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func GetEventValues(log sdk.ABCIMessageLog, evType string, evKey string) (res []
func GetEventValue(log sdk.ABCIMessageLog, evType string, evKey string) (string, error) {
values := GetEventValues(log, evType, evKey)
if len(values) == 0 {
return "", fmt.Errorf("Cannot find event with type: %s, key: %s", evType, evKey)
return "", fmt.Errorf("cannot find event with type: %s, key: %s", evType, evKey)
}
if len(values) > 1 {
return "", fmt.Errorf("Found more than one event with type: %s, key: %s", evType, evKey)
return "", fmt.Errorf("found more than one event with type: %s, key: %s", evType, evKey)
}
return values[0], nil
}
Loading

0 comments on commit e1d22b6

Please sign in to comment.