updating account souce to take multiple filters as input
This commit is contained in:
parent
d12a6b538d
commit
708f0d2755
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
@ -111,18 +111,20 @@ impl AccountStorageInterface for AccountsOnDemand {
|
|||
// create a notify for accounts under loading
|
||||
lk.insert(account_pk, Arc::new(Notify::new()));
|
||||
log::debug!("subscribing to accounts update : {}", account_pk);
|
||||
let mut hash_set = HashSet::new();
|
||||
hash_set.insert(account_pk);
|
||||
self.accounts_source
|
||||
.subscribe_account(account_pk)
|
||||
.subscribe_accounts(hash_set)
|
||||
.await
|
||||
.map_err(|_| AccountLoadingError::ErrorSubscribingAccount)?;
|
||||
drop(lk);
|
||||
|
||||
// save snapshot
|
||||
let account_filter = AccountFilter {
|
||||
let account_filter = vec![AccountFilter {
|
||||
accounts: vec![account_pk],
|
||||
program_id: None,
|
||||
filters: None,
|
||||
};
|
||||
}];
|
||||
self.accounts_source
|
||||
.save_snapshot(self.accounts_storage.clone(), account_filter)
|
||||
.await
|
||||
|
@ -204,7 +206,7 @@ impl AccountStorageInterface for AccountsOnDemand {
|
|||
.await;
|
||||
|
||||
self.accounts_source
|
||||
.save_snapshot(self.accounts_storage.clone(), account_filter)
|
||||
.save_snapshot(self.accounts_storage.clone(), vec![account_filter])
|
||||
.await
|
||||
.map_err(|_| AccountLoadingError::ErrorCreatingSnapshot)?;
|
||||
// update loading lock
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use crate::{
|
||||
account_filter::{AccountFilter, AccountFilterType},
|
||||
account_filter::{AccountFilterType, AccountFilters},
|
||||
account_store_interface::AccountStorageInterface,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use std::sync::Arc;
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
|
||||
// Source to create snapshot and subscribe to new accounts
|
||||
#[async_trait]
|
||||
pub trait AccountsSourceInterface: Send + Sync {
|
||||
async fn subscribe_account(&self, account: Pubkey) -> anyhow::Result<()>;
|
||||
async fn subscribe_accounts(&self, account: HashSet<Pubkey>) -> anyhow::Result<()>;
|
||||
|
||||
async fn subscribe_program_accounts(
|
||||
&self,
|
||||
|
@ -20,6 +20,6 @@ pub trait AccountsSourceInterface: Send + Sync {
|
|||
async fn save_snapshot(
|
||||
&self,
|
||||
storage: Arc<dyn AccountStorageInterface>,
|
||||
account_filter: AccountFilter,
|
||||
account_filters: AccountFilters,
|
||||
) -> anyhow::Result<()>;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue