Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

feat: allow subsystems to send only declared messages, generate graphviz #5314

Merged
merged 139 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
0f6c6c1
outgoing messages
drahnr Apr 12, 2022
8fda133
refactor
drahnr Apr 14, 2022
c23c59b
fmt
drahnr Apr 14, 2022
510bed6
better check if missing send
drahnr Apr 19, 2022
2a49f94
fix failing tests
drahnr Apr 19, 2022
d7cab79
impro
drahnr Apr 19, 2022
63cfb62
intermediate commit, use petgraph for convenience and the dot graph
drahnr Apr 19, 2022
6306db8
cleanup overseer a bit, make dummy work
drahnr Apr 20, 2022
9053e17
more migration bits
drahnr Apr 20, 2022
d92a83e
fixups
drahnr Apr 21, 2022
f3ad18d
fixup sample
drahnr Apr 21, 2022
6cb6540
grunt
drahnr Apr 21, 2022
b91630e
fixup pvf-checker
drahnr Apr 22, 2022
ebadddf
more collector traits
drahnr Apr 22, 2022
92e4219
fixins
drahnr Apr 22, 2022
18c027a
move to new generated trait bounds, not compiling yet
drahnr Apr 22, 2022
1e9e46b
fixup disputes-coordinator
drahnr Apr 22, 2022
1cc4e4e
fixup approval voting
drahnr Apr 22, 2022
1552972
fixup availability distribution
drahnr Apr 22, 2022
2b1ca3a
the job based subsystem does not work yet, since the generated trait …
drahnr Apr 22, 2022
0a10c0a
prep deprecation notice
drahnr Apr 22, 2022
9bc9f9d
fixup candidate validation
drahnr Apr 22, 2022
15d2097
update required outbound messages for the overseer
drahnr Apr 22, 2022
0ed6f61
fixup subsystem util
drahnr Apr 22, 2022
11e77e2
half fix, dispatch_iter is there to make things efficient, but uses A…
drahnr Apr 22, 2022
fd1d835
fixup dispute distribution
drahnr Apr 22, 2022
0574a78
more outgoing
drahnr Apr 22, 2022
6e615c7
fixup collator protocol
drahnr Apr 22, 2022
7c5bf06
fixup collator proto
drahnr Apr 22, 2022
3ada1c0
prep provisioner, also job based and hence needs more work
drahnr Apr 22, 2022
11c2b59
chore trait based job sysmte works
drahnr Apr 25, 2022
a4cfe4e
Revert "chore trait based job sysmte works"
drahnr Apr 25, 2022
11eeeb0
minor foo
drahnr Apr 25, 2022
6e6570e
rename subsyste util
drahnr Apr 25, 2022
0503e61
fixup collation
drahnr Apr 25, 2022
4e160c1
fixup provisioner (first job based fixup)
drahnr Apr 25, 2022
2905c2e
update overseer ougoing collation gen
drahnr Apr 25, 2022
cf7ed17
chore
drahnr Apr 27, 2022
1052794
fixup approval voting
drahnr Apr 27, 2022
5f0b3cc
fixup fuckup fixup
drahnr Apr 27, 2022
2fa17c7
avail dist fixup
drahnr Apr 27, 2022
ce4aacd
avail rec + bitfield dist fixup
drahnr Apr 27, 2022
e10c90a
gossip support fixup
drahnr Apr 27, 2022
df9a95a
statement dist fixup
drahnr Apr 27, 2022
e068fc2
fixup annotations overseer
drahnr Apr 27, 2022
118f9ae
fixup borked revert of ToJob -> COnsumes -> Tojob
drahnr Apr 27, 2022
50cbe82
minor fixins
drahnr Apr 27, 2022
b1e3829
split metrics from bridges
drahnr Apr 27, 2022
8950b5f
FIXME FIXME TODO XXX networking bridge hacks
drahnr Apr 27, 2022
06555b7
fixup approval voting
drahnr Apr 27, 2022
27c59ab
chore
drahnr Apr 27, 2022
e199b15
fixup approval dist
drahnr Apr 27, 2022
d17dabc
fixup network bridge
drahnr Apr 27, 2022
a2a6f19
brige: can't leak private type
drahnr Apr 27, 2022
dbf595c
make all Senders send
drahnr Apr 27, 2022
f39bfb9
overseer annotation
drahnr Apr 27, 2022
02053ab
rolling session window explicitness
drahnr Apr 27, 2022
14a23ba
chore: fmt
drahnr May 11, 2022
d6ef62d
fixins
drahnr Apr 27, 2022
fb161d4
minor gimps
drahnr Apr 27, 2022
daf5f6e
avoid impl Trait, use explicit generics
drahnr Apr 28, 2022
9351330
disable type Sender = overseer::OverseerSender
drahnr Apr 28, 2022
bb69d2a
chore: silence some warnings
drahnr Apr 28, 2022
592acd3
add additional `<Context as *ContextTrait>::Sender` bounds
drahnr Apr 28, 2022
bcb08b8
chore fixes
drahnr Apr 29, 2022
41b59ee
overseer-gen: split tests and misc, for readability
drahnr Apr 29, 2022
7e39988
make task name a true literal
drahnr Apr 29, 2022
0c6ce51
make rustc hang
drahnr Apr 29, 2022
d284bc7
chore: move solo up
drahnr Apr 29, 2022
11f8e82
better trait bounds
drahnr Apr 29, 2022
1ef4b79
introduce `#[subsystem]` annotation
drahnr Apr 29, 2022
899f123
parse attr of `#[subsystem]`
drahnr Apr 29, 2022
580964c
drop all dispatch_iter logic
drahnr Apr 29, 2022
18a31f2
feat: use new `#[subsystem]` everywhere
drahnr Apr 29, 2022
2c151d5
chore: fmt
drahnr Apr 29, 2022
5c926a7
fixup overseer gen Ctx sending foo
drahnr Apr 29, 2022
cf8f65d
remove `no_dispatch` from parser
drahnr Apr 29, 2022
40aab17
remove dead extern_network_ty, it's unused
drahnr Apr 29, 2022
422e155
overseer test
drahnr Apr 29, 2022
7e8ecf6
chore: make test cases for overseer more realistic
drahnr May 2, 2022
01f4fff
fix misgeneration, `\#outgoing_wrapper` is not be prefixed with `\#su…
drahnr May 2, 2022
c601dcc
make overseer stuff prep
drahnr May 2, 2022
d5241f7
chore fmt
drahnr May 2, 2022
8132e17
make it all work together
drahnr May 2, 2022
d1d8451
compilation fixes (incomplete)
drahnr May 2, 2022
20c5726
make `#[subsystem]` annotations work across multiple fiels
drahnr May 4, 2022
b9bbe59
fix imports
drahnr May 4, 2022
ce49525
account
drahnr May 4, 2022
3ce7b20
start killing all the stupid trait bounds that are generated
drahnr May 4, 2022
56e003b
add docs to subsystem generation
drahnr May 4, 2022
225cd7a
headlines
drahnr May 4, 2022
5519fd7
fixup backing after rebase
drahnr May 4, 2022
ee5db10
use more ``#[overseer::contextbounds(*, prefix = self::overseer)]``
drahnr May 4, 2022
8972b69
use `#[overseer::contextbounds(..)]` almsot everywhere
drahnr May 4, 2022
b3192ae
polkadot compiles now
drahnr May 4, 2022
031ad5b
foo
drahnr May 5, 2022
17de992
interceptor WIP fixup
drahnr May 5, 2022
d47734d
fix warnings
drahnr May 6, 2022
d3956ae
fix interceptor
drahnr May 6, 2022
99c3c77
fix malus compilation
drahnr May 6, 2022
ea5540a
fix examples
drahnr May 6, 2022
48f4364
remove foo
drahnr May 6, 2022
026b20d
crazy unit type impl
drahnr May 6, 2022
224561c
test fixes
drahnr May 9, 2022
3dba834
example fix
drahnr May 9, 2022
b410971
avoid duplicate code generation
drahnr May 9, 2022
1042794
subsystem util
drahnr May 9, 2022
151c8e7
fix mut
drahnr May 9, 2022
a8a89d7
approval voting test fixes
drahnr May 9, 2022
4d80c53
fix overseer
drahnr May 9, 2022
3e70feb
fix rolling session window and other utils
drahnr May 9, 2022
714b045
undo change for util test
drahnr May 9, 2022
19a8263
foo fmt
drahnr May 9, 2022
cfdfcff
fix network bridge test cases
drahnr May 9, 2022
286db5e
chore: spellcheck
drahnr May 9, 2022
dbcc8b9
fix docs
drahnr May 9, 2022
d6754b5
rebase fallout
drahnr May 10, 2022
727dfcc
fixins
drahnr May 10, 2022
1b93941
cannot format generated files, since we still require nightly fmt
drahnr May 10, 2022
cf59239
add explaining comment
drahnr May 10, 2022
eafd859
please cargo spellcheck
drahnr May 10, 2022
9b32305
docs
drahnr May 10, 2022
80b86e5
do not attempt to compile expansion examples which are not fully corr…
drahnr May 11, 2022
cfb77e9
make doc tests work
drahnr May 11, 2022
f473178
can't teach hunspell `clonabl`, so drop that
drahnr May 11, 2022
0b90f2c
fix typo, causing a rustc panic
drahnr May 11, 2022
e79313b
chore: doc fixes
drahnr May 11, 2022
42fa7be
dev deps cause a false positive for deny(unused_crate_dependencies)
drahnr May 11, 2022
68b4621
warnings
drahnr May 11, 2022
ac2a89d
fix rustdoc complaint
drahnr May 12, 2022
786965b
disable doctests, broken in current nightly
drahnr May 12, 2022
0ba7af4
remove obsolete comment
drahnr May 12, 2022
7db9f33
remove some stale or known todos that don't really affect anything
drahnr May 12, 2022
863adfd
Update node/overseer/overseer-gen/proc-macro/src/impl_subsystem_ctx_s…
drahnr May 12, 2022
4811703
Update node/overseer/overseer-gen/proc-macro/src/parse/parse_subsyste…
drahnr May 12, 2022
0c1093f
Update node/network/bridge/src/metrics.rs
drahnr May 12, 2022
56aff7c
Update node/overseer/overseer-gen/proc-macro/src/subsystem.rs
drahnr May 12, 2022
8f76d68
improve README.md on what subsystem and contextbounds proc macros do
drahnr May 12, 2022
a4ab390
Update node/overseer/overseer-gen/proc-macro/src/overseer.rs
drahnr May 12, 2022
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions bridges/.config/lingua.dic
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Best/MS
BlockId
BlockNumber
BridgeStorage
clonable
CLI/MS
Chain1
Chain2
Expand Down Expand Up @@ -177,6 +178,7 @@ plancks
polkadot/MS
pov-block/MS
precommit
proc-macro/MS
prometheus
proxying
provisioner/MS
Expand Down
2 changes: 1 addition & 1 deletion core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub type ChainId = u32;
/// A hash of some data used by the relay chain.
pub type Hash = sp_core::H256;

