Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
RPC: use finalized as default pubsub commitment level (#16659)
Browse files Browse the repository at this point in the history
* RPC: use finalized as default pubsub commitment level

* update docs

* Fix tests
  • Loading branch information
jstarry authored Apr 20, 2021
1 parent c8b474c commit a7e65c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
13 changes: 4 additions & 9 deletions core/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,7 @@ impl RpcSubscriptions {
subscriber: Subscriber<Response<UiAccount>>,
) {
let config = config.unwrap_or_default();
let commitment = config
.commitment
.unwrap_or_else(CommitmentConfig::confirmed);
let commitment = config.commitment.unwrap_or_default();

let slot = if commitment.is_finalized() {
self.block_commitment_cache
Expand Down Expand Up @@ -703,10 +701,7 @@ impl RpcSubscriptions {
subscriber: Subscriber<Response<RpcKeyedAccount>>,
) {
let config = config.unwrap_or_default();
let commitment = config
.account_config
.commitment
.unwrap_or_else(CommitmentConfig::confirmed);
let commitment = config.account_config.commitment.unwrap_or_default();

let mut subscriptions = if commitment.is_confirmed() {
self.subscriptions
Expand Down Expand Up @@ -753,7 +748,7 @@ impl RpcSubscriptions {
sub_id: SubscriptionId,
subscriber: Subscriber<Response<RpcLogsResponse>>,
) {
let commitment = commitment.unwrap_or_else(CommitmentConfig::confirmed);
let commitment = commitment.unwrap_or_default();

{
let mut subscriptions = if commitment.is_confirmed() {
Expand Down Expand Up @@ -864,7 +859,7 @@ impl RpcSubscriptions {
.map(|config| (config.commitment, config.enable_received_notification))
.unwrap_or_default();

let commitment = commitment.unwrap_or_else(CommitmentConfig::confirmed);
let commitment = commitment.unwrap_or_default();

let mut subscriptions = if commitment.is_confirmed() {
self.subscriptions
Expand Down
17 changes: 15 additions & 2 deletions core/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde_json::{json, Value};
use solana_account_decoder::UiAccount;
use solana_client::{
rpc_client::RpcClient,
rpc_config::{RpcAccountInfoConfig, RpcSignatureSubscribeConfig},
rpc_response::{Response, RpcSignatureResult, SlotUpdate},
};
use solana_core::{rpc_pubsub::gen_client::Client as PubsubClient, test_validator::TestValidator};
Expand Down Expand Up @@ -262,7 +263,13 @@ fn test_rpc_subscriptions() {
for sig in signature_set_clone {
let status_sender = status_sender.clone();
let mut sig_sub = client
.signature_subscribe(sig.clone(), None)
.signature_subscribe(
sig.clone(),
Some(RpcSignatureSubscribeConfig {
commitment: Some(CommitmentConfig::confirmed()),
..RpcSignatureSubscribeConfig::default()
}),
)
.unwrap_or_else(|err| panic!("sig sub err: {:#?}", err));

tokio_02::spawn(async move {
Expand All @@ -277,7 +284,13 @@ fn test_rpc_subscriptions() {
for pubkey in account_set {
let account_sender = account_sender.clone();
let mut client_sub = client
.account_subscribe(pubkey, None)
.account_subscribe(
pubkey,
Some(RpcAccountInfoConfig {
commitment: Some(CommitmentConfig::confirmed()),
..RpcAccountInfoConfig::default()
}),
)
.unwrap_or_else(|err| panic!("acct sub err: {:#?}", err));
tokio_02::spawn(async move {
let response = client_sub.next().await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion docs/src/developing/clients/jsonrpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3050,7 +3050,7 @@ After connecting to the RPC PubSub websocket at `ws://<ADDRESS>/`:

- Submit subscription requests to the websocket using the methods below
- Multiple subscriptions may be active at once
- Many subscriptions take the optional [`commitment` parameter](jsonrpc-api.md#configuring-state-commitment), defining how finalized a change should be to trigger a notification. For subscriptions, if commitment is unspecified, the default value is `"confirmed"`.
- Many subscriptions take the optional [`commitment` parameter](jsonrpc-api.md#configuring-state-commitment), defining how finalized a change should be to trigger a notification. For subscriptions, if commitment is unspecified, the default value is `"finalized"`.

### accountSubscribe

Expand Down

0 comments on commit a7e65c0

Please sign in to comment.