Skip to content

Commit 912a389

Browse files
committed
Separate storage write operations from RW
1 parent 511bba3 commit 912a389

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

wallet/src/account/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ use std::collections::{BTreeMap, BTreeSet};
7575
use std::ops::{Add, Sub};
7676
use std::sync::Arc;
7777
use wallet_storage::{
78-
StoreTxRw, WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteLocked,
79-
WalletStorageWriteUnlocked,
78+
StoreTxRw, WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteLocked,
79+
WalletStorageWriteLocked, WalletStorageWriteUnlocked,
8080
};
8181
use wallet_types::utxo_types::{get_utxo_type, UtxoState, UtxoStates, UtxoType, UtxoTypes};
8282
use wallet_types::wallet_tx::{BlockData, TxData, TxState};
@@ -1955,7 +1955,7 @@ impl<K: AccountKeyChains> Account<K> {
19551955
pub fn scan_new_inmempool_transactions(
19561956
&mut self,
19571957
transactions: &[SignedTransaction],
1958-
db_tx: &mut impl WalletStorageWriteLocked,
1958+
db_tx: &mut impl WalletStorageReadWriteLocked,
19591959
wallet_events: &impl WalletEvents,
19601960
) -> WalletResult<()> {
19611961
self.scan_new_unconfirmed_transactions(
@@ -1969,7 +1969,7 @@ impl<K: AccountKeyChains> Account<K> {
19691969
pub fn scan_new_inactive_transactions(
19701970
&mut self,
19711971
transactions: &[SignedTransaction],
1972-
db_tx: &mut impl WalletStorageWriteLocked,
1972+
db_tx: &mut impl WalletStorageReadWriteLocked,
19731973
wallet_events: &impl WalletEvents,
19741974
) -> WalletResult<()> {
19751975
self.scan_new_unconfirmed_transactions(
@@ -1984,7 +1984,7 @@ impl<K: AccountKeyChains> Account<K> {
19841984
&mut self,
19851985
transactions: &[SignedTransaction],
19861986
make_tx_state: fn(u64) -> TxState,
1987-
db_tx: &mut impl WalletStorageWriteLocked,
1987+
db_tx: &mut impl WalletStorageReadWriteLocked,
19881988
wallet_events: &impl WalletEvents,
19891989
) -> WalletResult<()> {
19901990
let account_id = self.get_account_id();

wallet/src/key_chain/master_key_chain/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crypto::vrf::ExtendedVRFPrivateKey;
2222
use std::sync::Arc;
2323
use wallet_storage::{
2424
StoreTxRwUnlocked, WalletStorageReadLocked, WalletStorageReadUnlocked,
25-
WalletStorageWriteUnlocked,
25+
WalletStorageReadWriteUnlocked, WalletStorageWriteUnlocked,
2626
};
2727
use wallet_types::seed_phrase::{SerializableSeedPhrase, StoreSeedPhrase};
2828

@@ -131,7 +131,7 @@ impl MasterKeyChain {
131131

132132
pub fn create_account_key_chain(
133133
&self,
134-
db_tx: &mut impl WalletStorageWriteUnlocked,
134+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
135135
account_index: U31,
136136
lookahead_size: u32,
137137
) -> KeyChainResult<AccountKeyChainImplSoftware> {

wallet/src/signer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crypto::key::{
3434
SignatureError,
3535
};
3636
use wallet_storage::{
37-
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
37+
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteUnlocked,
3838
};
3939
use wallet_types::{
4040
partially_signed_transaction::PartiallySignedTransaction, signature_status::SignatureStatus,
@@ -145,7 +145,7 @@ pub trait SignerProvider {
145145
chain_config: Arc<ChainConfig>,
146146
account_index: U31,
147147
name: Option<String>,
148-
db_tx: &mut impl WalletStorageWriteUnlocked,
148+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
149149
) -> WalletResult<Account<Self::K>>;
150150

151151
fn load_account_from_database(

wallet/src/signer/software_signer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use itertools::Itertools;
4545
use randomness::make_true_rng;
4646
use wallet_storage::{
4747
StoreTxRwUnlocked, WalletStorageReadLocked, WalletStorageReadUnlocked,
48-
WalletStorageWriteUnlocked,
48+
WalletStorageReadWriteUnlocked,
4949
};
5050
use wallet_types::{
5151
partially_signed_transaction::PartiallySignedTransaction, seed_phrase::StoreSeedPhrase,
@@ -461,7 +461,7 @@ impl SignerProvider for SoftwareSignerProvider {
461461
chain_config: Arc<ChainConfig>,
462462
next_account_index: U31,
463463
name: Option<String>,
464-
db_tx: &mut impl WalletStorageWriteUnlocked,
464+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
465465
) -> WalletResult<Account<AccountKeyChainImplSoftware>> {
466466
let lookahead_size = db_tx.get_lookahead_size()?;
467467
let account_key_chain = self.master_key_chain.create_account_key_chain(

wallet/src/signer/trezor_signer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use trezor_client::{
7777
};
7878
use utils::ensure;
7979
use wallet_storage::{
80-
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
80+
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteUnlocked,
8181
};
8282
use wallet_types::{
8383
account_info::DEFAULT_ACCOUNT_INDEX,
@@ -1148,7 +1148,7 @@ impl SignerProvider for TrezorSignerProvider {
11481148
chain_config: Arc<ChainConfig>,
11491149
account_index: U31,
11501150
name: Option<String>,
1151-
db_tx: &mut impl WalletStorageWriteUnlocked,
1151+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
11521152
) -> WalletResult<Account<Self::K>> {
11531153
let account_pubkey = self.fetch_extended_pub_key(&chain_config, account_index)?;
11541154

wallet/src/wallet/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ pub use wallet_storage::Error;
7070
use wallet_storage::{
7171
DefaultBackend, Store, StoreTxRo, StoreTxRw, StoreTxRwUnlocked, TransactionRoLocked,
7272
TransactionRwLocked, TransactionRwUnlocked, Transactional, WalletStorageReadLocked,
73-
WalletStorageReadUnlocked, WalletStorageWriteLocked, WalletStorageWriteUnlocked,
73+
WalletStorageReadUnlocked, WalletStorageReadWriteLocked, WalletStorageReadWriteUnlocked,
74+
WalletStorageWriteLocked, WalletStorageWriteUnlocked,
7475
};
7576
use wallet_types::account_info::{StandaloneAddressDetails, StandaloneAddresses};
7677
use wallet_types::chain_info::ChainInfo;
@@ -670,7 +671,7 @@ where
670671

671672
fn reset_wallet_transactions(
672673
chain_config: Arc<ChainConfig>,
673-
db_tx: &mut impl WalletStorageWriteLocked,
674+
db_tx: &mut impl WalletStorageReadWriteLocked,
674675
) -> WalletResult<()> {
675676
db_tx.clear_transactions()?;
676677
db_tx.clear_addresses()?;
@@ -701,7 +702,7 @@ where
701702

702703
fn reset_wallet_transactions_and_load(
703704
chain_config: Arc<ChainConfig>,
704-
db_tx: &mut impl WalletStorageWriteLocked,
705+
db_tx: &mut impl WalletStorageReadWriteLocked,
705706
signer_provider: &P,
706707
) -> WalletResult<BTreeMap<U31, Account<P::K>>> {
707708
Self::reset_wallet_transactions(chain_config.clone(), db_tx)?;
@@ -723,7 +724,7 @@ where
723724

724725
fn migrate_next_unused_account(
725726
chain_config: Arc<ChainConfig>,
726-
db_tx: &mut impl WalletStorageWriteUnlocked,
727+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
727728
signer_provider: &mut P,
728729
) -> Result<(), WalletError> {
729730
let accounts_info = db_tx.get_accounts_info()?;
@@ -901,7 +902,7 @@ where
901902
fn create_next_unused_account(
902903
next_account_index: U31,
903904
chain_config: Arc<ChainConfig>,
904-
db_tx: &mut impl WalletStorageWriteUnlocked,
905+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
905906
name: Option<String>,
906907
signer_provider: &mut P,
907908
) -> WalletResult<(U31, Account<P::K>)> {

wallet/storage/src/internal/store_tx.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ impl<'st, B: storage::Backend> crate::TransactionRoUnlocked for StoreTxRoUnlocke
731731
}
732732
}
733733

734+
impl<'st, B: storage::Backend> crate::WalletStorageReadWriteLocked for StoreTxRw<'st, B> {}
735+
734736
impl<'st, B: storage::Backend> crate::TransactionRwLocked for StoreTxRw<'st, B> {
735737
fn commit(self) -> crate::Result<()> {
736738
self.storage.commit().map_err(Into::into)
@@ -741,6 +743,9 @@ impl<'st, B: storage::Backend> crate::TransactionRwLocked for StoreTxRw<'st, B>
741743
}
742744
}
743745

746+
impl<'st, B: storage::Backend> crate::WalletStorageReadWriteLocked for StoreTxRwUnlocked<'st, B> {}
747+
impl<'st, B: storage::Backend> crate::WalletStorageReadWriteUnlocked for StoreTxRwUnlocked<'st, B> {}
748+
744749
impl<'st, B: storage::Backend> crate::TransactionRwUnlocked for StoreTxRwUnlocked<'st, B> {
745750
fn commit(self) -> crate::Result<()> {
746751
self.storage.commit().map_err(Into::into)

wallet/storage/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub trait WalletStorageEncryptionRead {
137137
}
138138

139139
/// Modifying operations on persistent wallet data
140-
pub trait WalletStorageWriteLocked: WalletStorageReadLocked {
140+
pub trait WalletStorageWriteLocked {
141141
/// Set storage version
142142
fn set_storage_version(&mut self, version: u32) -> Result<()>;
143143
fn set_wallet_type(&mut self, wallet_type: WalletType) -> Result<()>;
@@ -200,7 +200,7 @@ pub trait WalletStorageWriteLocked: WalletStorageReadLocked {
200200
}
201201

202202
/// Modifying operations on persistent wallet data with access to encrypted data
203-
pub trait WalletStorageWriteUnlocked: WalletStorageReadUnlocked + WalletStorageWriteLocked {
203+
pub trait WalletStorageWriteUnlocked: WalletStorageWriteLocked {
204204
fn set_root_key(&mut self, content: &RootKeys) -> Result<()>;
205205
fn del_root_key(&mut self) -> Result<()>;
206206
fn set_seed_phrase(&mut self, seed_phrase: SerializableSeedPhrase) -> Result<()>;
@@ -221,6 +221,13 @@ pub trait WalletStorageEncryptionWrite {
221221
fn encrypt_seed_phrase(&mut self, new_encryption_key: &Option<SymmetricKey>) -> Result<()>;
222222
}
223223

224+
pub trait WalletStorageReadWriteLocked: WalletStorageReadLocked + WalletStorageWriteLocked {}
225+
226+
pub trait WalletStorageReadWriteUnlocked:
227+
WalletStorageReadUnlocked + WalletStorageWriteUnlocked + WalletStorageReadWriteLocked
228+
{
229+
}
230+
224231
/// Marker trait for types where read/write operations are run in a transaction
225232
pub trait IsTransaction: is_transaction_seal::Seal {}
226233

@@ -237,7 +244,7 @@ pub trait TransactionRoUnlocked: WalletStorageReadUnlocked + IsTransaction {
237244
}
238245

239246
/// Operations on read-write transactions
240-
pub trait TransactionRwLocked: WalletStorageWriteLocked + IsTransaction {
247+
pub trait TransactionRwLocked: WalletStorageReadWriteLocked + IsTransaction {
241248
/// Abort the transaction
242249
fn abort(self);
243250

@@ -246,7 +253,7 @@ pub trait TransactionRwLocked: WalletStorageWriteLocked + IsTransaction {
246253
}
247254

248255
/// Operations on read-write transactions
249-
pub trait TransactionRwUnlocked: WalletStorageWriteUnlocked + IsTransaction {
256+
pub trait TransactionRwUnlocked: WalletStorageReadWriteUnlocked + IsTransaction {
250257
/// Abort the transaction
251258
fn abort(self);
252259

@@ -284,7 +291,10 @@ pub trait Transactional<'t> {
284291
) -> Result<Self::TransactionRwUnlocked>;
285292
}
286293

287-
pub trait WalletStorage: WalletStorageWriteLocked + for<'tx> Transactional<'tx> + Send {}
294+
pub trait WalletStorage:
295+
WalletStorageWriteLocked + WalletStorageReadLocked + for<'tx> Transactional<'tx> + Send
296+
{
297+
}
288298

289299
pub type DefaultBackend = storage_sqlite::Sqlite;
290300
pub type WalletStorageTxRwImpl<'st> = StoreTxRw<'st, storage_sqlite::Sqlite>;

0 commit comments

Comments
 (0)