Skip to content

Commit

Permalink
Add support to configure indy_vdr, response cacher
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Aug 2, 2023
1 parent b409ee7 commit 4b84df6
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 282 deletions.
15 changes: 8 additions & 7 deletions agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;
use std::time::Duration;

use aries_vcx::core::profile::ledger::build_ledger_components;
use aries_vcx::core::profile::ledger::{build_ledger_components, VcxPoolConfig};
use aries_vcx::global::settings::DEFAULT_LINK_SECRET_ALIAS;
use aries_vcx::{
agency_client::{agency_client::AgencyClient, configuration::AgentProvisionConfig},
Expand All @@ -9,8 +10,7 @@ use aries_vcx::{
utils::provision::provision_cloud_agent,
};
use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite};
use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig;
use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, open_wallet, wallet_configure_issuer};
use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, wallet_configure_issuer};
use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig};
use url::Url;

Expand Down Expand Up @@ -75,11 +75,12 @@ impl Agent {
init_issuer_config(&config_issuer.institution_did).unwrap();
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));

let indy_vdr_pool_config = LedgerPoolConfig {
genesis_file_path: init_config.pool_config.genesis_path.clone(),
let pool_config = VcxPoolConfig {
genesis_file_path: init_config.pool_config.genesis_path,
indy_vdr_config: None,
response_cache_config: None,
};

let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), indy_vdr_pool_config).unwrap();
let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), pool_config).unwrap();
let anoncreds_ledger_read: Arc<dyn AnoncredsLedgerRead> = ledger_read.clone();
let anoncreds_ledger_write: Arc<dyn AnoncredsLedgerWrite> = ledger_write.clone();
let indy_ledger_read: Arc<dyn IndyLedgerRead> = ledger_read.clone();
Expand Down
35 changes: 25 additions & 10 deletions aries_vcx/src/core/profile/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@ use aries_vcx_core::ledger::indy_vdr_ledger::{
IndyVdrLedgerRead, IndyVdrLedgerReadConfig, IndyVdrLedgerWrite, IndyVdrLedgerWriteConfig, ProtocolVersion,
};
use aries_vcx_core::ledger::request_signer::base_wallet::BaseWalletRequestSigner;
use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig};
use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter};
use aries_vcx_core::ledger::response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::ResponseParser;
use aries_vcx_core::{PoolConfig, ResponseParser};
use std::sync::Arc;
use std::time::Duration;

pub struct VcxPoolConfig {
pub genesis_file_path: String,
pub indy_vdr_config: Option<PoolConfig>,
pub response_cache_config: Option<InMemoryResponseCacherConfig>,
}

pub fn build_ledger_components(
wallet: Arc<dyn BaseWallet>,
ledger_pool_config: LedgerPoolConfig,
pool_config: VcxPoolConfig,
) -> VcxResult<(
Arc<IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>>,
Arc<IndyVdrLedgerWrite<IndyVdrSubmitter, BaseWalletRequestSigner>>,
)> {
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let indy_vdr_config = match pool_config.indy_vdr_config {
None => PoolConfig::default(),
Some(cfg) => cfg,
};
let cache_config = match pool_config.response_cache_config {
None => InMemoryResponseCacherConfig::builder()
.ttl(Duration::from_secs(60))
.capacity(1000)?
.build(),
Some(cfg) => cfg,
};

let ledger_pool = Arc::new(IndyVdrLedgerPool::new(pool_config.genesis_file_path, indy_vdr_config)?);
let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));

let ledger_read = indyvdr_build_ledger_read(request_submitter.clone())?;
let ledger_read = indyvdr_build_ledger_read(request_submitter.clone(), cache_config)?;
let ledger_write = indyvdr_build_ledger_write(wallet, request_submitter, None);

