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

Add democracy migration and fix contracts migration #12

Merged
merged 20 commits into from
Jul 2, 2020

Conversation

apopiak
Copy link
Collaborator

@apopiak apopiak commented Jun 29, 2020

This PR migrates democracy for the Edgeware node migration.

Includes migration code inspired by:

Other notes:

Related to hicommonwealth/edgeware-node#164

Copy link
Collaborator

@drewstone drewstone left a comment

Choose a reason for hiding this comment

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

Looks good!

@apopiak
Copy link
Collaborator Author

apopiak commented Jun 30, 2020

Getting "Corrupted State" errors:

2020-06-30 12:34:37.861 tokio-runtime-worker INFO substrate  ✨ Imported #19 (0xddd4…57f6)
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  No BlockHashes to migrate...
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  🕊️  Migrating Account Balances...
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: FreeBalance -> Account
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: ReservedBalance -> Account
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: Vesting
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: Balance::Account -> System::Account
2020-06-30 12:34:38.834 event.loop0 DEBUG runtime  🕊️  Done Account Balances.
2020-06-30 12:34:38.834 event.loop0 DEBUG runtime  🕊️  Migrating Accounts...
2020-06-30 12:34:38.834 event.loop0 DEBUG runtime  2
2020-06-30 12:34:38.834 event.loop0 DEBUG runtime  🕊️  Done Accounts.
2020-06-30 12:34:38.834 event.loop0 DEBUG runtime  🕊️  Migrating Identity.
2020-06-30 12:34:38.834 event.loop0 DEBUG runtime  🕊️  Done Identity.
2020-06-30 12:34:38.836 event.loop0 DEBUG runtime  🕊️  Migrating Finality Tracker.
2020-06-30 12:34:38.836 event.loop0 DEBUG runtime  🕊️  Done Finality Tracker.
2020-06-30 12:34:38.837 event.loop0 DEBUG runtime  ERROR: Corrupted state at [242, 121, 76, 34, 227, 83, 233, 168, 57, 241, 47, 170, 176, 58, 145, 27, 246, 137, 103, 214, 53, 100, 26, 112, 135, 229, 63, 43, 255, 30, 202, 211, 28, 127, 16, 167, 25, 164, 98, 144, 41, 73, 152, 162, 173, 105, 53, 30, 231, 158, 214, 44, 82, 207, 80, 158, 209, 13, 229, 26, 159, 65, 108, 132]
2020-06-30 12:34:38.837 event.loop0 DEBUG runtime  🕊️  Migrating Transaction Payment.
2020-06-30 12:34:38.837 event.loop0 DEBUG runtime  🕊️  Done Transaction Payment.
2020-06-30 12:34:41.111 tokio-runtime-worker INFO substrate  💤 Idle (0 peers), best: #19 (0xddd4…57f6), finalized #17 (0x956a…c384), ⬇ 0.2kiB/s ⬆ 0.2kiB/s
2020-06-30 12:34:42.000 tokio-runtime-worker DEBUG runtime  No BlockHashes to migrate...
2020-06-30 12:34:42.000 tokio-runtime-worker DEBUG runtime  🕊️  Migrating Account Balances...
2020-06-30 12:34:42.000 tokio-runtime-worker DEBUG runtime  Balances: FreeBalance -> Account
2020-06-30 12:34:42.000 tokio-runtime-worker DEBUG runtime  Balances: ReservedBalance -> Account
2020-06-30 12:34:42.000 tokio-runtime-worker DEBUG runtime  Balances: Vesting
2020-06-30 12:34:42.000 tokio-runtime-worker DEBUG runtime  Balances: Balance::Account -> System::Account
2020-06-30 12:34:42.096 tokio-runtime-worker DEBUG runtime  🕊️  Done Account Balances.
2020-06-30 12:34:42.096 tokio-runtime-worker DEBUG runtime  🕊️  Migrating Accounts...
2020-06-30 12:34:42.096 tokio-runtime-worker DEBUG runtime  2
2020-06-30 12:34:42.096 tokio-runtime-worker DEBUG runtime  🕊️  Done Accounts.
2020-06-30 12:34:42.096 tokio-runtime-worker DEBUG runtime  🕊️  Migrating Identity.
2020-06-30 12:34:42.096 tokio-runtime-worker DEBUG runtime  🕊️  Done Identity.
2020-06-30 12:34:42.097 tokio-runtime-worker DEBUG runtime  🕊️  Migrating Finality Tracker.
2020-06-30 12:34:42.097 tokio-runtime-worker DEBUG runtime  🕊️  Done Finality Tracker.
2020-06-30 12:34:42.097 tokio-runtime-worker DEBUG runtime  ERROR: Corrupted state at [242, 121, 76, 34, 227, 83, 233, 168, 57, 241, 47, 170, 176, 58, 145, 27, 246, 137, 103, 214, 53, 100, 26, 112, 135, 229, 63, 43, 255, 30, 202, 211, 28, 127, 16, 167, 25, 164, 98, 144, 41, 73, 152, 162, 173, 105, 53, 30, 231, 158, 214, 44, 82, 207, 80, 158, 209, 13, 229, 26, 159, 65, 108, 132]
2020-06-30 12:34:42.098 tokio-runtime-worker DEBUG runtime  🕊️  Migrating Transaction Payment.
2020-06-30 12:34:42.098 tokio-runtime-worker DEBUG runtime  🕊️  Done Transaction Payment.
2020-06-30 12:34:42.111 tokio-runtime-worker INFO sc_basic_authorship::basic_authorship  🙌 Starting consensus session on top of parent 0xddd49cbd2f04ff98c23029e3a372788a2258a2173f9d0957228acc31d8b857f6
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  BlockNumber: 0
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  🕊️  No BlockHashes to migrate...
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Account Balances...
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  Balances: FreeBalance -> Account
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  Balances: ReservedBalance -> Account
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  Balances: Vesting
2020-06-30 12:34:42.111 tokio-blocking-driver DEBUG runtime  Balances: Balance::Account -> System::Account
2020-06-30 12:34:42.679 tokio-blocking-driver DEBUG runtime  🕊️  Done Account Balances.
2020-06-30 12:34:42.679 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Staking...
2020-06-30 12:34:42.680 tokio-blocking-driver DEBUG runtime  🕊️  Done Staking.
2020-06-30 12:34:42.680 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Accounts...
2020-06-30 12:34:42.681 tokio-blocking-driver DEBUG runtime  2
2020-06-30 12:34:42.681 tokio-blocking-driver DEBUG runtime  🕊️  Done Accounts.
2020-06-30 12:34:42.681 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Identity.
2020-06-30 12:34:42.681 tokio-blocking-driver DEBUG runtime  🕊️  Done Identity.
2020-06-30 12:34:42.685 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Finality Tracker.
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  🕊️  Done Finality Tracker.
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  🕊️  Migrating PhragmenElection...
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  🕊️  Done PhragmenElection.
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Democracy...
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  Democracy: Hasher
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  Democracy: Hasher: ReferendumInfo
2020-06-30 12:34:42.686 tokio-blocking-driver DEBUG runtime  Democracy: Hasher: PublicProps
2020-06-30 12:34:42.687 tokio-blocking-driver DEBUG runtime  Preimages key: [242, 121, 76, 34, 227, 83, 233, 168, 57, 241, 47, 170, 176, 58, 145, 27, 246, 137, 103, 214, 53, 100, 26, 112, 135, 229, 63, 43, 255, 30, 202, 211, 28, 127, 16, 167, 25, 164, 98, 144, 41, 73, 152, 162, 173, 105, 53, 30, 231, 158, 214, 44, 82, 207, 80, 158, 209, 13, 229, 26, 159, 65, 108, 132]
2020-06-30 12:34:42.687 tokio-blocking-driver DEBUG runtime  Democracy: Remove Unused
2020-06-30 12:34:42.690 tokio-blocking-driver DEBUG runtime  Democracy: ReferendumInfo
2020-06-30 12:34:42.690 tokio-blocking-driver DEBUG runtime  🕊️  Done Democracy.
2020-06-30 12:34:42.690 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Transaction Payment.
2020-06-30 12:34:42.691 tokio-blocking-driver DEBUG runtime  🕊️  Done Transaction Payment.
2020-06-30 12:34:42.698 tokio-blocking-driver DEBUG runtime  No BlockHashes to migrate...
2020-06-30 12:34:42.698 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Account Balances...
2020-06-30 12:34:42.698 tokio-blocking-driver DEBUG runtime  Balances: FreeBalance -> Account
2020-06-30 12:34:42.698 tokio-blocking-driver DEBUG runtime  Balances: ReservedBalance -> Account
2020-06-30 12:34:42.698 tokio-blocking-driver DEBUG runtime  Balances: Vesting
2020-06-30 12:34:42.698 tokio-blocking-driver DEBUG runtime  Balances: Balance::Account -> System::Account
2020-06-30 12:34:42.813 tokio-blocking-driver DEBUG runtime  🕊️  Done Account Balances.
2020-06-30 12:34:42.813 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Accounts...
2020-06-30 12:34:42.813 tokio-blocking-driver DEBUG runtime  2
2020-06-30 12:34:42.813 tokio-blocking-driver DEBUG runtime  🕊️  Done Accounts.
2020-06-30 12:34:42.813 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Identity.
2020-06-30 12:34:42.813 tokio-blocking-driver DEBUG runtime  🕊️  Done Identity.
2020-06-30 12:34:42.815 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Finality Tracker.
2020-06-30 12:34:42.815 tokio-blocking-driver DEBUG runtime  🕊️  Done Finality Tracker.
2020-06-30 12:34:42.817 tokio-blocking-driver DEBUG runtime  ERROR: Corrupted state at [242, 121, 76, 34, 227, 83, 233, 168, 57, 241, 47, 170, 176, 58, 145, 27, 246, 137, 103, 214, 53, 100, 26, 112, 135, 229, 63, 43, 255, 30, 202, 211, 28, 127, 16, 167, 25, 164, 98, 144, 41, 73, 152, 162, 173, 105, 53, 30, 231, 158, 214, 44, 82, 207, 80, 158, 209, 13, 229, 26, 159, 65, 108, 132]
2020-06-30 12:34:42.817 tokio-blocking-driver DEBUG runtime  🕊️  Migrating Transaction Payment.
2020-06-30 12:34:42.817 tokio-blocking-driver DEBUG runtime  🕊️  Done Transaction Payment.
2020-06-30 12:34:42.880 tokio-blocking-driver INFO sc_basic_authorship::basic_authorship  🎁 Prepared block for proposing at 20 [hash: 0xd9eb57ef00dbee8148842227b1ea9d5123fdd9000b5217d90bea8e96809abb81; parent_hash: 0xddd4…57f6; extrinsics (2): [0xcd6b…cacf, 0x07bd…d143]]

