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

Integrate all (dummy) subsystems with the Overseer #1374

Merged
merged 10 commits into from
Jul 9, 2020

Conversation

ordian
Copy link
Member

@ordian ordian commented Jul 7, 2020

Fixes #1317.

Please bear with me while I make these baby steps.
This boilerplate looks ugly so as an experiment I looked at a type map approach 2e934c3 (instead of storing a bunch of fields, we can store a HashMap<Type, Box<SomeTrait>>) but then reverted this change for now. Let me know if it's worth exploring.

@ordian ordian added A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jul 7, 2020
@ordian ordian self-assigned this Jul 7, 2020
@github-actions github-actions bot added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jul 7, 2020
@ordian ordian marked this pull request as ready for review July 8, 2020 08:39
@ordian ordian added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jul 8, 2020
Copy link
Contributor

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're definitely right that the repetition here is annoying. I think that you're also right that the runtime typemap is not the right way to handle it, because it prevents things like exhaustive matching.

I'm imagining a pair of macros which work like this:

// declare a list of types; produces some sort of private module? const item? not sure.
declare_types!(subsystem_messages, CandidateBackingMessage, CandidateSelectionMessage, ...);
// iterate over the types declared earlier. Produce a new ident from each closure provided.
// final item has appropriate idents substituted.
for_each_type_in!(
  subsystem_messages, 
  |type_name| to_snake_case(type_name.truncate(type_name.len() - "Message".len())),
  |type_name| to_snake_case(type_name.truncate(type_name.len() - "Message".len())) + "_subsystem",
  {
    let $1 = spawn (
      &mut s,
      &mut running_subsystems,
      &mut running_subsystems_rx,
      $0,
    )?;
  }
);

or

for_each_type_in!(
  subsystem_messages, 
  |type_name| to_snake_case(type_name.truncate(type_name.len() - "Message".len())) + "_subsystem",
  {
    if let (ref mut s) = self.$0.instance {
      let _ = s.tx.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
    }
  }
);

There would need to be an explicit match generator as well:

for_each_type_in!(
  subsystem_messages, 
  |type_name| type_name.truncate(type_name.len() - "Message".len()),
  |type_name| to_snake_case(type_name.truncate(type_name.len() - "Message".len())) + "_subsystem",
  match msg {
    AllMessage::$0(msg) => {
      if let Some(ref mut s) = self.$1.instance {
        let _ = s.tx.send(FromOverseer::Communication{ msg }).await
      }
    }
  }
);

It would mean two fairly complicated procedural macros, but it would also eliminate quite a lot of manual duplication of code... provided that we can come up with a good way to store a bunch of type idents in declare_types.

Alternately, we could skip declare_types entirely and just paste in the full type list for each invocation of for_each_type_in, but then we have the problem of copy-paste synchronization errors again.

@ordian
Copy link
Member Author

ordian commented Jul 8, 2020

@coriolinus thanks for the detailed feedback!

I was hesitant to throw macros at the problem, because in my experience while it can solve some problems, it inevitably create others, like code readability (now you need to read the source of the macro/docs/tests), maintenance, longer compile times, IDE-unfriendliness. But given the love of macros at Parity, I might reconsider :)

I think that you're also right that the runtime typemap is not the right way to handle it, because it prevents things like exhaustive matching.

Actually, I don't think it does prevent exhaustive matching, but to be fair I haven't explored this avenue fully. It also can guarantee exhaustive listing of subsystem fields via iteration.

@coriolinus
Copy link
Contributor

You're right that there are a bunch of downsides to throwing macros at a problem, but they do come with one key upside: they make correctness a lot easier. If we use macros set up as I suggested, then adding a new subsystem means that, beyond implementing the subsystem itself, you just need to add it to the declare_types list. Without it, you have to add a copy-paste case in a bunch of different places, none of which are easy to grep for. IMO that makes maintenance easier, not harder.

Copy link
Contributor

@montekki montekki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to add macros in this situation where the code is quite straightforward (but bloated). One of the most frequent complaints I've heard is our code being very macro-heavy.

@ordian
Copy link
Member Author

ordian commented Jul 8, 2020

