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

Problem: state streaming is not supported in old versions #700

Merged
merged 5 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Build
on:
pull_request:
push:
branches:
- main
- release/**

jobs:
cleanup-runs:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

### Improvements

- [#700](https://github.com/crypto-org-chain/cronos/pull/700) Integrate file streamer to stream the states of legacy blocks.

*May 12, 2022*

## v0.6.11

### Improvements

- [#470](https://github.com/crypto-org-chain/cronos/pull/470) Run the tasks in `fix-unlucky-tx` command in parallel.
- [#472](https://github.com/crypto-org-chain/cronos/pull/472) `fix-unlucky-tx` command supports `null` tendermint tx indexer.
- [#524](https://github.com/crypto-org-chain/cronos/pull/524) Fix tendermint duplicated tx issue.
Expand Down
32 changes: 32 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,32 @@ 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)
if err := service.Stream(wg); err != nil {
panic(err)
}
}

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"
yihuang marked this conversation as resolved.
Show resolved Hide resolved
)

// 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"`
}
yihuang marked this conversation as resolved.
Show resolved Hide resolved
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/crypto-org-chain/cosmos-sdk v0.44.6-cronos-revert-4
yihuang marked this conversation as resolved.
Show resolved Hide resolved

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,8 @@ 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/cosmos-sdk v0.44.6-cronos-revert-4 h1:oUP8cdB83JuHnHLh0nXnEiXYBvlQcKg+uuMllB3mtLM=
github.com/crypto-org-chain/cosmos-sdk v0.44.6-cronos-revert-4/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
Loading