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

Fix: Magport startup error, Feat: customize Avail service port #11

Merged
merged 7 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 123 additions & 123 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resolver = "2"
panic = "unwind"

[workspace.package]
authors = ["Magport/Substrate-Rollup team"]
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>", "Magport/Substrate-Rollup team"]
edition = "2021"
license = "Apache License 2.0"
repository = "https://github.com/Magport/Substrate-Rollup"
13 changes: 5 additions & 8 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "node-template"
name = "magport-node"
version = "4.0.0-dev"
description = "A fresh FRAME-based Substrate node, ready for hacking."
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
authors.workspace = true
homepage = "https://substrate.io/"
edition = "2021"
license = "MIT-0"
Expand All @@ -13,9 +13,6 @@ build = "build.rs"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[[bin]]
name = "node-template"

[dependencies]
clap = { version = "4.4.2", features = ["derive"] }
futures = { version = "0.3.21", features = ["thread-pool"] }
Expand Down Expand Up @@ -78,7 +75,7 @@ frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/parityte
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

# Local Dependencies
node-template-runtime = { version = "4.0.0-dev", path = "../runtime" }
magport-node-runtime = { version = "4.0.0-dev", path = "../runtime" }
node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false }
primitives-avail = { path = "../primitives/avail"}
# CLI-specific dependencies
Expand All @@ -97,13 +94,13 @@ substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/pa
default = []
# Dependencies that are only required if runtime benchmarking should be build.
runtime-benchmarks = [
"node-template-runtime/runtime-benchmarks",
"magport-node-runtime/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
]
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change
# in the near future.
try-runtime = [
"node-template-runtime/try-runtime",
"magport-node-runtime/try-runtime",
"try-runtime-cli/try-runtime",
]
30 changes: 23 additions & 7 deletions node/src/avail_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
Call::DataAvailability(da_call) => match da_call {
DaCall::submit_data { data } => {
// log::info!("=======get:{:?}", data);
let _rollup_block = node_template_runtime::Block::decode(&mut &data.0[..]);
let _rollup_block = magport_node_runtime::Block::decode(&mut &data.0[..]);
// log::info!("=======get block:{:?}", rollup_block);
let rollup_block_hash = client.block_hash(block_number_solo.into());
let mut find_flag = false;
Expand Down Expand Up @@ -109,6 +109,7 @@ pub fn spawn_avail_task<T, B>(
client: Arc<T>,
task_manager: &TaskManager,
avail_record: Arc<Mutex<AvailRecord>>,
avail_rpc_port: u16,
) -> Result<(), Box<dyn Error>>
where
B: BlockT,
Expand All @@ -126,15 +127,30 @@ where
{
task_manager.spawn_essential_handle().spawn("spawn_query_block", "magport", {
async move {
let avail_client =
avail_subxt::build_client("ws://127.0.0.1:9945", false).await.unwrap();
let avail_url = format!("ws://127.0.0.1:{}", avail_rpc_port);
log::info!("================ TASK | avail_url: {:?} ================", avail_url);
let avail_client = Arc::new(Mutex::new(None::<OnlineClient<AvailConfig>>));
let mut notification_st = client.import_notification_stream();
while let Some(notification) = notification_st.next().await {
if notification.origin != BlockOrigin::Own {
continue;
}
let block_number: u32 = (*notification.header.number()).into();
// If inner of avail_client is None, try to connect avail
if avail_client.lock().await.is_none() {
let avail_client_inner = avail_subxt::build_client(&avail_url, false).await;
if let Ok(avail_client_inner) = avail_client_inner {
*avail_client.lock().await = Some(avail_client_inner);
log::info!("================ TASK | avail service connected ================");
} else {
log::info!("================ TASK | avail service not connected ================");
continue;
}
}
// Get Avail Client
let guard = avail_client.lock().await;
let avail_client_ref = guard.as_ref().unwrap();

let block_number: u32 = (*notification.header.number()).into();
// Query
if block_number % 5 == 0 {
// Sync From Pallet
Expand Down Expand Up @@ -167,7 +183,7 @@ where
};

if last_submit_block_confirm != last_submit_block {
let avail_latest_finalized_height = get_avail_latest_finalized_height(&avail_client).await.unwrap();
let avail_latest_finalized_height = get_avail_latest_finalized_height(avail_client_ref).await.unwrap();
log::info!(
"================ QUERY TASK | Avail Block Query Range: {:?} to {:?} ================",
last_avail_scan_block_confirm,
Expand All @@ -184,7 +200,7 @@ where
log::info!("================ QUERY TASK | search avail block:{:?} ================", block_number);
for block_number_solo in last_submit_block_confirm + 1..=last_submit_block {
if let Ok(find_result) = query_block_exist(
&avail_client,
avail_client_ref,
client.clone(),
block_number,
block_number_solo,
Expand Down Expand Up @@ -267,7 +283,7 @@ where
let extrinsic_params =
AvailExtrinsicParams::new_with_app_id(AppId(0u32));
let signer = signer_from_seed("//Alice").unwrap();
match avail_client
match avail_client_ref
.tx()
.sign_and_submit(&data_transfer, &signer, extrinsic_params)
.await
Expand Down
Loading
Loading