/// Unit type wrapper around [`Hash`] that represents a candidate hash.
/// Unit type wrapper around [`type@Hash`] that represents a candidate hash.
///
/// This type is produced by [`CandidateReceipt::hash`].
///
Expand Down
40 changes: 16 additions & 24 deletions node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use futures::{channel::mpsc, future::FutureExt, join, select, sink::SinkExt, str
use parity_scale_codec::Encode;
use polkadot_node_primitives::{AvailableData, CollationGenerationConfig, PoV};
use polkadot_node_subsystem::{
messages::{AllMessages, CollationGenerationMessage, CollatorProtocolMessage},
messages::{CollationGenerationMessage, CollatorProtocolMessage},
overseer, ActiveLeavesUpdate, FromOverseer, OverseerSignal, SpawnedSubsystem, SubsystemContext,
SubsystemError, SubsystemResult, SubsystemSender,
SubsystemError, SubsystemResult,
};
use polkadot_node_subsystem_util::{
request_availability_cores, request_persisted_validation_data, request_validation_code,
Expand Down Expand Up @@ -54,6 +54,7 @@ pub struct CollationGenerationSubsystem {
metrics: Metrics,
}

#[overseer::contextbounds(CollationGeneration, prefix = self::overseer)]
impl CollationGenerationSubsystem {
/// Create a new instance of the `CollationGenerationSubsystem`.
pub fn new(metrics: Metrics) -> Self {
Expand All @@ -71,11 +72,7 @@ impl CollationGenerationSubsystem {
///
/// If `err_tx` is not `None`, errors are forwarded onto that channel as they occur.
/// Otherwise, most are logged and then discarded.
async fn run<Context>(mut self, mut ctx: Context)
where
Context: SubsystemContext<Message = CollationGenerationMessage>,
Context: overseer::SubsystemContext<Message = CollationGenerationMessage>,
{
async fn run<Context>(mut self, mut ctx: Context) {
// when we activate new leaves, we spawn a bunch of sub-tasks, each of which is
// expected to generate precisely one message. We don't want to block the main loop
// at any point waiting for them all, so instead, we create a channel on which they can
Expand Down Expand Up @@ -108,12 +105,8 @@ impl CollationGenerationSubsystem {
&mut self,
incoming: SubsystemResult<FromOverseer<<Context as SubsystemContext>::Message>>,
ctx: &mut Context,
sender: &mpsc::Sender<AllMessages>,
) -> bool
where
Context: SubsystemContext<Message = CollationGenerationMessage>,
Context: overseer::SubsystemContext<Message = CollationGenerationMessage>,
{
sender: &mpsc::Sender<overseer::CollationGenerationOutgoingMessages>,
) -> bool {
match incoming {
Ok(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated,
Expand Down Expand Up @@ -162,11 +155,8 @@ impl CollationGenerationSubsystem {
}
}

impl<Context> overseer::Subsystem<Context, SubsystemError> for CollationGenerationSubsystem
where
Context: SubsystemContext<Message = CollationGenerationMessage>,
Context: overseer::SubsystemContext<Message = CollationGenerationMessage>,
{
#[overseer::subsystem(CollationGeneration, error=SubsystemError, prefix=self::overseer)]
impl<Context> CollationGenerationSubsystem {
fn start(self, ctx: Context) -> SpawnedSubsystem {
let future = async move {
self.run(ctx).await;
Expand All @@ -178,12 +168,13 @@ where
}
}

async fn handle_new_activations<Context: SubsystemContext>(
#[overseer::contextbounds(CollationGeneration, prefix = self::overseer)]
async fn handle_new_activations<Context>(
config: Arc<CollationGenerationConfig>,
activated: impl IntoIterator<Item = Hash>,
ctx: &mut Context,
metrics: Metrics,
sender: &mpsc::Sender<AllMessages>,
sender: &mpsc::Sender<overseer::CollationGenerationOutgoingMessages>,
) -> crate::error::Result<()> {
// follow the procedure from the guide:
// https://w3f.github.io/parachain-implementers-guide/node/collators/collation-generation.html
Expand Down Expand Up @@ -393,9 +384,10 @@ async fn handle_new_activations<Context: SubsystemContext>(
metrics.on_collation_generated();

if let Err(err) = task_sender
.send(AllMessages::CollatorProtocol(
CollatorProtocolMessage::DistributeCollation(ccr, pov, result_sender),
))
.send(
CollatorProtocolMessage::DistributeCollation(ccr, pov, result_sender)
.into(),
)
.await
{
gum::warn!(
Expand All @@ -417,7 +409,7 @@ async fn obtain_current_validation_code_hash(
relay_parent: Hash,
para_id: ParaId,
assumption: OccupiedCoreAssumption,
sender: &mut impl SubsystemSender,
sender: &mut impl overseer::CollationGenerationSenderTrait,
) -> Result<Option<ValidationCodeHash>, crate::error::Error> {
use polkadot_node_subsystem::RuntimeApiError;

Expand Down
18 changes: 10 additions & 8 deletions node/collation-generation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ mod handle_new_activations {
*subsystem_sent_messages.lock().await = rx.collect().await;
});

let sent_messages = Arc::try_unwrap(sent_messages)
let mut sent_messages = Arc::try_unwrap(sent_messages)
.expect("subsystem should have shut down by now")
.into_inner();

Expand Down Expand Up @@ -328,7 +328,7 @@ mod handle_new_activations {
};

assert_eq!(sent_messages.len(), 1);
match &sent_messages[0] {
match AllMessages::from(sent_messages.pop().unwrap()) {
AllMessages::CollatorProtocol(CollatorProtocolMessage::DistributeCollation(
CandidateReceipt { descriptor, .. },
_pov,
Expand Down Expand Up @@ -356,7 +356,7 @@ mod handle_new_activations {
expect_descriptor.erasure_root = descriptor.erasure_root.clone();
expect_descriptor
};
assert_eq!(descriptor, &expect_descriptor);
assert_eq!(descriptor, expect_descriptor);
},
_ => panic!("received wrong message type"),
}
Expand Down Expand Up @@ -470,11 +470,13 @@ mod handle_new_activations {

assert_eq!(sent_messages.len(), 1);
match &sent_messages[0] {
AllMessages::CollatorProtocol(CollatorProtocolMessage::DistributeCollation(
CandidateReceipt { descriptor, .. },
_pov,
..,
)) => {
overseer::CollationGenerationOutgoingMessages::CollatorProtocolMessage(
CollatorProtocolMessage::DistributeCollation(
CandidateReceipt { descriptor, .. },
_pov,
..,
),
) => {
assert_eq!(expect_validation_code_hash, descriptor.validation_code_hash);
},
_ => panic!("received wrong message type"),
Expand Down
30 changes: 18 additions & 12 deletions node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use polkadot_node_subsystem::{
ApprovalDistributionMessage, ChainApiMessage, ChainSelectionMessage, RuntimeApiMessage,
RuntimeApiRequest,
},
overseer, RuntimeApiError, SubsystemContext, SubsystemError, SubsystemResult,
overseer, RuntimeApiError, SubsystemError, SubsystemResult,
};
use polkadot_node_subsystem_util::{
determine_new_blocks,
Expand Down Expand Up @@ -107,8 +107,9 @@ enum ImportedBlockInfoError {
}

/// Computes information about the imported block. Returns an error if the info couldn't be extracted.
async fn imported_block_info(
ctx: &mut (impl SubsystemContext + overseer::SubsystemContext),
#[overseer::contextbounds(ApprovalVoting, prefix = self::overseer)]
async fn imported_block_info<Context>(
ctx: &mut Context,
env: ImportedBlockInfoEnv<'_>,
block_hash: Hash,
block_header: &Header,
Expand Down Expand Up @@ -319,10 +320,11 @@ pub struct BlockImportedCandidates {
/// * and return information about all candidates imported under each block.
///
/// It is the responsibility of the caller to schedule wakeups for each block.
pub(crate) async fn handle_new_head(
ctx: &mut (impl SubsystemContext + overseer::SubsystemContext),
#[overseer::contextbounds(ApprovalVoting, prefix = self::overseer)]
pub(crate) async fn handle_new_head<Context, B: Backend>(
ctx: &mut Context,
state: &mut State,
db: &mut OverlayedBackend<'_, impl Backend>,
db: &mut OverlayedBackend<'_, B>,
head: Hash,
finalized_number: &Option<BlockNumber>,
) -> SubsystemResult<Vec<BlockImportedCandidates>> {
Expand Down Expand Up @@ -609,7 +611,7 @@ pub(crate) mod tests {
use assert_matches::assert_matches;
use merlin::Transcript;
use polkadot_node_primitives::approval::{VRFOutput, VRFProof};
use polkadot_node_subsystem::messages::AllMessages;
use polkadot_node_subsystem::messages::{AllMessages, ApprovalVotingMessage};
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_node_subsystem_util::database::Database;
use polkadot_primitives::v2::{Id as ParaId, SessionInfo, ValidatorIndex};
Expand Down Expand Up @@ -724,7 +726,8 @@ pub(crate) mod tests {
#[test]
fn imported_block_info_is_good() {
let pool = TaskExecutor::new();
let (mut ctx, mut handle) = make_subsystem_context::<(), _>(pool.clone());
let (mut ctx, mut handle) =
make_subsystem_context::<ApprovalVotingMessage, _>(pool.clone());

let session = 5;
let session_info = dummy_session_info(session);
Expand Down Expand Up @@ -847,7 +850,8 @@ pub(crate) mod tests {
#[test]
fn imported_block_info_fails_if_no_babe_vrf() {
let pool = TaskExecutor::new();
let (mut ctx, mut handle) = make_subsystem_context::<(), _>(pool.clone());
let (mut ctx, mut handle) =
make_subsystem_context::<ApprovalVotingMessage, _>(pool.clone());

let session = 5;
let session_info = dummy_session_info(session);
Expand Down Expand Up @@ -950,7 +954,8 @@ pub(crate) mod tests {
#[test]
fn imported_block_info_fails_if_ancient_session() {
let pool = TaskExecutor::new();
let (mut ctx, mut handle) = make_subsystem_context::<(), _>(pool.clone());
let (mut ctx, mut handle) =
make_subsystem_context::<ApprovalVotingMessage, _>(pool.clone());

let session = 5;

Expand Down Expand Up @@ -1027,7 +1032,7 @@ pub(crate) mod tests {
#[test]
fn imported_block_info_extracts_force_approve() {
let pool = TaskExecutor::new();
let (mut ctx, mut handle) = make_subsystem_context::<(), _>(pool.clone());
let (mut ctx, mut handle) = make_subsystem_context(pool.clone());

let session = 5;
let session_info = dummy_session_info(session);
Expand Down Expand Up @@ -1158,7 +1163,8 @@ pub(crate) mod tests {
let mut overlay_db = OverlayedBackend::new(&db);

let pool = TaskExecutor::new();
let (mut ctx, mut handle) = make_subsystem_context::<(), _>(pool.clone());
let (mut ctx, mut handle) =
make_subsystem_context::<ApprovalVotingMessage, _>(pool.clone());

let session = 5;
let irrelevant = 666;
Expand Down
Loading