@apopiak apopiak changed the title [WIP] Add democracy migration Add democracy migration Jul 1, 2020
@apopiak
Copy link
Collaborator Author

apopiak commented Jul 1, 2020

Getting "Corrupted State" errors:

2020-06-30 12:34:37.861 tokio-runtime-worker INFO substrate  ✨ Imported #19 (0xddd4…57f6)
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  No BlockHashes to migrate...
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  🕊️  Migrating Account Balances...
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: FreeBalance -> Account
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: ReservedBalance -> Account
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: Vesting
2020-06-30 12:34:38.555 event.loop0 DEBUG runtime  Balances: Balance::Account -> System::Account
[...]

Solved through rebuilds 🤷

Copy link
Collaborator

@drewstone drewstone left a comment

Choose a reason for hiding this comment

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

Looks good, if every migration is using MaxBlockWeight, does it sum those? Wouldn't that make the weight too larger to go in, in a single tx?

fn on_runtime_upgrade() -> Weight {
for i in 0..=SegmentIndex::get() {
UnderConstruction::migrate_key_from_blake(i);
}
// TODO: determine weight
0
T::MaximumBlockWeight::get()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use babe so not sure how necessary this one is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, probably isn't. Don't think it's worth it to remove it, though.

}

pub fn migrate_hasher<T: Trait>() -> Weight {
// TODO: is this valid?
Copy link
Collaborator

Choose a reason for hiding this comment

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

So far, we haven't had an vetos/cancellations. Should be fine!

}

