Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch P2P Messages #1149

Merged
merged 2 commits into from
Jan 13, 2022
Merged

Batch P2P Messages #1149

merged 2 commits into from
Jan 13, 2022

Conversation

AlastairHolmes
Copy link
Contributor

@AlastairHolmes AlastairHolmes commented Jan 11, 2022

This will batch the p2p messages decreasing the RPC bandwidth for broadcast multisig stages (By not sending the same message repeatedly via RPC).

I also did this now to simplify the existing multisig tests to help abit when refactoring them for the oneshot.

I've chosen to not change the SC's p2p rpc interface here because we are likely to remove all the p2p code in the SC and handle peering manually in the CFE.

Note I did remove this log message from the tests (println!("recv secret3 keygen, i: {}", i);), and added assert_channel_empty in all cases after receiving p2p messages via the channel in the tests. Otherwise behaviour is the same.


let (own_message, outgoing_messages) = match self.processor.init() {
DataToSend::Broadcast(stage_data) => {
let ceremony_data: D = stage_data.clone().into();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let ceremony_data: D = stage_data.clone().into();
let ceremony_data: Self::Message = stage_data.clone().into();

Same below

Ok(_) => slog::info!(logger, "Sent P2P message to: {}", account_id),
Err(error) => slog::error!(logger, "Failed to send P2P message to: {}. {}", account_id, error)
Some(messages) = outgoing_p2p_message_receiver.recv() => {
async fn send_messages<'a, AccountIds: 'a + IntoIterator<Item = &'a AccountId> + Clone>(client: &P2PRpcClient, account_to_peer: &BTreeMap<AccountId, (PeerId, u16, Ipv6Addr)>, account_ids: AccountIds, message: MultisigMessage, logger: &slog::Logger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we reconsider the practice of defining named functions (lambdas are a different story) inside other functions? It reduces readability in my opinion, and doesn't add any real benefit (e.g. I can't see at glance what this loop does, but with send_messages taken out the entire loop fits entirely in one screen). Like, you don't reduce the scope of this function by that much as long as it is private.

The formatting is also much nicer when the function is taken out:

async fn send_messages<'a, AccountIds: 'a + IntoIterator<Item = &'a AccountId> + Clone>(
    client: &P2PRpcClient,
    account_to_peer: &BTreeMap<AccountId, (PeerId, u16, Ipv6Addr)>,
    account_ids: AccountIds,
    message: MultisigMessage,
    logger: &slog::Logger,
) {

@AlastairHolmes AlastairHolmes force-pushed the chore/oneshot-remove-keygen-state-runner branch from 9b54117 to 856e5bc Compare January 12, 2022 07:48
Base automatically changed from chore/oneshot-remove-keygen-state-runner to develop January 12, 2022 08:01
@msgmaxim
Copy link
Contributor

Merging as we got three approvals.

@msgmaxim msgmaxim merged commit 271ebb9 into develop Jan 13, 2022
@msgmaxim msgmaxim deleted the fix/batch-p2p-messages branch January 13, 2022 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SC-2880] Batch P2P Messages for a single multisig stage
4 participants