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

release: prepare release for v1.1.0 #356

Merged
merged 10 commits into from
Nov 13, 2023
2 changes: 1 addition & 1 deletion .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v3

- name: Run Gosec Security Scanner
uses: securego/gosec@master
uses: securego/gosec@v2.17.0
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: "-no-fail -fmt sarif -out results.sarif ./..."
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.1.0
This release introduces the Pampas upgrade and contains 6 new features.

Features:
* [#316](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/316) feat: add validation with context information
* [#321](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/321) feat: add tool to migrate stores for fastnode
* [#336](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/336) feat: introduce the pampas upgrade
* [#341](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/341) feat: add support for some json rpc queries
* [#353](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/353) feat: distinguish inturn relayer
* [#320](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/320) feat: add MsgRejectMigrateBucket

## v1.0.1
This release includes 1 bug fix.

Expand Down
242 changes: 184 additions & 58 deletions api/cosmos/oracle/v1/query.pulsar.go

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ const (

// Supported EVM json-rpc requests
const (
EthBlockNumber = "eth_blockNumber"
EthGetBlockByNumber = "eth_getBlockByNumber"
EthGetBalance = "eth_getBalance"
EthChainID = "eth_chainId"
NetVersion = "net_version"
EthNetworkID = "eth_networkId"
EthBlockNumber = "eth_blockNumber"
EthGetBlockByNumber = "eth_getBlockByNumber"
EthGetBalance = "eth_getBalance"
EthChainID = "eth_chainId"
NetVersion = "net_version"
EthNetworkID = "eth_networkId"
EthGasPrice = "eth_gasPrice"
EthGetCode = "eth_getCode"
EthEstimateGas = "eth_estimateGas"
EthCall = "eth_call"
EthGetTransactionCount = "eth_getTransactionCount"
EthSendRawTransaction = "eth_sendRawTransaction"
)

// InitChain implements the ABCI interface. It runs the initialization logic
Expand Down
20 changes: 20 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,23 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error {
return nil
}

// validateRuntimeTxMsgs executes basic runtime validator calls for messages.
func validateRuntimeTxMsgs(ctx sdk.Context, msgs []sdk.Msg) error {
if len(msgs) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must contain at least one message")
}

for _, msg := range msgs {
if runtimeMsg, ok := msg.(sdk.MsgWithRuntimeValidation); ok {
if err := runtimeMsg.ValidateRuntime(ctx); err != nil {
return err
}
}
}

return nil
}

// Returns the application's deliverState if app is in runTxModeDeliver,
// prepareProposalState if app is in runTxPrepareProposal, processProposalState
// if app is in runTxProcessProposal, and checkState otherwise.
Expand Down Expand Up @@ -790,6 +807,9 @@ func (app *BaseApp) runTxOnContext(ctx sdk.Context, mode runTxMode, txBytes []by
if err := validateBasicTxMsgs(msgs); err != nil {
return sdk.GasInfo{}, nil, nil, 0, err
}
if err := validateRuntimeTxMsgs(ctx, msgs); err != nil {
return sdk.GasInfo{}, nil, nil, 0, err
}

if app.anteHandler != nil {
var (
Expand Down
24 changes: 24 additions & 0 deletions baseapp/ethrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func (e *EthQueryRouter) RegisterConstHandler() {
e.AddRoute(EthNetworkID, chainIdHandler)
e.AddRoute(EthChainID, chainIdHandler)
e.AddRoute(NetVersion, chainIdHandler)
e.AddRoute(EthGasPrice, gasPriceHandler)
e.AddRoute(EthGetCode, chainIdHandler) // return dummy result
e.AddRoute(EthEstimateGas, estimateGasHandler) // return dummy result
e.AddRoute(EthCall, chainIdHandler) // return dummy result
e.AddRoute(EthGetTransactionCount, getTransactionCountHandler) // return dummy result
e.AddRoute(EthSendRawTransaction, chainIdHandler) // return dummy result
}

func blockNumberHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
Expand All @@ -72,6 +78,24 @@ func blockNumberHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.Respo
return res, nil
}

func gasPriceHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
res.Response = big.NewInt(5e9).Bytes()
return res, nil
}

func estimateGasHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
res.Response = big.NewInt(21000).Bytes()
return res, nil
}

func getTransactionCountHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
res.Response = big.NewInt(1).Bytes()
return res, nil
}

func chainIdHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
eip155ChainID, err := sdk.ParseChainID(ctx.ChainID())
Expand Down
6 changes: 6 additions & 0 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
return nil, err
}

if runtimeReq, ok := req.(sdk.MsgWithRuntimeValidation); ok {
if err := runtimeReq.ValidateRuntime(ctx); err != nil {
return nil, err
}
}

if msr.circuitBreaker != nil {
msgURL := sdk.MsgTypeURL(req)

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.0

github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.3
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1

Expand All @@ -183,6 +183,7 @@ replace (
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
// replace broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/wercker/journalhook => github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117
)

retract (
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsy
github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI=
github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield-cometbft v0.0.3 h1:tv8NMy3bzX/1urqXGQIIAZSLy83loiI+dG0VKeyh1CY=
github.com/bnb-chain/greenfield-cometbft v0.0.3/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62 h1:pakuREXV/XfWNwgsTXUQwYirem12Tt+2LGGHIar0z8o=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62/go.mod h1:43yICrTxu90VjEUpQN23bsqi9mua5m5sFQq/ekHwN9s=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-iavl v0.20.1 h1:y3L64GU99otNp27/xLVBTDbv4eroR6CzoYz0rbaVotM=
Expand Down Expand Up @@ -1852,7 +1852,7 @@ github.com/wealdtech/go-eth2-util v1.6.3 h1:2INPeOR35x5LdFFpSzyw954WzTD+DFyHe3yK
github.com/wealdtech/go-eth2-util v1.6.3/go.mod h1:0hFMj/qtio288oZFHmAbCnPQ9OB3c4WFzs5NVPKTY4k=
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3/go.mod h1:qiIimacW5NhVRy8o+YxWo9YrecXqDAKKbL0+sOa0SJ4=
github.com/wealdtech/go-eth2-wallet-types/v2 v2.8.2/go.mod h1:k6kmiKWSWBTd4OxFifTEkPaBLhZspnO2KFD5XJY9nqg=
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9/go.mod h1:j4l84WPFclQPj320J9gp0XwNKBb3U0zt5CBqjPp22G4=
Expand Down
16 changes: 15 additions & 1 deletion proto/cosmos/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,22 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}

// ClaimSrcChain defines the src chain of a claim
enum ClaimSrcChain {
option (gogoproto.goproto_enum_prefix) = false;
// CLAIM_SRC_CHAIN_UNSPECIFIED
CLAIM_SRC_CHAIN_UNSPECIFIED = 0;
// CLAIM_SRC_CHAIN_BSC defines BSC source chain
CLAIM_SRC_CHAIN_BSC = 1;
// CLAIM_SRC_CHAIN_OP_BNB defines OPBNB source chain
CLAIM_SRC_CHAIN_OP_BNB = 2;
}

// QueryInturnRelayerRequest is the request type for the Query In-turn relayer RPC method.
message QueryInturnRelayerRequest {}
message QueryInturnRelayerRequest {
// ClaimSrcChain defines the src chain of a claim
ClaimSrcChain claim_src_chain = 1;
}

// QueryInturnRelayerResponse is the response type for the Query In-turn relayer RPC method.
message QueryInturnRelayerResponse {
Expand Down
94 changes: 94 additions & 0 deletions server/migrate_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package server

import (
"errors"
"fmt"
"os"

"github.com/cometbft/cometbft/node"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client/flags"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
)

// tmpMigratingDir is a temporary directory to facilitate the migration.
const tmpMigratingDir = "data-migrating"

// NewMigrateStoreCmd creates a command to migrate multistore from IAVL stores to plain DB stores to enable fast node.
func NewMigrateStoreCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "migrate-store",
Short: "migrate application db to use plain db stores instead of IAVL stores",
Long: `
To run a fast node, plain DB store type is needed. To convert a normal full node to a fast full node,
we need to migrate the underlying stores. With this command, the old application db will be backed up,
the new application db will use plain DB store types.
`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := GetServerContextFromCmd(cmd)
cfg := ctx.Config
home := cfg.RootDir
db, err := openDB(home, GetAppDBBackend(ctx.Viper))
if err != nil {
return err
}
newDb, err := openDBWithDataDir(home, tmpMigratingDir, GetAppDBBackend(ctx.Viper))
if err != nil {
return err
}
config, err := serverconfig.GetConfig(ctx.Viper)
if err != nil {
return err
}
genDocProvider := node.DefaultGenesisDocProviderFunc(ctx.Config)
genDoc, err := genDocProvider()
if err != nil {
return err
}
app := appCreator(ctx.Logger, db, nil, genDoc.ChainID, &config, ctx.Viper)

if err = app.CommitMultiStore().LoadLatestVersion(); err != nil {
return err
}
rs, ok := app.CommitMultiStore().(*rootmulti.Store)
if !ok {
return errors.New("cannot convert store to root multi store")
}

if err = rs.MigrateStores(storetypes.StoreTypeDB, newDb); err != nil {
return err
}
version, err := rootmulti.MigrateCommitInfos(db, newDb)
if err != nil {
return err
}
fmt.Printf("Multi root store is captured at version %d \n", version)

_ = db.Close()
_ = newDb.Close()

applicationPath := fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, "data", os.PathSeparator, "application.db")
applicationBackupPath := fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, "data", os.PathSeparator, "application.db-backup")
applicationMigratePath := fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, tmpMigratingDir, os.PathSeparator, "application.db")
if err = os.Rename(applicationPath, applicationBackupPath); err != nil {
return err
}
if err = os.Rename(applicationMigratePath, applicationPath); err != nil {
return err
}
fmt.Printf("Application db is replaced and the old one is backup %s\n", applicationBackupPath)

_ = os.Remove(applicationMigratePath)
fmt.Printf("Migrate application db done, please update app.toml and config.toml to use fastnode feature")

return nil
},
}

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
return cmd
}
6 changes: 6 additions & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type
ExportCmd(appExport, defaultNodeHome),
version.NewVersionCommand(),
NewRollbackCmd(appCreator, defaultNodeHome),
NewMigrateStoreCmd(appCreator, defaultNodeHome),
)
}

