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: recent improvements not backport to v1.2.x #1381

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## UNRELEASED

### Improvements

* (test) [#1380](https://github.com/crypto-org-chain/cronos/pull/1380) Upgrade cosmovisor to 1.5.0 in integration test.
* (versiondb) [#1379](https://github.com/crypto-org-chain/cronos/pull/1379) Flush versiondb when graceful shutdown, make rocksdb upgrade smooth.

yihuang marked this conversation as resolved.
Show resolved Hide resolved
*April 8, 2024*

## v1.2.0-rc1
Expand Down
24 changes: 16 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ import (
// this line is used by starport scaffolding # stargate/app/moduleImport

memiavlstore "github.com/crypto-org-chain/cronos/store"
memiavlrootmulti "github.com/crypto-org-chain/cronos/store/rootmulti"
"github.com/crypto-org-chain/cronos/v2/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client"
cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
Expand Down Expand Up @@ -370,6 +369,8 @@ type App struct {

// module configurator
configurator module.Configurator

qms storetypes.MultiStore
}

// New returns a reference to an initialized chain.
Expand Down Expand Up @@ -860,10 +861,9 @@ func New(

// wire up the versiondb's `StreamingService` and `MultiStore`.
streamers := cast.ToStringSlice(appOpts.Get("store.streamers"))
var qms sdk.MultiStore
if slices.Contains(streamers, "versiondb") {
var err error
qms, err = app.setupVersionDB(homePath, keys, tkeys, memKeys)
app.qms, err = app.setupVersionDB(homePath, keys, tkeys, memKeys)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -900,8 +900,8 @@ func New(
tmos.Exit(err.Error())
}

if qms != nil {
v1 := qms.LatestVersion()
if app.qms != nil {
v1 := app.qms.LatestVersion()
v2 := app.LastBlockHeight()
if v1 > 0 && v1 < v2 {
// try to prevent gap being created in versiondb
Expand Down Expand Up @@ -1197,11 +1197,19 @@ func VerifyAddressFormat(bz []byte) error {

// Close will be called in graceful shutdown in start cmd
func (app *App) Close() error {
err := app.BaseApp.Close()
errs := []error{app.BaseApp.Close()}

// flush the versiondb
if closer, ok := app.qms.(io.Closer); ok {
errs = append(errs, closer.Close())
}

if cms, ok := app.CommitMultiStore().(*memiavlrootmulti.Store); ok {
return stderrors.Join(err, cms.Close())
// mainly to flush memiavl
if closer, ok := app.CommitMultiStore().(io.Closer); ok {
errs = append(errs, closer.Close())
}

err := stderrors.Join(errs...)
app.Logger().Info("Application gracefully shutdown", "error", err)
return err
}
10 changes: 0 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@
go = super.go_1_22;
test-env = final.callPackage ./nix/testenv.nix { };
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = drv: final.runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with final.buildPackages; [ gnutar gzip ];
} ''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
'';
bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { cronosd = drv; };
} // (with final;
let
Expand Down
11 changes: 6 additions & 5 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ let
# v1.1.1
released = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
current = pkgs.callPackage ../../. { };
farm = pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis/bin"; path = "${released0}/bin"; }
{ name = "v1.1.0/bin"; path = "${released}/bin"; }
{ name = "v1.2/bin"; path = "${current}/bin"; }
];
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released0; }
{ name = "v1.1.0"; path = released; }
{ name = "v1.2"; path = current; }
]
pkgs.make-tarball farm
25 changes: 22 additions & 3 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ def post_init(path, base_port, config):
chain_id,
data / SUPERVISOR_CONFIG_FILE,
lambda i, _: {
"command": f"cosmovisor start --home %(here)s/node{i}",
"environment": f"DAEMON_NAME=cronosd,DAEMON_HOME=%(here)s/node{i}",
"command": f"cosmovisor run start --home %(here)s/node{i}",
"environment": (
"DAEMON_NAME=cronosd,"
"DAEMON_SHUTDOWN_GRACE=1m,"
"UNSAFE_SKIP_BACKUP=true,"
f"DAEMON_HOME=%(here)s/node{i}"
),
},
)

Expand All @@ -71,10 +76,24 @@ def setup_cronos_test(tmp_path_factory):
"nix-build",
Path(__file__).parent / f"configs/{nix_name}.nix",
"-o",
path / "upgrades",
path / "upgrades.tar.gz",
]
print(*cmd)
subprocess.run(cmd, check=True)

# extract the tarball so the directory is writable.
(path / "upgrades").mkdir()
subprocess.run(
[
"tar",
"xfz",
path / "upgrades.tar.gz",
"-C",
path / "upgrades",
],
check=True,
)

# init with genesis binary
with contextmanager(setup_custom_cronos)(
path,
Expand Down
17 changes: 17 additions & 0 deletions nix/build_overlay.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# some basic overlays nessesary for the build
final: super: {
rocksdb = final.callPackage ./rocksdb.nix { };

# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = final.callPackage
({ buildPackages
, runCommand
}: drv: runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with buildPackages; [ gnutar gzip ];
}
''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
''
)
{ };
}
21 changes: 21 additions & 0 deletions nix/cosmovisor.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ buildGoModule
, fetchFromGitHub
}:

let
version = "1.5.0";
cosmos-sdk = fetchFromGitHub {
owner = "cosmos";
repo = "cosmos-sdk";
rev = "tools/cosmovisor/v${version}";
hash = "sha256-Ov8FGpDOcsqmFLT2s/ubjmTXj17sQjBWRAdxlJ6DNEY=";
};
in
buildGoModule rec {
name = "cosmovisor";
version = "1.5.0";
src = cosmos-sdk + "/tools/cosmovisor";
subPackages = [ "./cmd/cosmovisor" ];
vendorHash = "sha256-IkPnnfkofn5w8Oa/uzGxgI1eb5RrJ9haNgj4mBXF+n8=";
doCheck = false;
}
8 changes: 1 addition & 7 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ import sources.nixpkgs {
})
(_: pkgs: { test-env = pkgs.callPackage ./testenv.nix { }; })
(_: pkgs: {
cosmovisor = pkgs.buildGo120Module rec {
name = "cosmovisor";
src = sources.cosmos-sdk + "/cosmovisor";
subPackages = [ "./cmd/cosmovisor" ];
vendorHash = "sha256-OAXWrwpartjgSP7oeNvDJ7cTR9lyYVNhEM8HUnv3acE=";
doCheck = false;
};
cosmovisor = pkgs.callPackage ./cosmovisor.nix { };
})
(_: pkgs: {
rly = pkgs.buildGo120Module rec {
Expand Down
12 changes: 0 additions & 12 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
"url": "https://github.com/crypto-org-chain/chain-main/archive/04e8e094b7d51a8cf92b74c789394b7b34987b10.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"cosmos-sdk": {
"branch": "v0.45.0",
"description": ":chains: A Framework for Building High Value Public Blockchains :sparkles:",
"homepage": "https://cosmos.network/",
"owner": "cosmos",
"repo": "cosmos-sdk",
"rev": "b6c77e6c819f8a51166649eaef125d1bfb276f04",
"sha256": "09ns4yfxyfi7c7n5g69zv32m1rdssdl48c1akmv1y2vz6ayz4v02",
"type": "tarball",
"url": "https://github.com/cosmos/cosmos-sdk/archive/b6c77e6c819f8a51166649eaef125d1bfb276f04.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"dapptools": {
"branch": "master",
"description": "Dapp, Seth, Hevm, and more",
Expand Down
5 changes: 5 additions & 0 deletions versiondb/multistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,8 @@ func (s *MultiStore) LatestVersion() int64 {
}
return version
}

// Close will flush the versiondb
func (s *MultiStore) Close() error {
return s.versionDB.Flush()
}
10 changes: 10 additions & 0 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ func (s Store) Import(version int64, ch <-chan versiondb.ImportEntry) error {
return s.SetLatestVersion(version)
}

func (s Store) Flush() error {
opts := grocksdb.NewDefaultFlushOptions()
defer opts.Destroy()

return errors.Join(
s.db.Flush(opts),
s.db.FlushCF(s.cfHandle, opts),
)
}

func newTSReadOptions(version *int64) *grocksdb.ReadOptions {
var ver uint64
if version == nil {
Expand Down
4 changes: 4 additions & 0 deletions versiondb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type VersionStore interface {

// Import the initial state of the store
Import(version int64, ch <-chan ImportEntry) error

// Flush wal logs, and make the changes persistent,
// mainly for rocksdb version upgrade, sometimes the wal format is not compatible.
Flush() error
}

type ImportEntry struct {
Expand Down
Loading