pub fn migrate_remove_unused_storage<T: Trait>() -> Weight {
// TODO: is this valid?
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we delete things after we move them?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure where VotersFor is defined or if we have it on our substrate commit that mainnet is pegged to. What are the potential reprecussions of removing these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

VotersFor seems empty on current edgeware. (Checked on https://polkadot.js.org/apps/#/chainstate with some indices. referendumCount is 8.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So we delete things after we move them?

Nope, the ones deleted here are not moved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The repercussions I can see are the following: This migration just drops some state that currently doesn't exist on edgeware. If people were to create proposals and vote on them while this migration is in process, some data might be lost. AFAICT this would not corrupt any state, people would just have to vote again.

@apopiak
Copy link
Collaborator Author

apopiak commented Jul 2, 2020

Looks good, if every migration is using MaxBlockWeight, does it sum those? Wouldn't that make the weight too larger to go in, in a single tx?

These upgrades are performed by on_runtime_upgrade and thus are not subject to the same tx limits. It does result in the block being very heavy and thus not any other (non-mandatory) transactions happening during the migration block. But that's what we want as the migration will be quite heavy with all the account migration stuff.

@apopiak
Copy link
Collaborator Author

apopiak commented Jul 2, 2020

So returning T::MaximumBlockWeight in on_runtime_upgrade (or on_initialize) fills the block and keeps regular transactions out.

@apopiak apopiak changed the title Add democracy migration Add democracy migration and fix contrac migration Jul 2, 2020
@apopiak apopiak changed the title Add democracy migration and fix contrac migration Add democracy migration and fix contracts migration Jul 2, 2020
@drewstone drewstone merged commit 0ad4f35 into time-travel Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants