Skip to content

Commit

Permalink
Problem: state streaming is supported in old versions
Browse files Browse the repository at this point in the history
Solution:
- backport the feature to older version of cosmos-sdk
- integration the basic file streamer, further processing can be done based on that
  • Loading branch information
yihuang committed Sep 19, 2022
1 parent 2a936a4 commit 3cb886c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1,750 deletions.
30 changes: 30 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"path/filepath"
"sync"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -17,12 +18,14 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming/file"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -103,6 +106,7 @@ import (
evmtypes "github.com/tharsis/ethermint/x/evm/types"

// this line is used by starport scaffolding # stargate/app/moduleImport
cronosappclient "github.com/crypto-org-chain/cronos/client"
cronos "github.com/crypto-org-chain/cronos/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/x/cronos/client"
cronoskeeper "github.com/crypto-org-chain/cronos/x/cronos/keeper"
Expand All @@ -122,6 +126,8 @@ const (
//
// NOTE: In the SDK, the default value is 255.
AddrLen = 20

FileStreamerDirectory = "file_streamer"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -296,6 +302,30 @@ func New(
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

// configure state listening capabilities using AppOptions
// we are doing nothing with the returned streamingServices and waitGroup in this case
// Only support file streamer right now.
if cast.ToString(appOpts.Get(cronosappclient.FlagStreamers)) == "file" {
streamingDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", FileStreamerDirectory)
if err := os.MkdirAll(streamingDir, os.ModePerm); err != nil {
panic(err)
}

// default to exposing all
exposeStoreKeys := make([]sdk.StoreKey, 0, len(keys))
for _, storeKey := range keys {
exposeStoreKeys = append(exposeStoreKeys, storeKey)
}
service, err := file.NewStreamingService(streamingDir, "", exposeStoreKeys, appCodec)
if err != nil {
panic(err)
}
bApp.SetStreamingService(service)

wg := new(sync.WaitGroup)
service.Stream(wg)
}

app := &App{
BaseApp: bApp,
cdc: cdc,
Expand Down
21 changes: 21 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"

"github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/tharsis/ethermint/server/config"
)

// List of available flags for the simulator
Expand Down Expand Up @@ -73,3 +74,23 @@ func NewConfigFromFlags() simulation.Config {
AllInvariants: FlagAllInvariantsValue,
}
}

type StoreConfig struct {
Streamers []string `mapstructure:"streamers"`
}

type StreamersConfig struct {
File FileStreamerConfig `mapstructure:"file"`
}

type FileStreamerConfig struct {
Prefix string `mapstructure:"prefix"`
WriteDir string `mapstructure:"write_dir"`
}

type Config struct {
config.Config

Store StoreConfig `mapstructure:"store"`
Streamers StreamersConfig `mapstructure:"streamers"`
}
3 changes: 3 additions & 0 deletions client/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package client

const FlagStreamers = "streamers"
2 changes: 2 additions & 0 deletions cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
ethermint "github.com/tharsis/ethermint/types"

"github.com/crypto-org-chain/cronos/app"
cronosclient "github.com/crypto-org-chain/cronos/client"
// this line is used by starport scaffolding # stargate/root/import
)

Expand Down Expand Up @@ -141,6 +142,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
startCmd.Flags().String(cronosclient.FlagStreamers, "", "Enable streamers, only file streamer is supported right now")
// this line is used by starport scaffolding # stargate/root/initFlags
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ replace github.com/cosmos/iavl => github.com/cosmos/iavl v0.17.3

replace github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.3-patched

replace github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.44.6-cronos-revert-3
replace github.com/cosmos/cosmos-sdk => github.com/yihuang/cosmos-sdk v0.44.6-cronos-revert-3.0.20220919040112-058151ab2e67

replace github.com/tharsis/ethermint => github.com/crypto-org-chain/ethermint v0.7.2-cronos-16

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crypto-org-chain/cosmos-sdk v0.44.6-cronos-revert-3 h1:EyxkID6wKgk7uodJTMQUJS59Vcpl4uL7yNoVHKfxCek=
github.com/crypto-org-chain/cosmos-sdk v0.44.6-cronos-revert-3/go.mod h1:mvz7GorYj4kEhY8EDTprfY7PX0P3yBH5KPKZNoLeuhU=
github.com/crypto-org-chain/ethermint v0.7.2-cronos-16 h1:uQDmZGApQGnoSxlxqZJlzxrxsnt32fovz5fudL2C0TQ=
github.com/crypto-org-chain/ethermint v0.7.2-cronos-16/go.mod h1:k5Y7SrhjzZl4q90qRsJeGmobbdPpWiBDTphoo5wpYa4=
github.com/crypto-org-chain/go-ethereum v1.10.3-patched h1:kr6oQIYOi2VC8SZwkhlUDZE1Omit/YHVysKMgCB2nes=
Expand Down Expand Up @@ -1405,6 +1403,8 @@ github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62
github.com/yagipy/maintidx v1.0.0/go.mod h1:0qNf/I/CCZXSMhsRsrEPDZ+DkekpKLXAJfsTACwgXLk=
github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE=
github.com/yeya24/promlinter v0.2.0/go.mod h1:u54lkmBOZrpEbQQ6gox2zWKKLKu2SGe+2KOiextY+IA=
github.com/yihuang/cosmos-sdk v0.44.6-cronos-revert-3.0.20220919040112-058151ab2e67 h1:qWlAlxz8qujPvu/uG5FplxQQtinQQkZvuWzVoqKUAkQ=
github.com/yihuang/cosmos-sdk v0.44.6-cronos-revert-3.0.20220919040112-058151ab2e67/go.mod h1:mvz7GorYj4kEhY8EDTprfY7PX0P3yBH5KPKZNoLeuhU=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
Expand Down
Loading

0 comments on commit 3cb886c

Please sign in to comment.