feat(p2p): add versioned handlers function#5548
Open
janos wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
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