Skip to content

Commit

Permalink
make basic collator aware of last included block [Backport to 0.5.2] (#…
Browse files Browse the repository at this point in the history
…473)

* make basic collator aware of last included block

* update node verison
  • Loading branch information
girazoki authored Mar 25, 2024
1 parent 8cc97ba commit 07be0f3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 42 additions & 1 deletion client/consensus/src/collators/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use {
},
cumulus_client_consensus_proposer::ProposerInterface,
cumulus_primitives_core::{
relay_chain::{BlockId as RBlockId, Hash as PHash},
relay_chain::{BlockId as RBlockId, Hash as PHash, OccupiedCoreAssumption},
PersistedValidationData,
},
cumulus_relay_chain_interface::RelayChainInterface,
Expand Down Expand Up @@ -158,6 +158,19 @@ pub async fn run<Block, P, BI, CIDP, Client, RClient, SO, Proposer, CS, GOH>(

let parent_hash = parent_header.hash();

// Evaluate whether we can build on top
// The requirement is that the parent_hash is the last included block in the relay
let can_build = can_build_upon_included::<Block, _>(
parent_hash,
&collator.relay_client,
params.para_id,
*request.relay_parent(),
)
.await;
if !can_build {
continue;
}

// Check whether we can build upon this block
if !collator
.collator_service()
Expand Down Expand Up @@ -261,3 +274,31 @@ pub async fn run<Block, P, BI, CIDP, Client, RClient, SO, Proposer, CS, GOH>(
last_processed_slot = *claim.slot();
}
}

// Checks whether we can build upon the last included block
// Essentially checks that the latest head we are trying to build
// is the one included in the relay
async fn can_build_upon_included<Block: BlockT, RClient>(
parent_hash: Block::Hash,
relay_client: &RClient,
para_id: ParaId,
relay_parent: PHash,
) -> bool
where
RClient: RelayChainInterface + Send + Clone + 'static,
{
let included_header = relay_client
.persisted_validation_data(relay_parent, para_id, OccupiedCoreAssumption::TimedOut)
.await;

if let Ok(Some(included_header)) = included_header {
let decoded = Block::Header::decode(&mut &included_header.parent_head.0[..]).ok();
if let Some(decoded_header) = decoded {
let included_hash = decoded_header.hash();
if parent_hash == included_hash {
return true;
}
}
}
false
}
2 changes: 1 addition & 1 deletion container-chains/templates/frontier/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build = "build.rs"
description = "Frontier container chain template node"
edition = "2021"
license = "GPL-3.0-only"
version = "0.5.1"
version = "0.5.2"

[dependencies]
async-io = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion container-chains/templates/simple/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build = "build.rs"
description = "Simple container-chain template node"
edition = "2021"
license = "GPL-3.0-only"
version = "0.5.1"
version = "0.5.2"

[dependencies]
async-io = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build = "build.rs"
description = "Tanssi node implementation"
edition = "2021"
license = "GPL-3.0-only"
version = "0.5.1"
version = "0.5.2"

[dependencies]
async-io = { workspace = true }
Expand Down

0 comments on commit 07be0f3

Please sign in to comment.