Expand Down Expand Up @@ -432,6 +433,11 @@ func openDB(rootDir string, backendType dbm.BackendType, opts ...*dbm.NewDatabas
return dbm.NewDB("application", backendType, dataDir, opts...)
}

func openDBWithDataDir(rootDir, subDir string, backendType dbm.BackendType, opts ...*dbm.NewDatabaseOption) (dbm.DB, error) {
dataDir := filepath.Join(rootDir, subDir)
return dbm.NewDB("application", backendType, dataDir, opts...)
}

func openTraceWriter(traceWriterFile string) (w io.WriteCloser, err error) {
if traceWriterFile == "" {
return
Expand Down
1 change: 1 addition & 0 deletions snapshots/types/snapshot.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ func (rs *Store) GetStoreType() types.StoreType {
return types.StoreTypeMulti
}

// MigrateStores will migrate stores to another type in another db.
func (rs *Store) MigrateStores(targetType types.StoreType, newDb dbm.DB) error {
if targetType != types.StoreTypeDB {
return errors.New("only StoreTypeDB is supported")
}

for key, store := range rs.stores {
switch store.GetStoreType() {
case types.StoreTypeIAVL:
rs.logger.Info("Migrating IAVL store", "store name", key.Name())
iterator := store.Iterator(nil, nil)
for ; iterator.Valid(); iterator.Next() {
prefixKey := append([]byte("s/k:"+key.Name()+"/"), iterator.Key()...)
if err := newDb.SetSync(prefixKey, iterator.Value()); err != nil {
return err
}
}
_ = iterator.Close()
default:

}
}
return nil
}

// MountStoreWithDB implements CommitMultiStore.
func (rs *Store) MountStoreWithDB(key types.StoreKey, typ types.StoreType, db dbm.DB) {
if key == nil {
Expand Down Expand Up @@ -1249,3 +1274,34 @@ func flushLatestVersion(batch dbm.Batch, version int64) {

batch.Set([]byte(latestVersionKey), bz)
}

// MigrateCommitInfos will migrate commit infos to another db.
func MigrateCommitInfos(oldDb, newDb dbm.DB) (int64, error) {
bz, err := oldDb.Get([]byte(latestVersionKey))
if err != nil {
return 0, errors.New("fail to read the latest version")
}
if err = newDb.SetSync([]byte(latestVersionKey), bz); err != nil {
return 0, err
}

version := GetLatestVersion(oldDb)
bz, err = oldDb.Get([]byte(fmt.Sprintf(commitInfoKeyFmt, version)))
if bz == nil {
return 0, errors.New("fail to read the latest commit info")
}
if err != nil {
return 0, err
}
if err = newDb.SetSync([]byte(fmt.Sprintf(commitInfoKeyFmt, version)), bz); err != nil {
return 0, err
}

// ignore the errors for saving old commit info
bz, _ = oldDb.Get([]byte(fmt.Sprintf(commitInfoKeyFmt, version-1)))
if bz != nil {
_ = newDb.SetSync([]byte(fmt.Sprintf(commitInfoKeyFmt, version-1)), bz)
}

return version, nil
}
Loading
Loading