Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class EvoSDK {
);
}

this.wasmSdk = builder.build();
this.wasmSdk = await builder.build();
}

static fromWasm(wasmSdk: wasm.WasmSdk): EvoSDK {
Expand Down
21 changes: 21 additions & 0 deletions packages/rs-sdk-ffi/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ pub struct DashSDKConfigExtended {
pub core_sdk_handle: *mut CoreSDKHandle,
}

/// Best-effort protocol-version refresh on SDK init.
///
/// Logs a warning and proceeds if the network is unreachable; never fails SDK creation.
fn best_effort_refresh(sdk: &Sdk, runtime: &BigStackRuntime) {
// Mock SDKs have no live network; refreshing only logs noise.
if sdk.is_mock() {
return;
}
match runtime.block_on(sdk.refresh_protocol_version()) {
Ok(v) => debug!(protocol_version = v, "protocol version refreshed on init"),
Err(e) => warn!(
error = %e,
"protocol version refresh failed on init; proceeding with floor version"
),
}
Comment on lines +37 to +43
}
Comment on lines +29 to +44

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: best_effort_refresh's Err arm is unreachable

Sdk::refresh_protocol_version (packages/rs-sdk/src/sdk/refresh.rs:73-104) already catches ExtendedEpochInfo::fetch_current errors, logs them at warn under target dash_sdk::protocol_version, then unconditionally returns Ok(self.protocol_version_number()). The outer Err(e) => warn!("protocol version refresh failed on init; ...") arm here (and the equivalent in packages/wasm-sdk/src/sdk.rs:317-322) can therefore never fire. The user-visible failure log on init is actually the inner 'proven protocol-version refresh failed; keeping current version' line, not the more descriptive outer message. Either drop the match in favor of letting the inner log speak for itself, or change refresh_protocol_version to surface the inner error so the documented outer warn actually runs.

source: ['claude']


fn apply_version(builder: SdkBuilder, platform_version: u32) -> Result<SdkBuilder, DashSDKError> {
if platform_version == 0 {
return Ok(builder);
Expand Down Expand Up @@ -168,6 +185,7 @@ pub unsafe extern "C" fn dash_sdk_create(config: *const DashSDKConfig) -> DashSD

match sdk_result {
Ok(sdk) => {
best_effort_refresh(&sdk, &runtime);
// Clone Arc<Runtime> into the wrapper
let wrapper = Box::new(SDKWrapper {
sdk,
Expand Down Expand Up @@ -281,6 +299,7 @@ pub unsafe extern "C" fn dash_sdk_create_extended(

match sdk_result {
Ok(sdk) => {
best_effort_refresh(&sdk, &runtime);
let wrapper = Box::new(SDKWrapper {
sdk,
runtime,
Expand Down Expand Up @@ -487,6 +506,8 @@ pub unsafe extern "C" fn dash_sdk_create_trusted(config: *const DashSDKConfig) -

match sdk_result {
Ok(sdk) => {
best_effort_refresh(&sdk, &runtime);

// Prefetch quorums for trusted setup
info!("dash_sdk_create_trusted: SDK built, prefetching quorums...");

Expand Down
16 changes: 16 additions & 0 deletions packages/rs-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,22 @@ impl Sdk {
self.protocol_version.load(Ordering::Relaxed)
}

/// Returns `true` if this SDK is backed by a mock instead of a live network.
///
/// Real (network-backed) SDKs return `false`. Used by callers (e.g. the FFI
/// init wiring) to skip the best-effort protocol-version refresh, which would
/// otherwise issue a guaranteed-failing proven query against a mock.
pub fn is_mock(&self) -> bool {
#[cfg(feature = "mocks")]
{
matches!(self.inner, SdkInstance::Mock { .. })
}
#[cfg(not(feature = "mocks"))]
{
false
}
}

// TODO: Move to settings
/// Indicate if the sdk should request and verify proofs.
pub fn prove(&self) -> bool {
Expand Down
8 changes: 7 additions & 1 deletion packages/wasm-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,14 @@ impl WasmSdkBuilder {
}
}

pub fn build(self) -> Result<WasmSdk, WasmSdkError> {
pub async fn build(self) -> Result<WasmSdk, WasmSdkError> {
let sdk = self.inner.build().map_err(WasmSdkError::from)?;
if let Err(e) = sdk.refresh_protocol_version().await {
tracing::warn!(
error = %e,
"protocol version refresh failed on init; proceeding with floor version"
);
}
Comment on lines 337 to +343
Ok(WasmSdk {
sdk,
trusted_context: self.trusted_context,
Expand Down
Loading