feat(rpc): add NewWithCommitment / NewWithTimeout / NewWithTimeoutAndCommitment (#414)#436
Open
ozpool wants to merge 1 commit into
Open
Conversation
…Commitment Adds the three rpc.Client constructor variants requested in solana-foundation#414, plus a DefaultCommitment() accessor so callers can read the pinned commitment back without exporting a new field. The new constructors compose New / a small newHTTPWithTimeout helper, leaving the existing 5-minute default for callers using New unchanged. - NewWithCommitment(url, commitment) pins a CommitmentType on the returned *Client. Methods that take an explicit commitment continue to honor whatever the caller passes; the stored value is exposed through Client.DefaultCommitment so consumers can use it as a fallback rather than threading it through every call site themselves. - NewWithTimeout(url, timeout) lifts the hardcoded http.Client timeout. The same value is also bound to the dialer's connect timeout and the transport's idle connection timeout so long-haul reads, connect, and pool eviction stay aligned. - NewWithTimeoutAndCommitment is the combined variant, mirroring the rust-sdk RpcClient::new_with_timeout_and_commitment ergonomics. Adds rpc/client_constructors_test.go covering the empty-default case, each constructor's stored state, and the http.Client.Timeout the custom-timeout constructors emit. Fixes solana-foundation#414
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.
Description
Fixes #414. Adds the three
rpc.Clientconstructor variants the issue asks for, plus aDefaultCommitment()accessor so callers can read the pinned commitment back without exporting a new field.NewWithCommitment(url, commitment)pins aCommitmentTypeon the returned*Client. Methods that take an explicit commitment continue to honor whatever the caller passes; the stored value is exposed throughClient.DefaultCommitmentso consumers can use it as a fallback rather than threading it through every call site themselves.NewWithTimeout(url, timeout)lifts the hardcodedhttp.Clienttimeout. The same value is also bound to the dialer's connect timeout and the transport's idle connection timeout so long-haul reads, connect, and pool eviction stay aligned.NewWithTimeoutAndCommitment(url, timeout, commitment)is the combined variant, mirroring the rust-sdkRpcClient::new_with_timeout_and_commitmentergonomics.The new constructors compose
New/ a smallnewHTTPWithTimeouthelper, leaving the existing 5-minute default for callers usingNewunchanged. No behavior change for existing call sites.Tests
Added
rpc/client_constructors_test.gocovering:Newreturns an empty default commitment.NewWithCommitmentstores the pinnedCommitmentFinalizedvalue.NewWithTimeoutpropagates the timeout to the underlyinghttp.Client.Timeout.NewWithTimeoutdoes not pin a commitment.NewWithTimeoutAndCommitmentstores both the commitment and the timeout.