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

feat/Add memiavl based storage #2973

Closed
wants to merge 5 commits into from
Closed

Conversation

chillyvee
Copy link
Contributor

@chillyvee chillyvee commented Mar 1, 2024

Description

Add memiavl storage support

  • Faster state-sync recovery
  • Reduced disk i/o and space usage

No operational change when memiavl is not enabled.

Note github.com/crypto-org-chain/cronos requires go 1.22

Statesync, Snapshot, Validation works well in Theta Testnet as provided in this branch against v15.0.0-rc3
https://github.com/chillyvee/gaia/tree/cv15.0.0-rc3-memiavl

Quickly test on theta testnet with app.toml as follows:

[memiavl]
  async-commit-buffer = 0
  cache-size = 1000
  enable = true
  snapshot-interval = 61
  snapshot-keep-recent = 3
  zero-copy = false

[state-sync]
  snapshot-interval = 61
  snapshot-keep-recent = 3

The statesync chunk apply time for Theta Testnet is approximately:

  • 70 minutes for goleveldb (as is - on test server)
  • 2 minutes for memiavl (same server)

This work follows a general effort to provide options to increase the speed of statesync and improved i/o utilization.

Related discussion here:
cosmos/iavl#878

Author Checklist

I have...

  • Included the correct type prefix in the PR title
  • Added ! to the type prefix if API, client, or state breaking change (i.e., requires minor or major version bump)
  • Targeted the correct branch (see PR Targeting)
  • Provided a link to the relevant issue or specification
  • Followed the guidelines for building SDK modules
  • Included the necessary unit and integration tests
  • Added a changelog entry in .changelog (for details, see contributing guidelines)
  • Included comments for documenting Go code
  • Updated the relevant documentation or specification
  • Reviewed "Files changed" and left comments if necessary
  • Confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage

go.mod Outdated
@@ -221,8 +233,13 @@ replace (
// Use special SDK v0.47.x release with support for both ICS and LSM
github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.47.10-ics-lsm

// use memiavl for faster storage
github.com/cosmos/cosmos-sdk/store => github.com/crypto-org-chain/cronos/store v0.0.5-0.20240301012710-e9bb006c8d14
github.com/cosmos/cosmos-sdk/versiondb => github.com/crypto-org-chain/cronos/versiondb v0.0.5-0.20240301012710-e9bb006c8d14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is not needed for memiavl alone.

Copy link
Contributor Author

@chillyvee chillyvee Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yihuang for the review and comment

Would it be useful for RPC/API providers that need to be able to provide query results with data from different heights?

Or is this only useful for creating statesync snapshots on a verison that memiavl does not snapshot?

Copy link

@yihuang yihuang Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful for RPC/API providers that need to be able to provide query results with data from different heights?

It do support historical state/proof queries, and the supported range is determined by the memiavl.snapshot-keep-recent config, it support historical query from the oldest available snapshot to latest height.

Copy link

@yihuang yihuang Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have to say, historical query is not that efficient with memiavl, I'm not sure how it performs under load, we use versiondb aka. state storage to provide state queries, only use memiavl to provide proof queries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If historical state/proof query support is removed (no go mod replace), will it case any problems for validators or users of API/RPC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep versiondb to help the RPC node providers. The store mod replace will be removed.

Copy link

@yihuang yihuang Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this only useful for creating statesync snapshots on a verison that memiavl does not snapshot?

You can't create state sync snapshot from versiondb, because it don't have information for the branch nodes, only leaf key value pairs.
and memiavl do support creating state sync snapshots for all the intermediate versions between the oldest snapshot and the latest height.

Copy link
Contributor Author

@chillyvee chillyvee Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification. For others reviewing, we discussed how to enable snapshots for intermediate versions here: cosmos/iavl#878 (comment)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification. For others reviewing, we discussed how to enable snapshots for intermediate versions here: cosmos/iavl#878 (comment)

maybe you can add some comments for the individual parameters here for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments on parameters added

go.mod Outdated
@@ -221,8 +233,13 @@ replace (
// Use special SDK v0.47.x release with support for both ICS and LSM
github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.47.10-ics-lsm

// use memiavl for faster storage
github.com/cosmos/cosmos-sdk/store => github.com/crypto-org-chain/cronos/store v0.0.5-0.20240301012710-e9bb006c8d14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this replacement is not needed, the github.com/crypto-org-chain/cronos/store is not a replacement for the cosmos store package.

Copy link
Contributor Author

@chillyvee chillyvee Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to NOT replace cosmos-sdk/store and only use cronos/store for the helper function?

https://github.com/cosmos/gaia/pull/2973/files#diff-0f1d2976054440336a576d47a44a37b80cdf6701dd9113012bce0e3c425819b7R61

memiavlstore "github.com/crypto-org-chain/cronos/store"
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, baseAppOptions)

Copy link

@yihuang yihuang Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not supposed to replace cosmos-sdk/store at all, it's a different package ;D
it implements the same interfaces, and hook into cosmos-sdk to replace the default root multistore.

go.mod Outdated
@@ -16,6 +18,7 @@ require (
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.2
github.com/cosmos/ibc-go/v7 v7.3.2
github.com/cosmos/interchain-security/v3 v3.3.0
github.com/crypto-org-chain/cronos/store v0.0.0-00010101000000-000000000000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
github.com/crypto-org-chain/cronos/store v0.0.0-00010101000000-000000000000
github.com/crypto-org-chain/cronos/store v0.0.5-0.20240301012710-e9bb006c8d14

I think you can pin the version here, and remove the replacement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try again. go mod tidy kept on putting zeros.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be able to fix after removing the replace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@chillyvee chillyvee marked this pull request as ready for review March 1, 2024 16:56
@chillyvee chillyvee force-pushed the cv/memiavl branch 2 times, most recently from 3ca7cd9 to 071abe4 Compare March 7, 2024 17:59
Copy link
Contributor

@MSalopek MSalopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution and opening a PR.

I went over the PR and the linked issues/PRs on other repos.

I'm not certain we can just add it - we need to do more extensive testing.

I'm not certain the cosmos-sdk/versiondb needs to be replaced.

I need more information to figure out what this means for future chain upgrades:

  • Can we upgrade to v16 and add these without issues?
  • Is this a purely optional feature?
  • Does this impact upgrade speed and how?

If we add it, does it affect all users?

With this, we would need some docs or guides to communicate to validators how and why use this. Would you be able to provide a more comprehensive guide?

@chillyvee
Copy link
Contributor Author

chillyvee commented Mar 26, 2024

I'm not certain the cosmos-sdk/versiondb needs to be replaced.

@yihuang - Do you have a chance to comment on this?

I need more information to figure out what this means for future chain upgrades:

memiavl is an alternate key value storage db. On Jackal chain, running memiavl prior to upgrade and after upgrade resulted in a fast upgrade with no problems.

Mixing db drivers before and after upgrade will not work. Similar as switching goleveldb to rocksdb. Must delete local database storage and resync when database drivers change.

Is this a purely optional feature?

Purely optional and opt-in by configuration.

If we add it, does it affect all users?

Default opt-out. PR is configured for Opt-in-only by operators who are interested.

Does this impact upgrade speed and how?

Upgrade speed should be much faster. The one hour downtime for the previous hub upgrade would be greatly reduced. If you prefer an actual tested time, can provision a node an give an actual time.

The statesync chunk apply time for Theta Testnet is approximately:

70 minutes for goleveldb (as is - on test server)
2 minutes for memiavl (same server)

Upgrades changing key value pairs should have similar performance improvements. Statesync is an upgrade from height 0 to current head height.

Can we upgrade to v16 and add these without issues?

Typically no issue seen adding. memiavl needs to be active

With this, we would need some docs or guides to communicate to validators how and why use this. Would you be able to provide a more comprehensive guide?

If this PR is acceptable, we can allocate time to create usage documentation prior to merge.

@yihuang
Copy link

yihuang commented Mar 26, 2024

I'm not certain the cosmos-sdk/versiondb needs to be replaced.
@yihuang - Do you have a chance to comment on this?

Yes, unneeded, there's no this package in the first place.

@chillyvee
Copy link
Contributor Author

updated code to remove version db as suggested by @yihuang

go 1.22 required

go: github.com/crypto-org-chain/cronos/[email protected] requires go >= 1.22; switching to go1.22.1

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 13, 2024
@github-actions github-actions bot closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants