Skip to content

Commit 28ec848

Browse files
committed
Separate storage write operations from RW
1 parent 0801329 commit 28ec848

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
@@ -27,7 +27,7 @@ use common::chain::{
2727
};
2828
use crypto::key::hdkd::{derivable::DerivationError, u31::U31};
2929
use wallet_storage::{
30-
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
30+
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteUnlocked,
3131
};
3232
use wallet_types::{
3333
partially_signed_transaction::PartiallySignedTransaction, signature_status::SignatureStatus,
@@ -120,7 +120,7 @@ pub trait SignerProvider {
120120
chain_config: Arc<ChainConfig>,
121121
account_index: U31,
122122
name: Option<String>,
123-
db_tx: &mut impl WalletStorageWriteUnlocked,
123+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
124124
) -> WalletResult<Account<Self::K>>;
125125

126126
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,
@@ -441,7 +441,7 @@ impl SignerProvider for SoftwareSignerProvider {
441441
chain_config: Arc<ChainConfig>,
442442
next_account_index: U31,
443443
name: Option<String>,
444-
db_tx: &mut impl WalletStorageWriteUnlocked,
444+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
445445
) -> WalletResult<Account<AccountKeyChainImplSoftware>> {
446446
let lookahead_size = db_tx.get_lookahead_size()?;
447447
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,
@@ -1181,7 +1181,7 @@ impl SignerProvider for TrezorSignerProvider {
11811181
chain_config: Arc<ChainConfig>,
11821182
account_index: U31,
11831183
name: Option<String>,
1184-
db_tx: &mut impl WalletStorageWriteUnlocked,
1184+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
11851185
) -> WalletResult<Account<Self::K>> {
11861186
let account_pubkey = self.fetch_extended_pub_key(&chain_config, account_index)?;
11871187

wallet/src/wallet/mod.rs

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

670671
fn reset_wallet_transactions(
671672
chain_config: Arc<ChainConfig>,
672-
db_tx: &mut impl WalletStorageWriteLocked,
673+
db_tx: &mut impl WalletStorageReadWriteLocked,
673674
) -> WalletResult<()> {
674675
db_tx.clear_transactions()?;
675676
db_tx.clear_addresses()?;
@@ -700,7 +701,7 @@ where
700701

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

723724
fn migrate_next_unused_account(
724725
chain_config: Arc<ChainConfig>,
725-
db_tx: &mut impl WalletStorageWriteUnlocked,
726+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
726727
signer_provider: &mut P,
727728
) -> Result<(), WalletError> {
728729
let accounts_info = db_tx.get_accounts_info()?;
@@ -900,7 +901,7 @@ where
900901
fn create_next_unused_account(
901902
next_account_index: U31,
902903
chain_config: Arc<ChainConfig>,
903-
db_tx: &mut impl WalletStorageWriteUnlocked,
904+
db_tx: &mut impl WalletStorageReadWriteUnlocked,
904905
name: Option<String>,
905906
signer_provider: &mut P,
906907
) -> 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)