This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
implement bitfield signing subsystem #1364
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
170efd3
update guide to reduce confusion and TODOs
coriolinus ed778a4
work from previous bitfield signing effort
coriolinus a8d312c
start rewriting bitfield signing in terms of the util module
coriolinus 6d3081a
implement construct_availability_bitvec
coriolinus 29cc1c3
implement the unimplemented portions of bitfield signing
coriolinus 5807799
get core availability concurrently, not sequentially
coriolinus 00ef611
use sp-std instead of std for a parachain item
coriolinus 7fc7780
resolve type inference failure caused by multiple From impls
coriolinus 684038f
handle bitfield signing subsystem & Allmessages variant in overseer
coriolinus f14ffe5
fix more multi-From inference issues
coriolinus 89ff07b
more concisely handle overflow
coriolinus 51dbee5
Merge remote-tracking branch 'origin/master' into prgn-bitfield-signing
coriolinus c1b8b54
Revert "resolve type inference failure caused by multiple From impls"
coriolinus 4410c87
Revert "fix more multi-From inference issues"
coriolinus 528cf9b
impl From<i32> for ParaId
coriolinus 7779405
handle another instance of AllSubsystems
coriolinus 333d076
improve consistency when returning existing options
coriolinus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
work from previous bitfield signing effort
There were large merge issues with the old bitfield signing PR, so we're just copying all the work from that onto this and restarting. Much of the existing work will be discarded because we now have better tools available, but that's fine.
- Loading branch information
commit ed778a45648219ddbaf6a4aca97c27da87ad1186
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "polkadot-node-bitfield-signing" | ||
| version = "0.1.0" | ||
| authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"] | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| futures = "0.3.5" | ||
| log = "0.4.8" | ||
| polkadot-primitives = { path = "../../primitives" } | ||
| polkadot-node-subsystem = { path = "../subsystem" } | ||
| wasm-timer = "0.2.4" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright 2020 Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! The bitfield signing subsystem produces `SignedAvailabilityBitfield`s once per block. | ||
|
|
||
| use futures::{ | ||
| channel::{mpsc, oneshot}, | ||
| future::{abortable, AbortHandle}, | ||
| prelude::*, | ||
| Future, | ||
| }; | ||
| use polkadot_node_subsystem::{ | ||
| messages::{AllMessages, BitfieldSigningMessage}, | ||
| OverseerSignal, SubsystemResult, | ||
| }; | ||
| use polkadot_node_subsystem::{FromOverseer, SpawnedSubsystem, Subsystem, SubsystemContext}; | ||
| use polkadot_primitives::Hash; | ||
| use std::{ | ||
| collections::HashMap, | ||
| pin::Pin, | ||
| time::{Duration, Instant}, | ||
| }; | ||
|
|
||
| /// Delay between starting a bitfield signing job and its attempting to create a bitfield. | ||
| const JOB_DELAY: Duration = Duration::from_millis(1500); | ||
|
|
||
| /// JobCanceler aborts all abort handles on drop. | ||
| #[derive(Debug, Default)] | ||
| struct JobCanceler(HashMap<Hash, AbortHandle>); | ||
|
|
||
| // AbortHandle doesn't impl Drop on its own, so we wrap it | ||
| // in this struct to get free cancellation on drop. | ||
| impl Drop for JobCanceler { | ||
| fn drop(&mut self) { | ||
| for abort_handle in self.0.values() { | ||
| abort_handle.abort(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Bitfield signing subsystem. | ||
| struct BitfieldSigning; | ||
|
|
||
| impl BitfieldSigning { | ||
| async fn run<Context>(mut ctx: Context) -> SubsystemResult<()> | ||
| where | ||
| Context: SubsystemContext<Message = BitfieldSigningMessage> + Clone, | ||
| { | ||
| let mut active_jobs = JobCanceler::default(); | ||
|
|
||
| loop { | ||
| use FromOverseer::*; | ||
| use OverseerSignal::*; | ||
| match ctx.recv().await { | ||
| Ok(Communication { msg: _ }) => { | ||
| unreachable!("BitfieldSigningMessage is uninstantiable; qed") | ||
| } | ||
| Ok(Signal(StartWork(hash))) => { | ||
| let (future, abort_handle) = | ||
| abortable(bitfield_signing_job(hash.clone(), ctx.clone())); | ||
| // future currently returns a Result based on whether or not it was aborted; | ||
| // let's ignore all that and return () unconditionally, to fit the interface. | ||
| let future = async move { | ||
| let _ = future.await; | ||
| }; | ||
| active_jobs.0.insert(hash.clone(), abort_handle); | ||
| ctx.spawn(Box::pin(future)).await?; | ||
| } | ||
| Ok(Signal(StopWork(hash))) => { | ||
| if let Some(abort_handle) = active_jobs.0.remove(&hash) { | ||
| abort_handle.abort(); | ||
| } | ||
| } | ||
| Ok(Signal(Conclude)) => break, | ||
| Err(err) => { | ||
| return Err(err); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl<Context> Subsystem<Context> for BitfieldSigning | ||
| where | ||
| Context: SubsystemContext<Message = BitfieldSigningMessage> + Clone, | ||
| { | ||
| fn start(self, ctx: Context) -> SpawnedSubsystem { | ||
| SpawnedSubsystem(Box::pin(async move { | ||
| if let Err(err) = Self::run(ctx).await { | ||
| log::error!("{:?}", err); | ||
| }; | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| async fn bitfield_signing_job<Context>(hash: Hash, ctx: Context) | ||
| where | ||
| Context: SubsystemContext<Message = BitfieldSigningMessage>, | ||
| { | ||
| // first up, figure out when we need to wait until | ||
| let delay = wasm_timer::Delay::new_at(Instant::now() + JOB_DELAY); | ||
| // next, do some prerequisite work | ||
| todo!(); | ||
| // now, wait for the delay to be complete | ||
| if let Err(_) = delay.await { | ||
| return; | ||
| } | ||
| // let (tx, _) = oneshot::channel(); | ||
|
|
||
| // ctx.send_message(AllMessages::CandidateValidation( | ||
| // CandidateValidationMessage::Validate( | ||
| // Default::default(), | ||
| // Default::default(), | ||
| // PoVBlock { | ||
| // block_data: BlockData(Vec::new()), | ||
| // }, | ||
| // tx, | ||
| // ) | ||
| // )).await.unwrap(); | ||
| unimplemented!() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.