Skip to content

Conversation

@haerdib
Copy link
Contributor

@haerdib haerdib commented Nov 10, 2021

Seems to work quite well: For every parentchain block we get 20 sidechain block events.
grafik

Introduces the following changes:

closes #457

@haerdib haerdib force-pushed the separate-block-confirmations branch from 9e45e6a to 386000b Compare November 10, 2021 12:49
@haerdib haerdib self-assigned this Nov 10, 2021
account: AccountId,
amount: Amount,
shard: &ShardIdentifier,
calls: &mut Vec<OpaqueCall>,
Copy link
Contributor Author

@haerdib haerdib Nov 10, 2021

Choose a reason for hiding this comment

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

Removed this input parameter, as there will never(!) be a new OpaqueCall introduced during Stf::execute of a shielding extrsinic. (New OpaqueCall is only issued during execute when calling "unshield")

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying this ☺️

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, good catch. 🛩️

@haerdib haerdib requested review from clangenb and murerfel and removed request for clangenb November 10, 2021 13:24
sp-utils = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
#beefy-merkle-tree = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", features = "keccak" }
Copy link
Contributor Author

@haerdib haerdib Nov 10, 2021

Choose a reason for hiding this comment

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

That's the ugly part here: substrate actually has a no-std compatible merkle tree primitives crate: https://github.com/paritytech/substrate/tree/master/frame/beefy-mmr/primitives

However, this was introduced on 23rd of September. We are not yet on this substrate commit. Can you agree with this temporary solution and to remove it once we are on this commit? If yes, I'll create an appropriate issue ofc.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's well documented and even has a corresponding issue, that's totally fine for me 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine too. 👍

@@ -0,0 +1,229 @@
// This file is part of Substrate.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@haerdib haerdib force-pushed the separate-block-confirmations branch from f1773ad to 5e49a19 Compare November 10, 2021 14:04
Comment on lines 1105 to 1109
let xt_block = [TEEREX_MODULE, BLOCK_CONFIRMED];
let opaque_call =
OpaqueCall::from_tuple(&(xt_block, shard, block_hash, state_hash_new.encode()));
let opaque_call = proposed_sidechain_block_extrinsic(shard, block_hash);
Copy link
Contributor

Choose a reason for hiding this comment

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

so we now use the sidechain block hash instead of the state hash for this extrinsic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly. State hash has been removed from the extrinsic as it didn't have any use case at all (#457)

Comment on lines 1113 to 1045
/// Creates a proposed_sidechain_block extrinsic for a given shard id and sidechain block hash.
fn proposed_sidechain_block_extrinsic(shard_id: ShardIdentifier, block_hash: H256) -> OpaqueCall {
OpaqueCall::from_tuple(&([TEEREX_MODULE, PROPOSED_SIDECHAIN_BLOCK], shard_id, block_hash))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here, I'd prefer the create_ in front. In a future refactoring, we could put these into the extrinsics factory component or something similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already changed. :) Yes, definitely - but I think the whole lib.rs (just like in PR #500 but also for parentchain syncing) should be refactored (but that's your call).. I didn't want to start something that will be changed in the future anyway. If you have a place they belong to already, I'll gladly move them.

Comment on lines 426 to 452
fn empty_extrinsic_vec_gives_zero_merkle_root() {
// given
let block_hash = H256::from([1; 32]);
let extrinsics = Vec::new();
let expected_call =
([TEEREX_MODULE, PROCESSED_PARENTCHAIN_BLOCK], block_hash, H256::default()).encode();

// when
let call = crate::processed_parentchain_block_extrinsic(block_hash, extrinsics);

// then
assert_eq!(call.0, expected_call);
}

fn some_extrinsics_vec_give_non_zero_merkle_root() {
// given
let block_hash = H256::from([1; 32]);
let extrinsics = vec![H256::from([4; 32]), H256::from([9; 32])];
let zero_root_call =
([TEEREX_MODULE, PROCESSED_PARENTCHAIN_BLOCK], block_hash, H256::default()).encode();

// when
let call = crate::processed_parentchain_block_extrinsic(block_hash, extrinsics);

// then
assert_ne!(call.0, zero_root_call);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Always nice to have tests for the changes you make 🥳

Comment on lines +1169 to +1099
fn hash_of<T: Encode>(xt: T) -> H256 {
blake2_256(&xt.encode()).into()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a function that we have duplicated multiple times I believe. We should at some point put it in a primitives crate where it can be properly shared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aye.. But I didn't want to touch too much code, in fear of the rebase conflicts 😨

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should simply implement hash on the extrinsic in the api-client. 😄

Copy link
Contributor

@murerfel murerfel left a comment

Choose a reason for hiding this comment

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

LGTM - and if the checks pass, it should be fine ☺️ thanks for your perseverance when it comes to good comments 🚀

Copy link
Contributor

@clangenb clangenb 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 to me. 👍

account: AccountId,
amount: Amount,
shard: &ShardIdentifier,
calls: &mut Vec<OpaqueCall>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, good catch. 🛩️

sp-utils = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
#beefy-merkle-tree = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master", features = "keccak" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine too. 👍

if let Err(e) = validator.submit_simple_header(
validator.num_relays(),
signed_block.block.header().clone(),
block.header().clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nice optimization.

Comment on lines +1169 to +1099
fn hash_of<T: Encode>(xt: T) -> H256 {
blake2_256(&xt.encode()).into()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should simply implement hash on the extrinsic in the api-client. 😄

@haerdib haerdib merged commit e08bf0c into master Nov 11, 2021
@haerdib haerdib deleted the separate-block-confirmations branch November 11, 2021 07:33
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.

Clarify Block & Call Confirmation

4 participants