let ledger_read = Arc::new(ledger_read);
Expand All @@ -32,13 +50,10 @@ pub fn build_ledger_components(

pub fn indyvdr_build_ledger_read(
request_submitter: Arc<IndyVdrSubmitter>,
cache_config: InMemoryResponseCacherConfig,
) -> VcxResult<IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>> {
let response_parser = Arc::new(ResponseParser::new());
let cacher_config = InMemoryResponseCacherConfig::builder()
.ttl(Duration::from_secs(60))
.capacity(1000)?
.build();
let response_cacher = Arc::new(InMemoryResponseCacher::new(cacher_config));
let response_cacher = Arc::new(InMemoryResponseCacher::new(cache_config));

let config_read = IndyVdrLedgerReadConfig {
request_submitter: request_submitter.clone(),
Expand Down
14 changes: 3 additions & 11 deletions aries_vcx/src/core/profile/modular_libs_profile.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
use std::sync::Arc;
use std::time::Duration;

use async_trait::async_trait;

use crate::core::profile::ledger::build_ledger_components;
use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_core::ledger::base_ledger::{
AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite, TaaConfigurator, TxnAuthrAgrmtOptions,
};
use aries_vcx_core::ledger::indy_vdr_ledger::{
IndyVdrLedgerRead, IndyVdrLedgerReadConfig, IndyVdrLedgerWrite, IndyVdrLedgerWriteConfig, ProtocolVersion,
};
use aries_vcx_core::ledger::request_signer::base_wallet::BaseWalletRequestSigner;
use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig};
use aries_vcx_core::ledger::response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::ResponseParser;

use crate::core::profile::ledger::{build_ledger_components, VcxPoolConfig};
use crate::errors::error::VcxResult;

use super::profile::Profile;
Expand All @@ -39,9 +31,9 @@ pub struct ModularLibsProfile {
}

impl ModularLibsProfile {
pub fn init(wallet: Arc<dyn BaseWallet>, ledger_pool_config: LedgerPoolConfig) -> VcxResult<Self> {
pub fn init(wallet: Arc<dyn BaseWallet>, vcx_pool_config: VcxPoolConfig) -> VcxResult<Self> {
let anoncreds = Arc::new(IndyCredxAnonCreds::new(Arc::clone(&wallet)));
let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), ledger_pool_config)?;
let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), vcx_pool_config)?;

Ok(ModularLibsProfile {
wallet,
Expand Down
26 changes: 16 additions & 10 deletions aries_vcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::WalletHandle;
use chrono::{DateTime, Duration, Utc};
use futures::future::BoxFuture;
use uuid::Uuid;

use crate::core::profile::ledger::build_ledger_components;
use crate::core::profile::ledger::{build_ledger_components, VcxPoolConfig};
use agency_client::agency_client::AgencyClient;
use agency_client::configuration::AgentProvisionConfig;
use agency_client::testing::mocking::{enable_agency_mocks, AgencyMockDecrypted};
use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite};
use aries_vcx_core::ledger::indy::pool::test_utils::{create_testpool_genesis_txn_file, get_temp_file_path};
use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig;
use aries_vcx_core::wallet::indy::did_mocks::DidMocks;
use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, open_wallet, wallet_configure_issuer};
use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, wallet_configure_issuer};
use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig};

#[cfg(feature = "modular_libs")]
use crate::core::profile::modular_libs_profile::ModularLibsProfile;
use crate::core::profile::prepare_taa_options;
use crate::core::profile::profile::Profile;
#[cfg(feature = "vdrtools")]
use crate::core::profile::vdrtools_profile::VdrtoolsProfile;
Expand Down Expand Up @@ -116,7 +113,12 @@ impl Drop for SetupMocks {
#[cfg(feature = "migration")]
pub fn make_modular_profile(wallet_handle: WalletHandle, genesis_file_path: String) -> Arc<ModularLibsProfile> {
let wallet = IndySdkWallet::new(wallet_handle);
Arc::new(ModularLibsProfile::init(Arc::new(wallet), LedgerPoolConfig { genesis_file_path }).unwrap())
let vcx_pool_config = VcxPoolConfig {
genesis_file_path: genesis_file_path.clone(),
indy_vdr_config: None,
response_cache_config: None,
};
Arc::new(ModularLibsProfile::init(Arc::new(wallet), vcx_pool_config).unwrap())
}

impl SetupProfile {
Expand Down Expand Up @@ -155,11 +157,13 @@ impl SetupProfile {
async fn build_profile_vdrtools(genesis_file_path: String) -> SetupProfile {
let (institution_did, wallet_handle) = setup_issuer_wallet().await;
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));
let indy_vdr_pool_config = LedgerPoolConfig {
let vcx_pool_config = VcxPoolConfig {
genesis_file_path: genesis_file_path.clone(),
indy_vdr_config: None,
response_cache_config: None,
};

let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), indy_vdr_pool_config).unwrap();
let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), vcx_pool_config).unwrap();
let anoncreds_ledger_read: Arc<dyn AnoncredsLedgerRead> = ledger_read.clone();
let anoncreds_ledger_write: Arc<dyn AnoncredsLedgerWrite> = ledger_write.clone();
let indy_ledger_read: Arc<dyn IndyLedgerRead> = ledger_read.clone();
Expand Down Expand Up @@ -189,11 +193,13 @@ impl SetupProfile {
let (institution_did, wallet_handle) = setup_issuer_wallet().await;

let wallet = IndySdkWallet::new(wallet_handle);
let indy_vdr_pool_config = LedgerPoolConfig {
let vcx_pool_config = VcxPoolConfig {
genesis_file_path: genesis_file_path.clone(),
indy_vdr_config: None,
response_cache_config: None,
};

let profile = Arc::new(ModularLibsProfile::init(Arc::new(wallet), indy_vdr_pool_config).unwrap());
let profile = Arc::new(ModularLibsProfile::init(Arc::new(wallet), vcx_pool_config).unwrap());

async fn modular_teardown() {
warn!("build_profile_modular::modular_teardown")
Expand Down
12 changes: 1 addition & 11 deletions aries_vcx/tests/utils/devsetup_alice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ use agency_client::agency_client::AgencyClient;
use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig};
use agency_client::MessageStatusCode;
use aries_vcx::common::ledger::transactions::into_did_doc;
#[cfg(feature = "modular_libs")]
use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile;
use aries_vcx::core::profile::profile::Profile;
use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile;
use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};
use aries_vcx::global::settings;
use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection};
use aries_vcx::handlers::issuance::holder::test_utils::get_credential_offer_messages;
use aries_vcx::handlers::issuance::holder::Holder;
Expand All @@ -24,14 +20,8 @@ use aries_vcx::handlers::util::{AnyInvitation, Status};
use aries_vcx::protocols::issuance::holder::state_machine::HolderState;
use aries_vcx::protocols::mediated_connection::invitee::state_machine::InviteeState;
use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState;
use aries_vcx::utils::devsetup::{SetupPoolDirectory, SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY};
use aries_vcx::utils::devsetup::{SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY};
use aries_vcx::utils::provision::provision_cloud_agent;
#[cfg(feature = "modular_libs")]
use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig;
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet::indy::wallet::open_wallet;
use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig};
use aries_vcx_core::WalletHandle;
use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential;
use messages::msg_fields::protocols::cred_issuance::CredentialIssuance;
use messages::msg_fields::protocols::present_proof::request::RequestPresentation;
Expand Down
7 changes: 1 addition & 6 deletions aries_vcx/tests/utils/devsetup_faber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ use aries_vcx::protocols::mediated_connection::inviter::state_machine::InviterSt
use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState;
use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus;
use aries_vcx::protocols::revocation_notification::sender::state_machine::SenderConfigBuilder;
use aries_vcx::utils::devsetup::{SetupPoolDirectory, SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY};
use aries_vcx::utils::devsetup::{SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY};
use aries_vcx::utils::provision::provision_cloud_agent;
#[cfg(feature = "modular_libs")]
use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig;
use aries_vcx_core::wallet::indy::wallet::{open_wallet, wallet_configure_issuer};
use aries_vcx_core::wallet::indy::{IssuerConfig, WalletConfig};
use aries_vcx_core::WalletHandle;
use diddoc_legacy::aries::service::AriesService;
use messages::decorators::please_ack::AckOn;
use messages::msg_fields::protocols::connection::invitation::public::{PublicInvitation, PublicInvitationContent};
Expand Down
21 changes: 0 additions & 21 deletions aries_vcx/tests/utils/devsetup_util.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
use std::sync::Arc;

use futures::future::BoxFuture;

#[cfg(feature = "modular_libs")]
use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile;
use aries_vcx::core::profile::profile::Profile;
use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile;
use aries_vcx::global::settings;
#[cfg(feature = "modular_libs")]
use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig;
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet::indy::wallet::open_wallet;
use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig};
use aries_vcx_core::WalletHandle;

use crate::utils::devsetup_alice::Alice;

#[cfg(test)]
pub mod test_utils {
use std::collections::HashMap;
use std::sync::Arc;

use agency_client::api::downloaded_message::DownloadedMessage;
#[cfg(feature = "modular_libs")]
use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile;
use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};
#[cfg(feature = "modular_libs")]
use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig;
use aries_vcx_core::wallet::indy::wallet::{close_wallet, delete_wallet};
use aries_vcx_core::wallet::indy::WalletConfig;
use aries_vcx_core::WalletHandle;
use messages::msg_fields::protocols::connection::Connection;
use messages::msg_fields::protocols::cred_issuance::CredentialIssuance;
use messages::msg_fields::protocols::present_proof::PresentProof;
Expand Down
9 changes: 2 additions & 7 deletions aries_vcx/tests/utils/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ use async_trait::async_trait;
use uuid::Uuid;

use aries_vcx::utils::devsetup::make_modular_profile;
use aries_vcx::{
core::profile::modular_libs_profile::ModularLibsProfile, global::settings::WALLET_KDF_RAW,
utils::devsetup::SetupProfile,
};
use aries_vcx::{global::settings::WALLET_KDF_RAW, utils::devsetup::SetupProfile};
use aries_vcx_core::wallet::agency_client_wallet::ToBaseAgencyClientWallet;
use aries_vcx_core::wallet::indy::wallet::create_and_open_wallet;
use aries_vcx_core::wallet::indy::IndySdkWallet;
use aries_vcx_core::wallet::indy::WalletConfig;
use aries_vcx_core::{
ledger::request_submitter::vdr_ledger::LedgerPoolConfig, wallet::base_wallet::BaseWallet, WalletHandle,
};
use aries_vcx_core::{wallet::base_wallet::BaseWallet, WalletHandle};

use crate::utils::devsetup_alice::Alice;
use crate::utils::devsetup_faber::Faber;
Expand Down
9 changes: 1 addition & 8 deletions aries_vcx_core/src/ledger/indy/pool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use indy_vdr::config::PoolConfig;
use serde::{Deserialize, Serialize};
use serde_json::Value;

Expand Down Expand Up @@ -227,11 +228,3 @@ pub mod test_utils {
f.sync_all().unwrap();
}
}

#[derive(Clone, Debug, Default, Builder, Serialize, Deserialize)]
#[builder(setter(into, strip_option), default)]
pub struct PoolConfig {
pub genesis_path: String,
pub pool_name: Option<String>,
pub pool_config: Option<Value>,
}
11 changes: 3 additions & 8 deletions aries_vcx_core/src/ledger/request_submitter/vdr_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResu

use super::RequestSubmitter;

pub struct LedgerPoolConfig {
pub genesis_file_path: String,
}

pub struct IndyVdrLedgerPool {
pub(self) runner: Option<PoolRunner>,
}
Expand All @@ -32,11 +28,10 @@ impl IndyVdrLedgerPool {
IndyVdrLedgerPool { runner: Some(runner) }
}

pub fn new(config: LedgerPoolConfig) -> VcxCoreResult<Self> {
let vdr_config = PoolConfig::default();
let txns = PoolTransactions::from_json_file(config.genesis_file_path)?;
pub fn new(genesis_file_path: String, indy_vdr_config: PoolConfig) -> VcxCoreResult<Self> {
let txns = PoolTransactions::from_json_file(genesis_file_path)?;

let runner = PoolBuilder::from(vdr_config).transactions(txns)?.into_runner()?;
let runner = PoolBuilder::from(indy_vdr_config).transactions(txns)?.into_runner()?;

Ok(IndyVdrLedgerPool { runner: Some(runner) })
}
Expand Down
2 changes: 2 additions & 0 deletions aries_vcx_core/src/ledger/response_cacher/in_memory/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{num::NonZeroUsize, time::Duration};
use serde::Deserialize;

use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind};

#[derive(Clone, Debug, Deserialize)]
pub struct InMemoryResponseCacherConfig {
ttl: Duration,
capacity: NonZeroUsize,
Expand Down
2 changes: 2 additions & 0 deletions aries_vcx_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ pub use vdrtools::{SearchHandle, WalletHandle, INVALID_SEARCH_HANDLE, INVALID_WA
pub use indy_vdr_proxy_client::VdrProxyClient;

pub use indy_ledger_response_parser::ResponseParser;

pub use indy_vdr::config::PoolConfig;
Loading

0 comments on commit 4b84df6

Please sign in to comment.