Skip to content

feat(p2p): add versioned handlers function#5548

Open
janos wants to merge 1 commit into
masterfrom
p2p-versioned-handlers
Open

feat(p2p): add versioned handlers function#5548
janos wants to merge 1 commit into
masterfrom
p2p-versioned-handlers

Conversation

@janos

@janos janos commented Jul 25, 2026

Copy link
Copy Markdown
Member

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

This PR adds VersionedHandler and NewVersionedHandlersFunc to pkg/p2p to streamline protocol backward compatibility across node versions. The suggestion for this feature came from @acud.

When updating protocols while maintaining support for older node releases, checking stream versions manually inside handler bodies can get verbose. NewVersionedHandlersFunc provides a clean, declarative way to associate handlers with minimum semver thresholds.

When using NewVersionedHandlersFunc function it is needed to declare legacy handlers with the versions of the protocol from which that handler is supported and new handlers to define from which version of the protocol it is supported, so the function will select the highest supported handler by the peer's stream. The implementation relies on the recently added Stream.Version() method to get the version of the stream. This function can be used for both handler and "client" functions, as the logic is the same. There is an example added for more clarity on the usage.

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

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