diff --git a/.github/workflows/publish-instant-seal-binary b/.github/workflows/publish-instant-seal-binary new file mode 100644 index 000000000..9e3c826e5 --- /dev/null +++ b/.github/workflows/publish-instant-seal-binary @@ -0,0 +1,53 @@ +name: Publish Binary + +on: + push: + tags: + - '*' + +jobs: + build: + name: Publish binaries + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + + - uses: ./.github/actions/free-disk-space + - name: Install toolchain + id: toolchain + uses: actions-rs/toolchain@master + with: + profile: minimal + toolchain: nightly + target: wasm32-unknown-unknown + + - name: Rust Cache + uses: Swatinem/rust-cache@v1.3.0 + + - name: Install Protobuf + run: sudo apt-get install protobuf-compiler + + - name: Build binary + run: cargo build --release -p tangle --locked --features testnet,txpool,manual-seal + + - name: Calculate SHA256 + run: sha256sum target/release/tangle > target/release/tangle.sha256sum + + - name: Upload manual-seal binary to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/release/tangle + asset_name: tangle-testnet-manual-seal-linux-amd64 + tag: ${{ github.ref }} + overwrite: true + + - name: Uplaod SHA256 of the binary + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/release/tangle.sha256sum + asset_name: tangle-testnet-manual-seal-linux-amd64.sha256sum + tag: ${{ github.ref }} + overwrite: true diff --git a/.github/workflows/publish-release-binary.yml b/.github/workflows/publish-release-binary.yml index 1d0da8aae..8cd168220 100644 --- a/.github/workflows/publish-release-binary.yml +++ b/.github/workflows/publish-release-binary.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - features: [testnet, default, txpool, manual-seal] + features: [testnet, default, txpool] steps: - uses: actions/checkout@v3 diff --git a/Cargo.lock b/Cargo.lock index 5e575b0f9..a40490c0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14085,6 +14085,7 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "futures 0.3.30", + "futures-timer", "hex", "hex-literal 0.4.1", "jsonrpsee 0.23.2", @@ -14304,7 +14305,7 @@ dependencies = [ [[package]] name = "tangle-subxt" -version = "0.3.0" +version = "0.4.0" dependencies = [ "parity-scale-codec", "scale-info", diff --git a/Cargo.toml b/Cargo.toml index a6380cd5e..10ef37c81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ rlp = { version = "0.5", default-features = false } tracing = "0.1.40" tokio = { version = "1.39" } futures = { version = "0.3.30" } +futures-timer = { version = "3.0.2" } rand_core = { version = "0.6", default-features = false } rand_chacha = { version = "0.3", default-features = false } rand = { version = "0.8.5", default-features = false } diff --git a/node/Cargo.toml b/node/Cargo.toml index 8c2035c2b..86f6855c7 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -115,6 +115,7 @@ tangle-crypto-primitives = { workspace = true } tangle-primitives = { workspace = true, features = ["std"] } tangle-runtime = { workspace = true, features = ["std"] } tangle-testnet-runtime = { workspace = true, optional = true } +futures-timer = { workspace = true } # sygma-rpc = { workspace = true } # sygma-runtime-api = { workspace = true } @@ -143,4 +144,4 @@ testnet = ["tangle-testnet-runtime"] txpool = ["fc-rpc/txpool"] fast-runtime = ["tangle-testnet-runtime/fast-runtime", "tangle-runtime/fast-runtime"] metadata-hash = ["tangle-testnet-runtime?/metadata-hash", "tangle-runtime/metadata-hash"] -manual-seal = [] +manual-seal = ["tangle-testnet-runtime/manual-seal"] diff --git a/node/src/command.rs b/node/src/command.rs index 6e4c35241..64e285e2e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -15,7 +15,7 @@ use crate::{ chainspec, cli::{Cli, Subcommand}, - service::{self, tangle}, + service, }; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use futures::TryFutureExt; @@ -236,7 +236,7 @@ pub fn run() -> sc_cli::Result<()> { } cmd.run_with_spec::, - ::ExtendHostFunctions>(Some( + ::ExtendHostFunctions>(Some( config.chain_spec, )) }, diff --git a/node/src/manual_seal.rs b/node/src/manual_seal.rs index 6b9a5c831..7eef5e9ac 100644 --- a/node/src/manual_seal.rs +++ b/node/src/manual_seal.rs @@ -24,8 +24,10 @@ use crate::eth::{ use futures::future; use futures::FutureExt; use futures::{channel::mpsc, prelude::*}; +use futures_timer::Delay; use sc_client_api::{Backend, BlockBackend}; use sc_consensus::BasicQueue; +use sc_consensus_babe::BabeLink; use sc_consensus_babe::{BabeWorkerHandle, SlotProportion}; use sc_consensus_grandpa::SharedVoterState; #[allow(deprecated)] @@ -248,18 +250,16 @@ where client.clone(), )?; - let slot_duration = babe_link.config().slot_duration(); + //let slot_duration = babe_link.config().slot_duration(); + let slot_duration = 0; // This is important to allow continous block let target_gas_price = eth_config.target_gas_price; - let (import_queue, block_import) = build_import_queue( - client.clone(), - config, - eth_config, - &task_manager, - telemetry.as_ref().map(|x| x.handle()), - grandpa_block_import, - )?; + let import_queue = sc_consensus_manual_seal::import_queue( + Box::new(block_import.clone()), + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + ); Ok(sc_service::PartialComponents { client, @@ -271,7 +271,7 @@ where transaction_pool, other: ( telemetry, - block_import, + Box::new(block_import), grandpa_link, babe_link, frontier_backend, @@ -341,49 +341,6 @@ pub async fn new_full { + let (mut sink, commands_stream) = futures::channel::mpsc::channel(1024); + task_manager.spawn_handle().spawn("block_authoring", None, async move { + loop { + futures_timer::Delay::new(std::time::Duration::from_millis(1000)).await; + sink.try_send(sc_consensus_manual_seal::EngineCommand::SealNewBlock { + create_empty: true, + finalize: true, + parent_hash: None, + sender: None, + }) + .unwrap(); + } + }); + + future::Either::Left(sc_consensus_manual_seal::run_manual_seal( + sc_consensus_manual_seal::ManualSealParams { + block_import, + env: proposer_factory, + client, + pool: transaction_pool, + commands_stream, + select_chain, + consensus_data_provider: Some(Box::new(babe_consensus_data_provider)), + create_inherent_data_providers: pending_create_inherent_data_providers, + }, + )) + }, + Sealing::Instant => future::Either::Right(sc_consensus_manual_seal::run_instant_seal( + sc_consensus_manual_seal::InstantSealParams { + block_import, + env: proposer_factory, + client, + pool: transaction_pool, + select_chain, + consensus_data_provider: Some(Box::new(babe_consensus_data_provider)), + create_inherent_data_providers: pending_create_inherent_data_providers, + }, + )), + }; + + // we spawn the future on a background thread managed by service. + task_manager + .spawn_essential_handle() + .spawn_blocking("manual-seal", None, manual_seal); network_starter.start_network(); log::info!("Manual Seal Ready"); return Ok(task_manager); } - // if the node isn't actively participating in consensus then it doesn't - // need a keystore, regardless of which protocol we use below. - let keystore = if role.is_authority() { Some(keystore_container.keystore()) } else { None }; - let grandpa_config = sc_consensus_grandpa::Config { // FIXME #1578 make this available through chainspec gossip_duration: Duration::from_millis(333), @@ -686,96 +698,6 @@ pub async fn new_full, - transaction_pool: Arc>, - select_chain: FullSelectChain, - block_import: BoxBlockImport, - task_manager: &TaskManager, - prometheus_registry: Option<&Registry>, - telemetry: Option<&Telemetry>, - commands_stream: mpsc::Receiver< - sc_consensus_manual_seal::rpc::EngineCommand<::Hash>, - >, -) -> Result<(), ServiceError> { - let proposer_factory = sc_basic_authorship::ProposerFactory::new( - task_manager.spawn_handle(), - client.clone(), - transaction_pool.clone(), - prometheus_registry, - telemetry.as_ref().map(|x| x.handle()), - ); - - thread_local!(static TIMESTAMP: RefCell = const { RefCell::new(0) }); - - /// Provide a mock duration starting at 0 in millisecond for timestamp inherent. - /// Each call will increment timestamp by slot_duration making Aura think time has passed. - struct MockTimestampInherentDataProvider; - - #[async_trait::async_trait] - impl sp_inherents::InherentDataProvider for MockTimestampInherentDataProvider { - async fn provide_inherent_data( - &self, - inherent_data: &mut sp_inherents::InherentData, - ) -> Result<(), sp_inherents::Error> { - TIMESTAMP.with(|x| { - *x.borrow_mut() += tangle_testnet_runtime::SLOT_DURATION; - inherent_data.put_data(sp_timestamp::INHERENT_IDENTIFIER, &*x.borrow()) - }) - } - - async fn try_handle_error( - &self, - _identifier: &sp_inherents::InherentIdentifier, - _error: &[u8], - ) -> Option> { - // The pallet never reports error. - None - } - } - - let target_gas_price = eth_config.target_gas_price; - let create_inherent_data_providers = move |_, ()| async move { - let timestamp = MockTimestampInherentDataProvider; - let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); - Ok((timestamp, dynamic_fee)) - }; - - let manual_seal = match sealing { - Sealing::Manual => future::Either::Left(sc_consensus_manual_seal::run_manual_seal( - sc_consensus_manual_seal::ManualSealParams { - block_import, - env: proposer_factory, - client, - pool: transaction_pool, - commands_stream, - select_chain, - consensus_data_provider: None, - create_inherent_data_providers, - }, - )), - Sealing::Instant => future::Either::Right(sc_consensus_manual_seal::run_instant_seal( - sc_consensus_manual_seal::InstantSealParams { - block_import, - env: proposer_factory, - client, - pool: transaction_pool, - select_chain, - consensus_data_provider: None, - create_inherent_data_providers, - }, - )), - }; - - // we spawn the future on a background thread managed by service. - task_manager - .spawn_essential_handle() - .spawn_blocking("manual-seal", None, manual_seal); - Ok(()) -} - #[allow(clippy::type_complexity)] pub fn new_chain_ops( config: &mut Configuration, diff --git a/node/src/rpc/mod.rs b/node/src/rpc/mod.rs index 56b1ee87a..f8f649be6 100644 --- a/node/src/rpc/mod.rs +++ b/node/src/rpc/mod.rs @@ -152,8 +152,6 @@ where let mut io = RpcModule::new(()); let FullDeps { client, pool, deny_unsafe, eth, babe, select_chain, grandpa } = deps; - let Some(BabeDeps { keystore, babe_worker_handle }) = babe else { todo!() }; - let GrandpaDeps { shared_voter_state, shared_authority_set, @@ -166,10 +164,13 @@ where io.merge(TransactionPayment::new(client.clone()).into_rpc())?; io.merge(ServicesClient::new(client.clone()).into_rpc())?; - io.merge( - Babe::new(client.clone(), babe_worker_handle.clone(), keystore, select_chain, deny_unsafe) - .into_rpc(), - )?; + if let Some(babe) = babe { + let BabeDeps { babe_worker_handle, keystore } = babe; + io.merge( + Babe::new(client.clone(), babe_worker_handle, keystore, select_chain, deny_unsafe) + .into_rpc(), + )?; + } io.merge( Grandpa::new( diff --git a/precompiles/balances-erc20/src/mock.rs b/precompiles/balances-erc20/src/mock.rs index 81a7533da..1cddc9554 100644 --- a/precompiles/balances-erc20/src/mock.rs +++ b/precompiles/balances-erc20/src/mock.rs @@ -17,7 +17,6 @@ //! Testing utilities. use super::*; - use frame_support::derive_impl; use frame_support::{construct_runtime, parameter_types, weights::Weight}; use pallet_evm::AddressMapping; diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 608e008d1..20cadd20a 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -82,3 +82,4 @@ verifying = [ ] integration-tests = [] fast-runtime = [] +manual-seal = [] diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 679160bff..9058f2d32 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -50,7 +50,10 @@ pub mod time { /// slot_duration()`. /// /// Change this to adjust the block time. + #[cfg(not(feature = "manual-seal"))] pub const SECONDS_PER_BLOCK: Moment = 6; + #[cfg(feature = "manual-seal")] + pub const SECONDS_PER_BLOCK: Moment = 1; pub const MILLISECS_PER_BLOCK: Moment = SECONDS_PER_BLOCK * 1000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; diff --git a/runtime/testnet/Cargo.toml b/runtime/testnet/Cargo.toml index 175dd3069..4020ef361 100644 --- a/runtime/testnet/Cargo.toml +++ b/runtime/testnet/Cargo.toml @@ -330,6 +330,7 @@ with-rocksdb-weights = [] with-paritydb-weights = [] evm-tracing = [] fast-runtime = ["tangle-primitives/fast-runtime"] +manual-seal = ["tangle-primitives/manual-seal"] # Enable the metadata hash generation. #