@coriolinus makes a good point about correctness though. It's not currently guaranteed at compile time that we didn't forget to check a certain subsystem e.g. in broadcast_signal. OTOH, the tests should catch it and I don't know if we we'll be adding any new subsystem anytime soon.

node/overseer/src/lib.rs Outdated Show resolved Hide resolved
node/overseer/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

* master:
  Implement PoV Distribution Subsystem (#1344)
  Bump Substrate (#1382)
  Update the Kusama bootnode IDs (#1377)
  Companion for #6575 (Add `WeightInfo`) (#1352)
  Companion for #6599 (#1371)
  Use `SpawnNamed` to give tasks names (#1379)
  Update to substrate#59ee76a0 (#1380)
  Companion PR for #6564 (#1350)
  Companion for #6584 (#1373)
  Companion for #6500 (decl_module: frame_system as default ident) (#1314)
@rphmeier rphmeier merged commit 8845df2 into master Jul 9, 2020
@rphmeier rphmeier deleted the ao-overseer-all-messages-integration branch July 9, 2020 20:25
pepyakin added a commit that referenced this pull request May 4, 2022
d2faa6b2600 Update spec_version for Rococo (#1387)
b3d701124fe Remove support for encoded-call messaging from relay and runtime integration code (#1376)
7f1c4af6650 fix copypaste (#1386)
4e195205ae2 re-enable BEEFY alarms for Rialto (#1385)
072ae865d6b fix for "`/root` is not writable." during deployments startup (#1384)
3ab1810b071 fix daily gitlab build (#1383)
3317b8a6811 Update Substrate/Polkadot refs for latest BEEFY + xcm-v3 capability (#1381)
ebfa9f2fef8 remove vault from ci (#1382)
82136eb42e3 Switch to gav-xcm-v3 branch to be able to test bridges + XCMv3 integration (#1378)
aa8896475b6 Revert "mention encoded-calls-messaging tag"
80c0f7ee05d mention encoded-calls-messaging tag
c7c6f0ce5e8 Revert "add api data() for inbound_lane (#1373)" (#1375)
6ef6bcc0169 FinalityEngine in substrate relay (#1374)
82698e3e082 add api data() for inbound_lane (#1373)
74a48878f86 pub use WeightInfo in Grandpa + Messsages pallets (#1370)
2cc27b7abb5 Update Substrate/Polkadot/Cumulus references (#1364)
9f3ffcd59c7 [ci] Use bridges-ci:production image in the pipeline (#1365)
61766e31f2e Few typos and clippy fixes (#1362)
REVERT: f220d2fccab Polkadot staging update (#1356)
REVERT: 92ddc3ea7a8 Polkadot-staging update (#1305)
REVERT: 29eecdf1fa1 Merge pull request #1294 from paritytech/polkadot-staging-update
REVERT: 173d2d82297 Merge pull request #1280 from paritytech/polkadot-staging-update
REVERT: 54146416e7f Merge pull request #1276 from paritytech/polkadot-staging-update
REVERT: df701181745 Merge branch 'master' into polkadot-staging-update
REVERT: f704a741ee8 Polkadot staging update (#1270)
REVERT: 1602249f0a2 Enable Beefy debug logs in test deployment (#1237)
REVERT: c61d240b474 Fix storage parameter name computation (#1238)
REVERT: 96d3808e88f Integrate BEEFY with Rialto & Millau runtimes (#1227)
REVERT: f75a1bdd9ba update dependencies (#1229)
REVERT: 957da038547 Add mut support (#1232)
REVERT: 8062637289f fixed set_operational in GRANDPA pallet (#1226)
REVERT: 14b36ca4eef Add CODEOWNERS file (#1219)
REVERT: 3bec15766f6 Unify metric names (#1209)
REVERT: 0e839d2423e remove abandoned exchange relay (#1217)
REVERT: 2c91c6815cf Remove unused `relays/headers` (#1216)
REVERT: 80b1e65db82 Remove unused PoA<>Substrate bridge (#1210)
REVERT: f36f76fc2a7 Fix UI deployment. (#1211)
REVERT: fc0b65365bb Add `AtLeast32BitUnsigned` for MessageLance::SourceChainBalance (#1207)

git-subtree-dir: bridges
git-subtree-split: d2faa6b2600fea77d121f3c0767cf59211e597a3
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate all subsystems with the Overseer
4 participants