-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Integrate all (dummy) subsystems with the Overseer #1374
Conversation
There was a problem hiding this 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.
@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 :)
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. |
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 |
There was a problem hiding this 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.
@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 |
There was a problem hiding this 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)
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
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.