Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): asset lock quorum and core locked height verification #2030

Open
wants to merge 20 commits into
base: v2.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b3f5f17
feat(sdk): asset lock quorum verify against platform
lklimek Jul 25, 2024
9de013f
feat(sdk)!: params of dash networks - testnet, mainnet, etc
lklimek Aug 15, 2024
6362883
feat(sdk): network type, continued
lklimek Aug 15, 2024
f984ced
feat: asset lock verify
lklimek Aug 15, 2024
bff31d5
refactor(dapi-client): replace CanRetry.is_node_failure with !CanRetr…
lklimek Aug 15, 2024
e3a5538
feat(sdk): Error implements CanRetry
lklimek Aug 15, 2024
4df0c40
fix(dapi-grpc): GetEpochsInfoRequest not marked as versioned
lklimek Aug 15, 2024
f41f2bc
test(sdk): asset locks verify tests, WIP
lklimek Aug 15, 2024
3517779
fix(sdk): local devnet uses LlmqTest
lklimek Aug 15, 2024
d9cada9
test(sdk): asset_lock test vectors
lklimek Aug 15, 2024
0c04b42
Merge remote-tracking branch 'origin/v1.1-dev' into fix/sdk-invalid-q…
lklimek Aug 15, 2024
c9c4a21
fix(dapi-grpc): fix const
lklimek Aug 16, 2024
f57e455
fix(sdk): build error due to imports
lklimek Aug 16, 2024
b5dfc6a
chore(sdk): cargo fmt
lklimek Aug 19, 2024
1f1c957
Merge remote-tracking branch 'origin/v1.1-dev' into fix/sdk-invalid-q…
lklimek Aug 21, 2024
c4cc766
Merge branch 'master' into fix/sdk-invalid-quorum
lklimek Aug 30, 2024
5d33c31
Merge remote-tracking branch 'origin/v1.7-dev' into fix/sdk-invalid-q…
lklimek Dec 10, 2024
727cc20
chore: fix build
lklimek Dec 10, 2024
50a5267
Merge branch 'v1.8-dev' into fix/sdk-invalid-quorum
lklimek Dec 13, 2024
ee83d83
Merge remote-tracking branch 'origin/v2.0-dev' into fix/sdk-invalid-q…
lklimek Feb 24, 2025
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
Prev Previous commit
Next Next commit
feat(sdk): network type, continued
  • Loading branch information
lklimek committed Aug 15, 2024
commit 6362883a6b7233b7db3488ff7f1ab42e51ef9c42
46 changes: 28 additions & 18 deletions packages/rs-sdk/src/networks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! Configuration of dash networks (devnet, testnet, mainnet, etc.).
//!
//! See also:
//! * https://github.com/dashpay/dash/blob/develop/src/chainparams.cpp

