Skip to content

fix(gossipsub): validate default mesh params in ConfigBuilder::build - #6648

Open
Bruce039 wants to merge 4 commits into
libp2p:masterfrom
Bruce039:gossipsub-validate-default-mesh-params
Open

Bruce039 wants to merge 4 commits into
libp2p:masterfrom
Bruce039:gossipsub-validate-default-mesh-params

Conversation

@Bruce039

Copy link
Copy Markdown

After the per-topic configuration was added (#5868), ConfigBuilder::build only loops over protocol.max_transmit_sizes.keys(). So the checks for MeshParametersInvalid, MeshOutboundInvalid and MaxTransmissionSizeTooSmall only run for topics that have a custom max transmit size. The default mesh params, the default max_transmit_size, and topics configured through set_topic_config or mesh_*_for_topic without a size are never checked.

For example ConfigBuilder::default().mesh_n(20).build() returns Ok. With such a config the heartbeat computes peers.len() - mesh_n in the mesh_n_high branch, which overflows in debug builds and in release prunes almost the whole mesh.

This validates the transmit sizes first and then runs the mesh checks on the default params plus every entry in topic_mesh_params. Three tests cover the default params, a topic config and a too small default size; all of them fail on master.

test_mesh_subtraction_with_topic_config_min_outbound used a config with mesh_outbound_min (7) above mesh_n_low (3), which only built because of this bug. I changed it to a valid config that still checks that the outbound peers are kept when the mesh is reduced to mesh_n.

Since the per-topic config landed, `build()` only ran its checks for
topics that have their own max transmit size. The default mesh params,
the default max transmit size and topics configured through
`set_topic_config` / `mesh_*_for_topic` were never validated.

Check the default params and every entry of `topic_mesh_params`, and the
default and per-topic transmit sizes.
@mergify

mergify Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @Bruce039? 🙏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant