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

grandpa: send neighbor packets to light clients on set transition #13559

Merged

Conversation

andresilva
Copy link
Contributor

@andresilva andresilva commented Mar 7, 2023

As part of the GRANDPA gossip protocol peers exchange small messages (neighbor packets) to inform their peers on what is their local view of the GRANDPA protocol, i.e. what round and set id they are currently observing. This is then used by the gossip logic to avoid gossiping information that peers aren't interested in (either stale or future). Currently these neighbor packets aren't sent to light clients, the reasoning being that since light clients aren't following the full GRANDPA protocol (i.e. they just import commits to finalize blocks), they don't need to care about the state of the peers they are connected to. Still this information can be useful to light clients around validator set boundaries, since it allows light clients to make an informed decision on who to ask justifications from (if necessary), i.e. if I'm looking for a justification for a block that changes the set id from 1 to 2, then any peer that announces being on set id 2 (or higher) should be able to provide such a justification.

This PR changes the gossip logic to also send neighbor packets to light clients when transitioning to a new set. Additionally, the light client also gets a neighbor packet on the initial connection to the peer (this was already the case before this PR).

Related: smol-dot/smoldot#239

@andresilva andresilva added 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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Mar 7, 2023
@andresilva andresilva requested a review from a team March 7, 2023 18:32
Comment on lines 794 to 818
let local_view = match self.local_view {
None => return None,
Some(ref mut v) =>
if v.round == round {
// Do not send neighbor packets out if `round` has not changed ---
// such behavior is punishable.
return None
} else {
v
},
};

let set_id = local_view.set_id;
let set_id = local_view.set_id;

debug!(
target: LOG_TARGET,
"Voter {} noting beginning of round {:?} to network.",
self.config.name(),
(round, set_id)
);
debug!(
target: LOG_TARGET,
"Voter {} noting beginning of round {:?} to network.",
self.config.name(),
(round, set_id)
);

local_view.update_round(round);
local_view.update_round(round);

self.live_topics.push(round, set_id);
self.peers.reshuffle();
}
self.multicast_neighbor_packet()
self.live_topics.push(round, set_id);
self.peers.reshuffle();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing changed here, I just removed this useless scope (rustc was dumber when this code was written).

Comment on lines +826 to +854
let local_view = match self.local_view {
ref mut x @ None => x.get_or_insert(LocalView::new(set_id, Round(1))),
Some(ref mut v) =>
if v.set_id == set_id {
let diff_authorities = self.authorities.iter().collect::<HashSet<_>>() !=
authorities.iter().collect::<HashSet<_>>();

if diff_authorities {
debug!(
target: LOG_TARGET,
"Gossip validator noted set {:?} twice with different authorities. \
Was the authority set hard forked?",
set_id,
);

self.authorities = authorities;
}

local_view.update_set(set_id);
self.live_topics.push(Round(1), set_id);
self.authorities = authorities;
}
self.multicast_neighbor_packet()
// Do not send neighbor packets out if the `set_id` has not changed ---
// such behavior is punishable.
return None
} else {
v
},
};

local_view.update_set(set_id);
self.live_topics.push(Round(1), set_id);
self.authorities = authorities;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

client/consensus/grandpa/src/communication/gossip.rs Outdated Show resolved Hide resolved
client/consensus/grandpa/src/communication/gossip.rs Outdated Show resolved Hide resolved
client/consensus/grandpa/src/communication/gossip.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@dmitry-markin dmitry-markin left a comment

Choose a reason for hiding this comment

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

LGTM!

Co-authored-by: Bastian Köcher <git@kchr.de>
@andresilva andresilva force-pushed the andre/grandpa-neighbor-packets-light-clients branch from 77feeae to 89ed9f2 Compare March 9, 2023 11:45
@andresilva
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 11b9326 into master Mar 9, 2023
@paritytech-processbot paritytech-processbot bot deleted the andre/grandpa-neighbor-packets-light-clients branch March 9, 2023 14:05
@tomaka
Copy link
Contributor

tomaka commented Mar 30, 2023

Is this change included in Polkadot v0.9.40? Or is it for 0.9.41?

@bkchr
Copy link
Member

bkchr commented Mar 30, 2023

Is part of 0.9.40

ukint-vs pushed a commit to gear-tech/substrate that referenced this pull request Apr 10, 2023
…ritytech#13559)

* grandpa: send neighbor packets to light clients on set transition

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* remove match statement

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
…ritytech#13559)

* grandpa: send neighbor packets to light clients on set transition

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* remove match statement

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
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. 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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants