Conversation
- chain_size_message not used. - Two enum values not used. - No need for savanna block transition handling - No need to support pre-Leap 5.0 clients epoch time in microseconds - Simplify notice_message handling
…ypes The generic select_ids<T> template used by notice_message and request_message overloaded field semantics based on context: known_trx.pending secretly carried fork_db_root_num, req_trx was always dead, transaction IDs were never populated, and id_list_modes meant different things in notices vs requests. Replace with three self-documenting types: - peer_status_notice: carries fork_db_root_id, fork_db_head_id, earliest_available_block_num, and lib_sync flag - block_request_message: carries my_head_id for catchup requests - block_nack_request_message: carries target_id and my_head_id for gap recovery after block_notice_message This also removes the make_block_id() hack that encoded block numbers into fake block_id_type values, the id_list_modes enum, modes_str(), select_ids<T>, and all the mode-switch validation logic in the handlers.
There was a problem hiding this comment.
Pull request overview
This PR modernizes the net_plugin protocol by removing legacy abstractions and replacing them with self-documenting message types. The changes are specifically designed for Wire, a fresh blockchain with no legacy peer compatibility requirements.
Changes:
- Replaced generic
notice_messageandrequest_messagewith three specific types:peer_status_notice,block_request_message, andblock_nack_request_message - Simplified protocol versioning to a single base version (version 1) removing all legacy version support
- Removed unused protocol types and backward compatibility code (
chain_size_message,id_list_modes,select_ids, generation checks, epoch normalization)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| plugins/net_plugin/include/sysio/net_plugin/protocol.hpp | Defined new self-documenting message types, removed legacy types and enums, updated net_message variant and msg_type_t enum |
| plugins/net_plugin/src/net_plugin.cpp | Updated message handlers to use new types, simplified protocol version handling, removed legacy compatibility code (generation checks, epoch normalization, proper_svnn_block_seen) |
| tests/trx_generator/trx_provider.cpp | Updated to use to_index() function instead of hardcoded message index, added protocol.hpp include |
| tests/trx_generator/CMakeLists.txt | Added net_plugin include directory to support protocol.hpp usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }; | ||
|
|
||
| struct handshake_message { | ||
| uint16_t network_version = 0; ///< incremental value above a computed base |
There was a problem hiding this comment.
The comment "incremental value above a computed base" is outdated. With the new protocol version scheme (proto_version_t::base = 1), the network_version field now directly contains the protocol version value without any base offset calculation.
| uint16_t network_version = 0; ///< incremental value above a computed base | |
| uint16_t network_version = 0; ///< protocol version value (no base offset) |
brianjohnson5972
left a comment
There was a problem hiding this comment.
Just a couple of cleanup items, but approved otherwise
| start_sync(c, root_num); | ||
| } else { | ||
| peer_dlog( p2p_blk_log, c, "sync_manager got catch_up peer_status_notice" ); | ||
| peer_ilog( p2p_blk_log, c, "peer_status_notice, head_num {}, id {}...", |
There was a problem hiding this comment.
I think head_num is only used here, can move it down here and avoid the call in the other conditional. Of could just call it in the peer_ilog and only call it if logging.
| uint32_t head_num = block_header::num_from_id(msg.fork_db_head_id); | ||
| uint32_t root_num = block_header::num_from_id(msg.fork_db_root_id); | ||
| if (msg.lib_sync) { | ||
| peer_dlog( p2p_blk_log, c, "sync_manager got lib_sync peer_status_notice" ); |
There was a problem hiding this comment.
root_num only used in the lib_sync path, can avoid calling for other path.
| req.req_blocks.ids.emplace_back( chain_info.fork_db_head_id ); | ||
| block_request_message req; | ||
| req.my_head_id = chain_info.fork_db_head_id; | ||
| c->enqueue( req ); |
There was a problem hiding this comment.
Moving the enqueue here and/or changing the message type means that peer_syncing_from_us is no longer being set false and I was wondering if that was a problem. It looks like it is not, because it doesn't seem like peer_syncing_from_us is ever read, just written. If I'm right then remove it in other locations.
There was a problem hiding this comment.
peer_syncing_from_us is used in many places including:
bool connection::current() const {
return (connected() && !peer_syncing_from_us);
}So yes, this is a real issue. Very good! Thanks! I'll push up a fix. Instead of adding a new message type or hacking it into the new message types, I can just send a handshake; as that causes the peer to re-evaluates sync state and clears peer_syncing_from_us.
…mote peer_syncing_from_us. When verify_catchup determines we already have the peer's announced block, the old request_message with mode=none signaled the remote peer to clear peer_syncing_from_us. The protocol simplification removed that signal path, leaving the remote peer stuck with peer_syncing_from_us=true until the next handshake exchange. This caused current() to return false, temporarily excluding the peer from block broadcasts. Send a handshake instead so the remote peer re-evaluates sync state through recv_handshake, which clears peer_syncing_from_us on the appropriate path.
Summary
notice_message/request_message(which abusedselect_ids<T>template with overloaded field semantics) with three self-documenting protocol types:peer_status_notice,block_request_message,block_nack_request_messageid_list_modesenum,modes_str(),select_ids<T>template,make_block_id()hack, and all mode-switch validation logic in handlerschain_size_messageMotivation
The old
notice_messageandrequest_messagetypes used a confusing genericselect_ids<T>template where field semantics were overloaded based on context:known_trx.pendingfork_db_root_numknown_trx.modenoneorlast_irr_catch_up(never actually about transactions)known_blocks.pendingfork_db_head_numknown_blocks.ids[0]fork_db_head_idknown_blocks.ids[1]make_block_id(earliest_available_block_num)(a fake block ID encoding a block number)req_trxnone, ids always emptyreq_blocks.modecatch_upfor head catchup,normalfor nack recovery,nonefor stop signalWire is a fresh chain with no legacy peers to support — now is the time to make the protocol self-documenting.
New types