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: state chain upgraded to substrate 2022-05 #1650

Merged
merged 34 commits into from
May 13, 2022

Conversation

dandanlen
Copy link
Collaborator

@dandanlen dandanlen commented May 10, 2022

Old substrate tag: monthly-2021-09+1
New substrate tag: monthly-2022-05

This latter tag has been recreated as chainflip-2022-05 in our substrate fork, and the recent grandpa fix cherry-picked. Our grandpa fork has also been updated.

The main changes to our code:

  • TypeInfo added to all storage types. TypeInfo can be derived alongside Encode and Decode and is required for all types in storage. It allows auto-generated type metadata for front-end tools. See the scale-info docs for more details.
  • MaxEncodedLen has been added where it was easy to add / derive. See here and here for details on MaxEncodedLen. The idea is that every storage item should have statically-determined maximium size. This implies that everywhere we store a Vec or BTreeSet etc. we should convert this to the Bounded* equivalent. The reason for this, as far as I can tell, is to have deterministic worst-case performance bounds for benchmarking. It also allows derivation of the StorageInfo trait, although not sure benefits this brings. Judging by this issue, it seems related to parachains. I considered adding this for our entire runtime to be out of scope for this PR, so for now I have annotated most pallets as without_storage_info - however we may want to slowly move towards enforcing MaxEncodedLen everywhere. I'll raise an issue to track this.
  • Related to the above, Aura and Grandpa now expect a max_authorities parameter. I've set it to 150.
  • AccountId no longer implements default.
  • The benchmarks now contain a SUBSTRATE_REFERENCE_HARDWARE constant - we should update this with out own values.
  • construct_runtime no longer need to list all the items that it exports (Call, Event, Storage..).
  • Calls are now exposed as structs instead of tuples. Note this doesn't impact the encoding, but it makes them easier to read.
  • Events can now be defined as named structs instead of tuples.
  • Errors can now include values, like normal errors.
  • Some minor changes to benchmarking syntax.
  • No more subxt in the Cfe.
  • Bonus content: I added the grandpa rpcs to our node.

Also one last note about secp256k1: there was a conflict because all parity crates, and web3 have updated their dependency to 0.21 while our signing code still uses 0.20. I didn't want to dive too deep into this, so for now have settled on importing two versions of the crate to keep the changes here minimal.

For a full list of substrate changes, see https://github.com/paritytech/substrate/releases.


  • Were any changes to the genesis config of any pallets? Negative.
  • Is types.json up to date? Types.json is no more.
  • Have any new dependencies been added? Lots of dependencies have been updated.
  • Has the external interface been changed? No
  • Do the changes require a runtime upgrade? No - I think? Would suggest rolling this out as part of a runtime+cfe+node upgrade anyway.

@kylezs kylezs linked an issue May 10, 2022 that may be closed by this pull request
Copy link
Contributor

@kylezs kylezs left a comment

Choose a reason for hiding this comment

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

Will let some other eyes go over this ofc.

state-chain/chains/src/eth.rs Show resolved Hide resolved
state-chain/pallets/cf-staking/src/lib.rs Show resolved Hide resolved
state-chain/runtime/src/chainflip.rs Outdated Show resolved Hide resolved
state_chain_runtime::Call::from(extrinsic.clone()).encode(),
));
let expected_hash = BlakeTwo256::hash_of(&unsigned_tx);
let call = call.into();
Copy link
Contributor

Choose a reason for hiding this comment

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

In the signed version above, you changed it so in the errors the call variable is formatted as it is passed into the function. Instead of turning the call into a state_chain_runtime::Call (using the into first) and then formatting that. I like this change, but you also need to do the same thing here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't do it the same way here because we need the state_chain_runtime::Call to calculate the expected_hash. I agree it's better to be consistent though. I'll re-shuffle a bit.

Add AURA digest and change block execution order.
@dandanlen
Copy link
Collaborator Author

Note - runtime integration tests are currently failing - would like to merge recent changes from PR paritytech/substrate#1538 into develop and then merge develop back into this before fixing them.

}
{{~/each}}
}
{{#if (eq pallet "frame_system")}}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you format the file in this way it will produce rust files with no valid format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you try it?

I merged this from core substrate - apparently there used to be a bug in the handlebars implementation that required pre/post-fixing ~ everywhere to handle newlines properly. This should no longer be required. Maybe we need to bump our version of handlebars?

Copy link
Collaborator Author

@dandanlen dandanlen May 11, 2022

Choose a reason for hiding this comment

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

Do you mean the extra tab of indentation? I'll take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the problem is the generated weights files will end up like the format in the hbs file. Back then when I created this I had to ensure that the file has a proper format that matches our fmt rules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like format-on-save messed up the formatting. I've reverted it and fixed the formatting, should be good now.

frame_system::CheckEra::from(Era::Immortal),
frame_system::CheckNonce::from(nonce),
frame_system::CheckWeight::new(),
state_chain_runtime::ChargeTransactionPayment::from(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this zero mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the tip - normally this is used to increase transaction priority, but we ignore it in our runtime since there's no fee market, and we don't want anyone manipulating the execution order.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(I'll add a comment)

state_chain_runtime::Call::from(extrinsic.clone()).encode(),
));
let expected_hash = BlakeTwo256::hash_of(&unsigned_tx);
let runtime_call = call.clone().into();
Copy link
Contributor

Choose a reason for hiding this comment

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

You could inline this like you did above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how, I need it in two places, once to calculate the expected_hash, then again to construct the extrinsic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah wait I think I made a mistake in the encoding, i need the hash of the extrinsic, not of the call.

See 762810b

@morelazers
Copy link

Because this is such a significant PR I'm trying out the successful builds with testnet-tools.

There's some strange behaviour in the engine when the chain requests a threshold signature, the parties immediately respond with a failure report.

image

@kylezs kylezs mentioned this pull request May 12, 2022
7 tasks
@morelazers
Copy link

Error reported in #1650 (comment) is actually due to another problem (#1658).

I'll double check again in the morning, but I think this one is good to merge otherwise. Awesome stuff.

@dandanlen dandanlen merged commit 3ad37c1 into develop May 13, 2022
@dandanlen dandanlen deleted the feat/integrate-substrate-monthly-2022-05 branch May 13, 2022 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SC-2669] Merge in Substrate SCALEInfo patch
6 participants