Gossipsub: control message every n hearthbeat
What
- Add a p2p
Pingwhose encoding is equivalent to aSubscribemessage with the following payload, wheretz1Ke2h7sDdakHJQh8WX4Z372du1KChsksyUis the zero/null address.
let ping_topic =
Types.Topic.
{
slot_index = 0;
pkh = Signature.Public_key_hash.zero;
}
- Add an issue #7768 (closed) to integrate the
Pingmessage when bumping the p2p message version - Add an issue for implementing metrics for the
Pingmessage #7770 (closed) - Add periodic emission of Subscribe messages for topics the DAL node is subscribed to every 45s. The chosen value is motivated by the following text.
(* The ping should be performed by the heartbeat handler at least
every 45s, hence every [heartbeat_ping_interval] ticks when_
[heartbeat_interval] = 1s.
A 45-second ping interval is a reasonable choice as it sits in
the middle of the commonly recommended 30-60 second range for P2P
networks.
This timing provides a good balance between maintaining
reliable connections and managing network overhead.
It's frequent enough to detect stale peers before most
NAT/firewall timeouts (which typically occur after 60-120
seconds)
*)
Why
- Improves network resilience by ensuring subscription state remains consistent across peers
How
- Added a new heartbeat interval constant
hearbeat_ping_intervalset to 180s in terms ofhearbeat_interval - During each heartbeat, check if
heartbeat_ticks mod hearbeat_ping_interval = 0- If it is, iterate through all connections and emit a
Pingmessage to each peer
- If it is, iterate through all connections and emit a
- Reuse existing
emit_p2p_messagefunction to send thePingmessages
Manually testing the MR
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR
Edited by Paul Laforgue