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

Query Part #5

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

28 changes: 15 additions & 13 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ codec = { package = "parity-scale-codec", version = "3.6.1" }
serde = { version = "1.0.188", features = ["derive"] }
jsonrpsee = { version = "0.16.2", features = ["server"] }
futures = "0.3.21"
futures-timer = "3.0"
log = "0.4.17"
parking_lot = "0.12.1"
rand = "0.8"

# primitives
Expand Down Expand Up @@ -77,7 +79,7 @@ sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", ta
grandpa = { package = "sc-consensus-grandpa", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
sc-service = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", default-features = false}
sc-service = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", default-features = false }
sc-telemetry = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
sc-sync-state-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
sc-sysinfo = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
Expand All @@ -93,8 +95,8 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-s
pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
pallet-asset-conversion-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
pallet-asset-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
pallet-im-online = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", default-features = false}
pallet-skip-feeless-payment = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", default-features = false}
pallet-im-online = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", default-features = false }
pallet-skip-feeless-payment = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", default-features = false }

# node-specific local dependencies
rollup-runtime = { path = "../../runtime" }
Expand All @@ -103,13 +105,13 @@ node-primitives = { path = "../primitives" }
node-executor = { package = "rollup-node-executor", path = "../executor" }

# CLI-specific dependencies
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
serde_json = "1.0.108"

## CLI-specific local dependencies
node-inspect = { package = "rollup-node-inspect", path = "../inspect", optional = true}
node-inspect = { package = "rollup-node-inspect", path = "../inspect", optional = true }


[dev-dependencies]
Expand Down Expand Up @@ -140,19 +142,19 @@ substrate-cli-test-utils = { git = "https://github.com/paritytech/polkadot-sdk.g
[build-dependencies]
clap = { version = "4.4.6", optional = true }
clap_complete = { version = "4.0.2", optional = true }
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
substrate-frame-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
try-runtime-cli = {git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true}
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
substrate-frame-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0", optional = true }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }
sc-storage-monitor = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.4.0" }

# build local dependencies
node-inspect = { package = "rollup-node-inspect", path = "../inspect", optional = true}
node-inspect = { package = "rollup-node-inspect", path = "../inspect", optional = true }

[features]
default = [ "cli" ]
default = ["cli"]
cli = [
"clap",
"clap_complete",
Expand Down
102 changes: 97 additions & 5 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ use codec::Encode;
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
use frame_system_rpc_runtime_api::AccountNonceApi;
use futures::prelude::*;
use futures_timer::Delay;
use node_executor::ExecutorDispatch;
use node_primitives::Block;
use node_primitives::{Block, BlockNumber};
use parking_lot::RwLock;
use rollup_runtime::RuntimeApi;
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion};
Expand All @@ -38,8 +40,8 @@ use sc_statement_store::Store as StatementStore;
use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_api::ProvideRuntimeApi;
use sp_core::crypto::Pair;
use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion};
use sp_core::{crypto::Pair, ConstU32};
use sp_runtime::{generic, traits::Block as BlockT, BoundedVec, SaturatedConversion};
use std::sync::Arc;

/// The full client type definition.
Expand Down Expand Up @@ -680,8 +682,11 @@ pub fn new_full_base(
pub fn new_full(config: Configuration, cli: Cli) -> Result<TaskManager, ServiceError> {
let mixnet_config = cli.mixnet_params.config(config.role.is_authority());
let database_source = config.database.clone();
let task_manager = new_full_base(config, mixnet_config, cli.no_hardware_benchmarks, |_, _| ())
.map(|NewFullBase { task_manager, .. }| task_manager)?;
let NewFullBase {
task_manager,
client,
..
} = new_full_base(config, mixnet_config, cli.no_hardware_benchmarks, |_, _| ())?;

sc_storage_monitor::StorageMonitorService::try_spawn(
cli.storage_monitor,
Expand All @@ -690,6 +695,93 @@ pub fn new_full(config: Configuration, cli: Cli) -> Result<TaskManager, ServiceE
)
.map_err(|e| ServiceError::Application(e.into()))?;

// let submit_state = Arc::new(RwLock::new(BlockNumber::from(0u32)));

type LastSubmittedBlockNumber = Option<BlockNumber>;
type BlockNumberCollection = BoundedVec<BlockNumber, ConstU32<100>>;

let arc_last_submitted_block = Arc::new(RwLock::new(LastSubmittedBlockNumber::default()));
let arc_block_numbers = Arc::new(RwLock::new(BlockNumberCollection::default()));

let arc_last_submitted_block_clone = arc_last_submitted_block.clone();
let arc_block_numbers_clone = arc_block_numbers.clone();
task_manager
.spawn_essential_handle()
.spawn("query-blocks-for-submit", "magport", {
let client = client.clone();
async move {
loop {
Delay::new(std::time::Duration::from_secs(1)).await;
let finalized_block_number = client.chain_info().finalized_number;

let start_block_number;
{
let last_submitted_block_number_guard = arc_last_submitted_block_clone.read();

start_block_number = match &*last_submitted_block_number_guard {
Some(last_submitted_block_number) => {
(*last_submitted_block_number).clone() + 1
}
None => 0u32,
};
}
{
let mut write_guard = arc_block_numbers_clone.write();
write_guard.clear();

if start_block_number <= finalized_block_number {
for block_number in start_block_number..=finalized_block_number {
if write_guard.try_push(block_number).is_err() {
break;
}
}
log::info!("Query Part: writing block number: {:?}", write_guard);
} else {
log::info!(
"Query Part: start_block_number: {:?} finalized_block_number: {:?} nothing to commit.",
start_block_number,
finalized_block_number
);
}
}
}
}
});

task_manager
.spawn_essential_handle()
.spawn("submit-blocks", "magport", {
async move {
loop {
Delay::new(std::time::Duration::from_secs(1)).await;
let blocks_waiting_for_submit;
{
let arc_block_numbers_guard = arc_block_numbers.read();
blocks_waiting_for_submit = (*arc_block_numbers_guard).clone();
}
log::info!(
"Submit Part: reading blocks_waiting_for_submit: {:?}",
blocks_waiting_for_submit
);
if blocks_waiting_for_submit.is_empty() {
continue;
}

// Update arc_last_submitted_block, assume each time will submit all block data in `blocks_waiting_for_submit` to Avail.
{
let mut write_guard = arc_last_submitted_block.write();
if let Some(block_number) = blocks_waiting_for_submit.last() {
*write_guard = Some(block_number.clone());
}
log::info!(
"Submit Part: writing arc_last_submitted_block: {:?}",
*write_guard
);
}
}
}
});

Ok(task_manager)
}

Expand Down
Loading