Skip to content

Commit

Permalink
Merge pull request Magport#60 from sulijia/polkadot-v1.7.0
Browse files Browse the repository at this point in the history
Coretime function adapted to Polkadot-SDK 1.7.0
  • Loading branch information
Acaishiba authored Mar 25, 2024
2 parents 8c4e46b + 6a7edc8 commit 195c864
Show file tree
Hide file tree
Showing 12 changed files with 17,855 additions and 69,512 deletions.
14 changes: 6 additions & 8 deletions client/consensus/aura/src/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ where
inherent_data: (ParachainInherentData, InherentData),
proposal_duration: Duration,
max_pov_size: usize,
) -> Result<(Collation, ParachainBlockData<Block>, Block::Hash), Box<dyn Error + Send + 'static>>
{
) -> Result<
Option<(Collation, ParachainBlockData<Block>, Block::Hash)>,
Box<dyn Error + Send + 'static>,
> {
let mut digest = additional_pre_digest.into().unwrap_or_default();
digest.push(slot_claim.pre_digest.clone());

Expand All @@ -213,11 +215,7 @@ where
.map_err(|e| Box::new(e) as Box<dyn Error + Send>)?;

let proposal = match maybe_proposal {
None => {
return Err(
Box::<dyn Error + Send + Sync>::from("None proposal") as Box<dyn Error + Send>
)
}, //Ok(None),
None => return Ok(None),
Some(p) => p,
};

Expand Down Expand Up @@ -265,7 +263,7 @@ where
);
}

Ok((collation, block_data, post_hash))
Ok(Some((collation, block_data, post_hash)))
} else {
Err(Box::<dyn Error + Send + Sync>::from("Unable to produce collation")
as Box<dyn Error + Send>)
Expand Down
39 changes: 28 additions & 11 deletions client/consensus/aura/src/collators/on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// along with Magnet. If not, see <http://www.gnu.org/licenses/>.

use codec::{Codec, Decode};
use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
use cumulus_client_collator::{
relay_chain_driven::CollationRequest, service::ServiceInterface as CollatorServiceInterface,
};
use cumulus_client_consensus_common::ParachainBlockImportMarker;
use cumulus_client_consensus_proposer::ProposerInterface;
use cumulus_primitives_core::{
Expand All @@ -30,6 +32,7 @@ use polkadot_primitives::{CollatorPair, Id as ParaId};
use cumulus_primitives_core::PersistedValidationData;
use futures::lock::Mutex;
use futures::prelude::*;
use futures::{channel::mpsc::Receiver, prelude::*};
use magnet_primitives_order::OrderRecord;
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf};
use sc_consensus::BlockImport;
Expand All @@ -43,7 +46,6 @@ use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member};
use std::{convert::TryFrom, sync::Arc, time::Duration};

/// Parameters for [`run`].
pub struct Params<BI, CIDP, Client, RClient, SO, Proposer, CS> {
/// Inherent data providers. Only non-consensus inherent data should be provided, i.e.
Expand Down Expand Up @@ -76,6 +78,10 @@ pub struct Params<BI, CIDP, Client, RClient, SO, Proposer, CS> {
pub collator_service: CS,
/// The amount of time to spend authoring each block.
pub authoring_duration: Duration,
/// Receiver for collation requests. If `None`, Aura consensus will establish a new receiver.
/// Should be used when a chain migrates from a different consensus algorithm and was already
/// processing collation requests before initializing Aura.
pub collation_request_receiver: Option<Receiver<CollationRequest>>,
}

/// Run bare Aura consensus as a relay-chain-driven collator.
Expand Down Expand Up @@ -110,12 +116,17 @@ where
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
{
async move {
let mut collation_requests = cumulus_client_collator::relay_chain_driven::init(
params.collator_key,
params.para_id,
params.overseer_handle,
)
.await;
let mut collation_requests = match params.collation_request_receiver {
Some(receiver) => receiver,
None => {
cumulus_client_collator::relay_chain_driven::init(
params.collator_key,
params.para_id,
params.overseer_handle,
)
.await
},
};

let mut collator = {
let params = crate::collator::Params {
Expand Down Expand Up @@ -191,7 +202,7 @@ where
)
.await
);
let (collation, _, post_hash) = try_request!(
let maybe_collation = try_request!(
collator
.collate(
&parent_header,
Expand All @@ -208,8 +219,14 @@ where
.await
);

let result_sender = Some(collator.collator_service().announce_with_barrier(post_hash));
request.complete(Some(CollationResult { collation, result_sender }));
if let Some((collation, _, post_hash)) = maybe_collation {
let result_sender =
Some(collator.collator_service().announce_with_barrier(post_hash));
request.complete(Some(CollationResult { collation, result_sender }));
} else {
request.complete(None);
tracing::debug!(target: crate::LOG_TARGET, "No block proposal");
}
}
}
}
24 changes: 12 additions & 12 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ fn testnet_genesis(
],
// Genesis metadata: Vec<(id, name, symbol, decimals)>
"metadata": vec![
(1, "asset-1", "ALT1", 18),
(2, "asset-2", "ALT2", 18),
(1, b"asset-1".to_vec(), b"ALT1".to_vec(), 18),
(2, b"asset-2".to_vec(), b"ALT2".to_vec(), 18),
],
// Genesis accounts: Vec<(id, account_id, balance)>
"accounts": vec![
(1, alice, 500_000_000_0000_0000_0000u128),
(2, bob, 500_000_000_0000_0000_0000u128),
],
},
"assets_bridge": {
"admin_key": Some(root.clone()),
"assetsBridge": {
"adminKey": Some(root.clone()),
},
"council": {
"members": endowed_accounts
Expand All @@ -250,12 +250,12 @@ fn testnet_genesis(
.filter_map(|(idx, acc)| if idx % 2 == 0 { Some(acc.clone()) } else { None })
.collect::<Vec<_>>(),
},
"parachain_info": {
"parachain_id": id,
"parachainInfo": {
"parachainId": id,
},
"collator_selection": {
"collatorSelection": {
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacy_bond": EXISTENTIAL_DEPOSIT * 16,
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
},
"session": {
"keys": invulnerables
Expand All @@ -271,14 +271,14 @@ fn testnet_genesis(
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this.
"polkadot_xcm": {
"safe_xcm_version": Some(SAFE_XCM_VERSION),
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": { "key": Some(root.clone()) },

// EVM compatibility
"evm_chain_id": {
"chain_id": u64::from(u32::from(id)),
"evmChainId": {
"chainId": u64::from(u32::from(id)),
},

"evm": { "accounts": evm_accounts },
Expand Down
Loading

0 comments on commit 195c864

Please sign in to comment.