mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Fix block announcement validation (#171)
* Fix block announce * Fix compilation
This commit is contained in:
@@ -40,6 +40,7 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulu
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "0.8.0-rc5" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
|
||||
@@ -14,29 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};
|
||||
|
||||
fn main() {
|
||||
generate_cargo_keys();
|
||||
rerun_if_git_head_changed();
|
||||
|
||||
let mut manifest_dir = PathBuf::from(
|
||||
env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
|
||||
);
|
||||
|
||||
while manifest_dir.parent().is_some() {
|
||||
if manifest_dir.join(".git/HEAD").exists() {
|
||||
println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
manifest_dir.join(".git/HEAD").display()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
manifest_dir.pop();
|
||||
}
|
||||
|
||||
println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.with_current_project()
|
||||
.with_wasm_builder_from_crates("1.0.11")
|
||||
.with_wasm_builder_from_crates("2.0.0")
|
||||
.export_heap_base()
|
||||
.import_memory()
|
||||
.build()
|
||||
|
||||
@@ -83,7 +83,7 @@ fn testnet_genesis(
|
||||
) -> GenesisConfig {
|
||||
GenesisConfig {
|
||||
frame_system: Some(SystemConfig {
|
||||
code: WASM_BINARY.to_vec(),
|
||||
code: WASM_BINARY.expect("WASM binary was not build, please build it!").to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
pallet_balances: Some(BalancesConfig {
|
||||
|
||||
@@ -42,9 +42,7 @@ static INTEGRATION_TEST_ALLOWED_TIME: Option<&str> = option_env!("INTEGRATION_TE
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn integration_test() {
|
||||
let task_executor: TaskExecutor = (|fut, _| {
|
||||
spawn(fut).map(|_| ())
|
||||
}).into();
|
||||
let task_executor: TaskExecutor = (|fut, _| spawn(fut).map(|_| ())).into();
|
||||
|
||||
// start alice
|
||||
let mut alice =
|
||||
@@ -82,7 +80,10 @@ async fn integration_test() {
|
||||
Info {
|
||||
scheduling: Scheduling::Always,
|
||||
},
|
||||
parachain_runtime::WASM_BINARY.to_vec().into(),
|
||||
parachain_runtime::WASM_BINARY
|
||||
.expect("You need to build the WASM binary to run this test!")
|
||||
.to_vec()
|
||||
.into(),
|
||||
genesis_state.into(),
|
||||
)),
|
||||
)));
|
||||
@@ -104,7 +105,8 @@ async fn integration_test() {
|
||||
let parachain_config =
|
||||
parachain_config(task_executor.clone(), Charlie, vec![], para_id).unwrap();
|
||||
let (_service, charlie_client) =
|
||||
crate::service::run_collator(parachain_config, key, polkadot_config, para_id, true).unwrap();
|
||||
crate::service::run_collator(parachain_config, key, polkadot_config, para_id, true)
|
||||
.unwrap();
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
charlie_client.wait_for_blocks(4).await;
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
use ansi_term::Color;
|
||||
use cumulus_collator::{prepare_collator_config, CollatorBuilder};
|
||||
use cumulus_network::DelayedBlockAnnounceValidator;
|
||||
use cumulus_network::{DelayedBlockAnnounceValidator, JustifiedBlockAnnounceValidator};
|
||||
use futures::{future::ready, FutureExt};
|
||||
use polkadot_primitives::v0::CollatorPair;
|
||||
use polkadot_primitives::v0::{CollatorPair, Block as PBlock, Id as ParaId};
|
||||
use sc_executor::native_executor_instance;
|
||||
pub use sc_executor::NativeExecutor;
|
||||
use sc_informant::OutputFormat;
|
||||
@@ -26,7 +26,8 @@ use sc_service::{Configuration, PartialComponents, TaskManager, TFullBackend, TF
|
||||
use std::sync::Arc;
|
||||
use sp_core::crypto::Pair;
|
||||
use sp_trie::PrefixedMemoryDB;
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
|
||||
use polkadot_service::{AbstractClient, RuntimeApiCollection};
|
||||
|
||||
// Our native executor instance.
|
||||
native_executor_instance!(
|
||||
@@ -206,11 +207,11 @@ pub fn run_collator(
|
||||
.spawn("polkadot", polkadot_future);
|
||||
} else {
|
||||
let is_light = matches!(polkadot_config.role, Role::Light);
|
||||
let builder = polkadot_service::NodeBuilder::new(polkadot_config);
|
||||
let mut polkadot_task_manager = if is_light {
|
||||
return Err("Light client not supported.".into());
|
||||
let (mut polkadot_task_manager, client, _) = if is_light {
|
||||
Err("Light client not supported.".into())
|
||||
} else {
|
||||
builder.build_full(
|
||||
polkadot_service::build_full(
|
||||
polkadot_config,
|
||||
Some((key.public(), id)),
|
||||
None,
|
||||
false,
|
||||
@@ -221,6 +222,7 @@ pub fn run_collator(
|
||||
let polkadot_future = async move {
|
||||
polkadot_task_manager.future().await.expect("polkadot essential task failed");
|
||||
};
|
||||
client.execute_with(SetDelayedBlockAnnounceValidator { block_announce_validator, para_id: id });
|
||||
|
||||
task_manager
|
||||
.spawn_essential_handle()
|
||||
@@ -229,3 +231,22 @@ pub fn run_collator(
|
||||
|
||||
Ok((task_manager, client))
|
||||
}
|
||||
|
||||
struct SetDelayedBlockAnnounceValidator<B: BlockT> {
|
||||
block_announce_validator: DelayedBlockAnnounceValidator<B>,
|
||||
para_id: ParaId,
|
||||
}
|
||||
|
||||
impl<B: BlockT> polkadot_service::ExecuteWithClient for SetDelayedBlockAnnounceValidator<B> {
|
||||
type Output = ();
|
||||
|
||||
fn execute_with_client<Client, Api, Backend>(self, client: Arc<Client>) -> Self::Output
|
||||
where<Api as sp_api::ApiExt<PBlock>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
|
||||
Backend: sc_client_api::Backend<PBlock>,
|
||||
Backend::State: sp_api::StateBackend<BlakeTwo256>,
|
||||
Api: RuntimeApiCollection<StateBackend = Backend::State>,
|
||||
Client: AbstractClient<PBlock, Backend, Api = Api> + 'static
|
||||
{
|
||||
self.block_announce_validator.set(Box::new(JustifiedBlockAnnounceValidator::new(client, self.para_id)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user