/*
Mainnet:
Expand All @@ -23,54 +26,61 @@ Devnet:

use dashcore_rpc::json::QuorumType;

/// Dash network types.
#[derive(Eq, PartialEq, Clone, Debug)]
pub enum NetworkType {
/// Mock implementation; in practice, feaults to Devnet config for Mock mode. Errors when used in non-mock mode.
Mock,
/// Mainnet network, used for production.
Mainnet,
/// Testnet network, used for testing and development.
Testnet,
/// Devnet network, used local for development.
Devnet,
Copy link
Member

Choose a reason for hiding this comment

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

Should receive quorum params

Mock,
Custom(NetworkConfig),
/// Custom network configuration.
Custom(QuorumParams),
Copy link
Member

Choose a reason for hiding this comment

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

Local

}

impl NetworkType {
pub fn instant_lock_quorum_type(&self) -> QuorumType {
self.to_network_config().instant_lock
self.to_quorum_params().instant_lock_quorum_type
}

fn to_network_config(&self) -> NetworkConfig {
pub(crate) fn to_quorum_params(&self) -> QuorumParams {
match self {
NetworkType::Mainnet => NetworkConfig::new_mainnet(),
NetworkType::Testnet => NetworkConfig::new_testnet(),
NetworkType::Devnet => NetworkConfig::new_devnet(),
NetworkType::Mock => NetworkConfig::new_mock(),
NetworkType::Mainnet => QuorumParams::new_mainnet(),
NetworkType::Testnet => QuorumParams::new_testnet(),
NetworkType::Devnet => QuorumParams::new_devnet(),
NetworkType::Custom(config) => config.clone(),
NetworkType::Mock => QuorumParams::new_mock(),
}
}
}

/// Configuration of Dash Core Quorums.
///
/// In most cases, you should use the [`new_mainnet`] or [`new_testnet`] functions to create a new instance.
#[derive(Clone, Debug)]
pub struct NetworkConfig {
pub instant_lock: QuorumType,
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct QuorumParams {
pub instant_lock_quorum_type: QuorumType,
}

impl NetworkConfig {
impl QuorumParams {
Copy link
Member

Choose a reason for hiding this comment

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

We have quorum params in Drive and dashcore library. I think the correct place for them is dashcore lib

pub fn new_mainnet() -> Self {
NetworkConfig {
instant_lock: QuorumType::Llmq400_60,
QuorumParams {
instant_lock_quorum_type: QuorumType::Llmq400_60,
}
}

pub fn new_testnet() -> Self {
NetworkConfig {
instant_lock: QuorumType::Llmq50_60,
QuorumParams {
instant_lock_quorum_type: QuorumType::Llmq50_60,
}
}

pub fn new_devnet() -> Self {
NetworkConfig {
instant_lock: QuorumType::LlmqDevnet,
QuorumParams {
instant_lock_quorum_type: QuorumType::LlmqDevnet,
}
}

Expand Down
30 changes: 23 additions & 7 deletions packages/rs-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::internal_cache::InternalSdkCache;
use crate::mock::MockResponse;
#[cfg(feature = "mocks")]
use crate::mock::{provider::GrpcContextProvider, MockDashPlatformSdk};
use crate::networks::NetworkType;
use crate::networks::{NetworkType, QuorumParams};
use crate::platform::transition::put_settings::PutSettings;
use crate::platform::{Fetch, Identifier};
use dapi_grpc::mock::Mockable;
Expand Down Expand Up @@ -79,6 +79,8 @@ pub type LastQueryTimestamp = u64;
#[derive(Clone)]
pub struct Sdk {
inner: SdkInstance,
/// Type of network we use. Determines some parameters, like quorum types.
network_type: NetworkType,
/// Use proofs when retrieving data from the platform.
///
/// This is set to `true` by default. `false` is not implemented yet.
Expand Down Expand Up @@ -420,6 +422,12 @@ impl Sdk {
}
}


/// Return configuration of quorum, like type of quorum used for instant lock.
pub(crate) fn quorum_params(&self) -> QuorumParams {
self.network_type.to_quorum_params()
}

/// Return [Dash Platform version](PlatformVersion) information used by this SDK.
///
///
Expand Down Expand Up @@ -499,8 +507,9 @@ impl DapiRequestExecutor for &Sdk {
/// Mandatory steps of initialization in normal mode are:
///
/// 1. Create an instance of [SdkBuilder] with [`SdkBuilder::new()`]
/// 2. Configure the builder with [`SdkBuilder::with_core()`]
/// 3. Call [`SdkBuilder::build()`] to create the [Sdk] instance.
/// 2. Set up network type with [`SdkBuilder::with_network_type()`] (not needed for mock)
/// 3. Configure the builder with [`SdkBuilder::with_core()`]
/// 4. Call [`SdkBuilder::build()`] to create the [Sdk] instance.
pub struct SdkBuilder {
/// List of addressses to connect to.
///
Expand Down Expand Up @@ -576,15 +585,14 @@ impl Default for SdkBuilder {
impl SdkBuilder {
/// Create a new SdkBuilder with provided address list.
///
/// It creates new SdkBuilder, preconfigured to connect to provided addresses on the [NetworkType::Testnet].
/// It creates new SdkBuilder, preconfigured to connect to provided addresses.
///
/// You can change this using [`SdkBuilder::with_network_type()`].
/// Once created, you need to set [NetworkType] with [`SdkBuilder::with_network_type()`].
pub fn new(addresses: AddressList) -> Self {
Self {
addresses: Some(addresses),
..Default::default()
}
.with_network_type(NetworkType::Testnet)
}

/// Create a new SdkBuilder that will generate mock client.
Expand Down Expand Up @@ -714,13 +722,20 @@ impl SdkBuilder {
let sdk= match self.addresses {
// non-mock mode
Some(addresses) => {
if self.network_type == NetworkType::Mock {
return Err(Error::Config(
"Network type must be set, use SdkBuilder::with_network_type()".to_string(),
));
}

let dapi = DapiClient::new(addresses, self.settings);
#[cfg(feature = "mocks")]
let dapi = dapi.dump_dir(self.dump_dir.clone());

#[allow(unused_mut)] // needs to be mutable for #[cfg(feature = "mocks")]
let mut sdk= Sdk{
inner:SdkInstance::Dapi { dapi, version:self.version },
network_type: self.network_type,
proofs:self.proofs,
context_provider: self.context_provider.map(Arc::new),
cancel_token: self.cancel_token,
Expand Down Expand Up @@ -770,7 +785,8 @@ impl SdkBuilder {
mock:Arc::new(Mutex::new( MockDashPlatformSdk::new(self.version, Arc::clone(&dapi), self.proofs))),
dapi,
version:self.version,
},
},
network_type: self.network_type,
dump_dir: self.dump_dir,
proofs:self.proofs,
internal_cache: Default::default(),
Expand Down