diff --git a/Cargo.lock b/Cargo.lock index 5f096f5d5c..2ff0329d74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4294,9 +4294,9 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +checksum = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653" dependencies = [ "cpufeatures", ] diff --git a/api-server/scanner-lib/src/sync/tests/mod.rs b/api-server/scanner-lib/src/sync/tests/mod.rs index 6ff7486edb..83fa63f6d2 100644 --- a/api-server/scanner-lib/src/sync/tests/mod.rs +++ b/api-server/scanner-lib/src/sync/tests/mod.rs @@ -206,7 +206,7 @@ fn create_chain( count: usize, ) { let mut tf = node.tf.lock().unwrap(); - let parent_id = tf.chainstate.get_block_id_from_height(&parent.into()).unwrap().unwrap(); + let parent_id = tf.chainstate.get_block_id_from_height(parent.into()).unwrap().unwrap(); tf.create_chain(&parent_id, count, rng).unwrap(); } @@ -1077,7 +1077,7 @@ async fn sync_and_compare( .block_height(); local_state.scan_blocks(block_height, vec![block]).await.unwrap(); - let node_data = tf.chainstate.get_stake_pool_data(pool_id).unwrap().unwrap(); + let node_data = tf.chainstate.get_stake_pool_data(&pool_id).unwrap().unwrap(); let tx = local_state.storage().transaction_ro().await.unwrap(); let scanner_data = tx.get_pool_data(pool_id).await.unwrap().unwrap(); @@ -1101,7 +1101,7 @@ async fn sync_and_compare( let node_delegations = tf .chainstate - .get_stake_pool_delegations_shares(pool_id) + .get_stake_pool_delegations_shares(&pool_id) .unwrap() .unwrap_or_default(); diff --git a/api-server/scanner-lib/src/sync/tests/simulation.rs b/api-server/scanner-lib/src/sync/tests/simulation.rs index 890fbbd391..75d1040310 100644 --- a/api-server/scanner-lib/src/sync/tests/simulation.rs +++ b/api-server/scanner-lib/src/sync/tests/simulation.rs @@ -82,7 +82,7 @@ impl PoSAccountingView for PoSAccountingAdapterToCheckFees<'_> { &self, pool_id: PoolId, ) -> Result, Self::Error> { - Ok(self.chainstate.get_stake_pool_data(pool_id).unwrap()) + Ok(self.chainstate.get_stake_pool_data(&pool_id).unwrap()) } fn get_pool_delegations_shares( @@ -366,7 +366,7 @@ async fn simulation( let block_height_to_continue_from = BlockHeight::new(height_to_continue_from as u64); let mut prev_block_hash = tf .chainstate - .get_block_id_from_height(&block_height_to_continue_from) + .get_block_id_from_height(block_height_to_continue_from) .unwrap() .unwrap(); @@ -789,7 +789,7 @@ async fn check_utxo( let utxo_block_id = block_id.classify(tf.chainstate.get_chain_config()); let time_of_tx = match utxo_block_id { GenBlockId::Block(id) => { - tf.chainstate.get_block_header(id).unwrap().unwrap().timestamp() + tf.chainstate.get_block_header(&id).unwrap().unwrap().timestamp() } GenBlockId::Genesis(_) => { tf.chainstate.get_chain_config().genesis_block().timestamp() @@ -868,13 +868,13 @@ async fn check_pool( let tx = local_state.storage().transaction_ro().await.unwrap(); let scanner_data = tx.get_pool_data(pool_id).await.unwrap().unwrap(); - if let Some(node_data) = tf.chainstate.get_stake_pool_data(pool_id).unwrap() { + if let Some(node_data) = tf.chainstate.get_stake_pool_data(&pool_id).unwrap() { // check all fields are the same assert_eq!(node_data, scanner_data.pool_data); // check delegations_balance let node_pool_balance = - tf.chainstate.get_stake_pool_balance(pool_id).unwrap().unwrap_or(Amount::ZERO); + tf.chainstate.get_stake_pool_balance(&pool_id).unwrap().unwrap_or(Amount::ZERO); let scanner_pool_balance = (scanner_data.staker_balance().unwrap() + scanner_data.delegations_balance).unwrap(); assert_eq!(node_pool_balance, scanner_pool_balance); @@ -887,7 +887,7 @@ async fn check_pool( // Compare the delegation shares let node_delegations = tf .chainstate - .get_stake_pool_delegations_shares(pool_id) + .get_stake_pool_delegations_shares(&pool_id) .unwrap() .unwrap_or_default(); @@ -926,7 +926,7 @@ async fn check_delegation( let tx = local_state.storage().transaction_ro().await.unwrap(); let scanner_data = tx.get_delegation(delegation_id).await.unwrap().unwrap(); - if let Some(node_data) = tf.chainstate.get_stake_delegation_data(delegation_id).unwrap() { + if let Some(node_data) = tf.chainstate.get_stake_delegation_data(&delegation_id).unwrap() { assert_eq!(node_data.source_pool(), scanner_data.pool_id()); assert_eq!( node_data.spend_destination(), @@ -936,14 +936,14 @@ async fn check_delegation( // check delegation balances are the same let node_delegation_balance = tf .chainstate - .get_stake_delegation_balance(delegation_id) + .get_stake_delegation_balance(&delegation_id) .unwrap() .unwrap_or(Amount::ZERO); assert_eq!(node_delegation_balance, *scanner_data.balance()); let node_acc_next_nonce = tf .chainstate - .get_account_nonce_count(AccountType::Delegation(delegation_id)) + .get_account_nonce_count(&AccountType::Delegation(delegation_id)) .unwrap() .map_or(AccountNonce::new(0), |nonce| nonce.increment().unwrap()); assert_eq!(&node_acc_next_nonce, scanner_data.next_nonce()); @@ -969,7 +969,7 @@ async fn check_token( token_id: TokenId, ) { let tx = local_state.storage().transaction_ro().await.unwrap(); - let node_data = tf.chainstate.get_token_info_for_rpc(token_id).unwrap().unwrap(); + let node_data = tf.chainstate.get_token_info_for_rpc(&token_id).unwrap().unwrap(); match node_data { RPCTokenInfo::FungibleToken(node_data) => { diff --git a/blockprod/src/detail/utils.rs b/blockprod/src/detail/utils.rs index bc54ca6246..731a51ea7c 100644 --- a/blockprod/src/detail/utils.rs +++ b/blockprod/src/detail/utils.rs @@ -47,7 +47,7 @@ pub fn get_pool_staker_balance( pool_id: &PoolId, ) -> Result { let balance = chainstate - .get_stake_pool_data(*pool_id) + .get_stake_pool_data(pool_id) .map_err(|err| { BlockProductionError::ChainstateError( consensus::ChainstateError::StakePoolDataReadError(*pool_id, err.to_string()), @@ -65,7 +65,7 @@ pub fn get_pool_total_balance( pool_id: &PoolId, ) -> Result { let pool_balance = chainstate - .get_stake_pool_balance(*pool_id) + .get_stake_pool_balance(pool_id) .map_err(|err| { BlockProductionError::ChainstateError(consensus::ChainstateError::PoolBalanceReadError( *pool_id, @@ -263,7 +263,7 @@ pub fn get_block_id_from_height( height: BlockHeight, ) -> Result, BlockProductionError> { let block_id = chainstate - .get_block_id_from_height(&height) + .get_block_id_from_height(height) .map_err(|err| { BlockProductionError::ChainstateError( consensus::ChainstateError::FailedToObtainBlockIdFromHeight( diff --git a/blockprod/src/lib.rs b/blockprod/src/lib.rs index 958196ee9c..f8185d2d21 100644 --- a/blockprod/src/lib.rs +++ b/blockprod/src/lib.rs @@ -178,7 +178,7 @@ mod tests { key::{KeyKind, PrivateKey}, vrf::{VRFKeyKind, VRFPrivateKey}, }; - use mempool::{MempoolConfig, MempoolHandle}; + use mempool::{MempoolConfig, MempoolHandle, MempoolInit}; use p2p::{ peer_manager::peerdb::storage_impl::PeerDbStorageImpl, test_helpers::test_p2p_config, }; @@ -291,13 +291,13 @@ mod tests { let chainstate = manager.add_subsystem("chainstate", chainstate); - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( Arc::clone(&chain_config), mempool_config, subsystem::Handle::clone(&chainstate), time_getter.clone(), ); - let mempool = manager.add_custom_subsystem("mempool", |hdl| mempool.init(hdl)); + let mempool = manager.add_custom_subsystem("mempool", |hdl| mempool_init.init(hdl)); let mut p2p_config = test_p2p_config(); p2p_config.bind_addresses = vec![SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0).into()]; diff --git a/chainstate/src/detail/bootstrap.rs b/chainstate/src/detail/bootstrap.rs index 359b2a4513..e6a82baeed 100644 --- a/chainstate/src/detail/bootstrap.rs +++ b/chainstate/src/detail/bootstrap.rs @@ -122,7 +122,7 @@ where for block_id in blocks_list { writer.write_all(magic_bytes)?; - let block = query_interface.get_existing_block(block_id)?; + let block = query_interface.get_existing_block(&block_id)?; writer.write_all(&block.encode())?; } Ok(()) diff --git a/chainstate/src/detail/chainstateref/consistency_checker.rs b/chainstate/src/detail/chainstateref/consistency_checker.rs index cef952e44a..6dc06c5ffa 100644 --- a/chainstate/src/detail/chainstateref/consistency_checker.rs +++ b/chainstate/src/detail/chainstateref/consistency_checker.rs @@ -137,7 +137,7 @@ impl<'a, DbTx: BlockchainStorageRead> ConsistencyChecker<'a, DbTx> { // in the block itself. if block_index.is_persisted() { let block = - self.db_tx.get_block(*block_id)?.expect("The block is known to be present"); + self.db_tx.get_block(block_id)?.expect("The block is known to be present"); let calculated_block_id = block.get_id(); assert_eq!( calculated_block_id, *block_id, diff --git a/chainstate/src/detail/chainstateref/mod.rs b/chainstate/src/detail/chainstateref/mod.rs index 4f6d23776f..325812be76 100644 --- a/chainstate/src/detail/chainstateref/mod.rs +++ b/chainstate/src/detail/chainstateref/mod.rs @@ -251,7 +251,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat #[log_error] pub fn get_block_id_by_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result>, PropertyQueryError> { self.db_tx.get_block_id_by_height(height).map_err(PropertyQueryError::from) } @@ -259,26 +259,26 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat #[log_error] pub fn get_existing_block_id_by_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result, PropertyQueryError> { self.get_block_id_by_height(height)? - .ok_or(PropertyQueryError::BlockForHeightNotFound(*height)) + .ok_or(PropertyQueryError::BlockForHeightNotFound(height)) } #[log_error] - pub fn get_block(&self, block_id: Id) -> Result, PropertyQueryError> { + pub fn get_block(&self, block_id: &Id) -> Result, PropertyQueryError> { self.db_tx.get_block(block_id).map_err(PropertyQueryError::from) } #[log_error] - pub fn block_exists(&self, block_id: Id) -> Result { + pub fn block_exists(&self, block_id: &Id) -> Result { self.db_tx.block_exists(block_id).map_err(PropertyQueryError::from) } #[log_error] pub fn get_block_header( &self, - block_id: Id, + block_id: &Id, ) -> Result, PropertyQueryError> { Ok(self.db_tx.get_block_header(block_id)?) } @@ -383,7 +383,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat #[log_error] pub fn get_header_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result, PropertyQueryError> { let id = self.get_existing_block_id_by_height(height)?; let id = id @@ -413,7 +413,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat #[log_error] pub fn get_account_nonce_count( &self, - account: AccountType, + account: &AccountType, ) -> Result, PropertyQueryError> { self.db_tx.get_account_nonce_count(account).map_err(PropertyQueryError::from) } @@ -430,7 +430,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat }; if let Some(block_index) = self.get_block_index(&id)? { - let mainchain_block_id = self.get_block_id_by_height(&block_index.block_height())?; + let mainchain_block_id = self.get_block_id_by_height(block_index.block_height())?; // Note: this function may be called when the chain is still empty, so we don't unwrap // mainchain_block_id and wrap gen_id instead. @@ -887,7 +887,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat &self, block_index: &BlockIndex, ) -> Result, chainstate_storage::Error> { - self.db_tx.get_block(*block_index.block_id()) + self.db_tx.get_block(block_index.block_id()) } #[log_error] @@ -958,7 +958,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat let id_from_height = |block_height: u64| -> Result, PropertyQueryError> { let block_height: BlockHeight = block_height.into(); let block_id = self - .get_block_id_by_height(&block_height)? + .get_block_id_by_height(block_height)? .expect("Since block_height is >= best_height, this must exist"); let block_id = block_id .classify(self.chain_config) @@ -1129,7 +1129,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat }; let lowest_block_id = self - .get_existing_block_id_by_height(&min_height) + .get_existing_block_id_by_height(min_height) .map_err(BlockError::PropertyQueryError)?; self.disconnect_tip_in_memory_until( @@ -1340,7 +1340,7 @@ impl ChainstateRe self.connect_transactions(block_index, &block)?; self.db_tx.set_block_id_at_height( - &block_index.block_height(), + block_index.block_height(), &(*block_index.block_id()).into(), )?; self.db_tx.set_best_block_id(&(*block_index.block_id()).into())?; @@ -1384,7 +1384,7 @@ impl ChainstateRe self.disconnect_transactions(&block.into())?; self.db_tx.set_best_block_id(block_index.prev_block_id())?; // Disconnect block - self.db_tx.del_block_id_at_height(&block_index.block_height())?; + self.db_tx.del_block_id_at_height(block_index.block_height())?; let prev_block_index = self .get_previous_block_index(&block_index) @@ -1415,7 +1415,7 @@ impl ChainstateRe #[log_error] pub fn persist_block(&mut self, block: &WithId) -> Result<(), BlockError> { - if self.db_tx.block_exists(block.get_id()).map_err(BlockError::from)? { + if self.db_tx.block_exists(&block.get_id()).map_err(BlockError::from)? { return Err(BlockError::BlockAlreadyExists(block.get_id())); } @@ -1450,7 +1450,7 @@ impl ChainstateRe "Trying to delete a block index for a persisted block {block_id}" ); - self.db_tx.del_block_index(*block_id)?; + self.db_tx.del_block_index(block_id)?; } Ok(()) } diff --git a/chainstate/src/detail/chainstateref/tx_verifier_storage.rs b/chainstate/src/detail/chainstateref/tx_verifier_storage.rs index 87f75fe84a..2d0559ffaf 100644 --- a/chainstate/src/detail/chainstateref/tx_verifier_storage.rs +++ b/chainstate/src/detail/chainstateref/tx_verifier_storage.rs @@ -78,7 +78,7 @@ impl TransactionVe match tx_source { TransactionSource::Chain(id) => { let undo = - self.db_tx.get_undo_data(id)?.map(CachedUtxosBlockUndo::from_utxo_block_undo); + self.db_tx.get_undo_data(&id)?.map(CachedUtxosBlockUndo::from_utxo_block_undo); Ok(undo) } TransactionSource::Mempool => { @@ -105,7 +105,7 @@ impl TransactionVe match tx_source { TransactionSource::Chain(id) => { let undo = - self.db_tx.get_pos_accounting_undo(id)?.map(CachedBlockUndo::from_block_undo); + self.db_tx.get_pos_accounting_undo(&id)?.map(CachedBlockUndo::from_block_undo); Ok(undo) } TransactionSource::Mempool => { @@ -123,7 +123,7 @@ impl TransactionVe TransactionSource::Chain(id) => { let undo = self .db_tx - .get_tokens_accounting_undo(id)? + .get_tokens_accounting_undo(&id)? .map(CachedBlockUndo::from_block_undo); Ok(undo) } @@ -139,7 +139,7 @@ impl TransactionVe account: AccountType, ) -> Result, TransactionVerifierStorageError> { self.db_tx - .get_account_nonce_count(account) + .get_account_nonce_count(&account) .map_err(TransactionVerifierStorageError::from) } @@ -153,7 +153,7 @@ impl TransactionVe TransactionSource::Chain(id) => { let undo = self .db_tx - .get_orders_accounting_undo(id)? + .get_orders_accounting_undo(&id)? .map(CachedBlockUndo::from_block_undo); Ok(undo) } @@ -264,7 +264,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .set_undo_data(id, &undo.clone().consume()) + .set_undo_data(&id, &undo.clone().consume()) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -280,7 +280,7 @@ impl TransactionV // TODO: check tx_source at compile-time (mintlayer/mintlayer-core#633) match tx_source { TransactionSource::Chain(id) => { - self.db_tx.del_undo_data(id).map_err(TransactionVerifierStorageError::from) + self.db_tx.del_undo_data(&id).map_err(TransactionVerifierStorageError::from) } TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -298,7 +298,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .set_pos_accounting_undo_data(id, &undo.clone().consume()) + .set_pos_accounting_undo_data(&id, &undo.clone().consume()) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -315,7 +315,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .del_pos_accounting_undo_data(id) + .del_pos_accounting_undo_data(&id) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -364,7 +364,7 @@ impl TransactionV nonce: AccountNonce, ) -> Result<(), ::Error> { self.db_tx - .set_account_nonce_count(account, nonce) + .set_account_nonce_count(&account, nonce) .map_err(TransactionVerifierStorageError::from) } @@ -374,7 +374,7 @@ impl TransactionV account: AccountType, ) -> Result<(), ::Error> { self.db_tx - .del_account_nonce_count(account) + .del_account_nonce_count(&account) .map_err(TransactionVerifierStorageError::from) } @@ -388,7 +388,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .set_tokens_accounting_undo_data(id, &undo.clone().consume()) + .set_tokens_accounting_undo_data(&id, &undo.clone().consume()) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -405,7 +405,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .del_tokens_accounting_undo_data(id) + .del_tokens_accounting_undo_data(&id) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -423,7 +423,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .set_orders_accounting_undo_data(id, &undo.clone().consume()) + .set_orders_accounting_undo_data(&id, &undo.clone().consume()) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") @@ -440,7 +440,7 @@ impl TransactionV match tx_source { TransactionSource::Chain(id) => self .db_tx - .del_orders_accounting_undo_data(id) + .del_orders_accounting_undo_data(&id) .map_err(TransactionVerifierStorageError::from), TransactionSource::Mempool => { panic!("Flushing mempool info into the storage is forbidden") diff --git a/chainstate/src/detail/mod.rs b/chainstate/src/detail/mod.rs index dc0d94f562..06466761d3 100644 --- a/chainstate/src/detail/mod.rs +++ b/chainstate/src/detail/mod.rs @@ -252,10 +252,10 @@ impl Chainstate // Look up the parent of block 1 to figure out the genesis ID according to storage let block1_id = dbtx - .get_block_id_by_height(&BlockHeight::new(1))? + .get_block_id_by_height(BlockHeight::new(1))? .ok_or(InitializationError::Block1Missing)?; let block1 = dbtx - .get_block(Id::new(block1_id.to_hash()))? + .get_block(&Id::new(block1_id.to_hash()))? .ok_or(InitializationError::Block1Missing)?; let stored_genesis_id = block1.prev_block_id(); @@ -672,7 +672,7 @@ impl Chainstate let mut db_tx = self.chainstate_storage.transaction_rw(None).map_err(BlockError::from)?; db_tx.set_best_block_id(&genesis_id).map_err(BlockError::StorageError)?; db_tx - .set_block_id_at_height(&BlockHeight::zero(), &genesis_id) + .set_block_id_at_height(BlockHeight::zero(), &genesis_id) .map_err(BlockError::StorageError)?; db_tx diff --git a/chainstate/src/detail/query.rs b/chainstate/src/detail/query.rs index 12fafd2b42..6882a743d9 100644 --- a/chainstate/src/detail/query.rs +++ b/chainstate/src/detail/query.rs @@ -67,31 +67,31 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat #[allow(dead_code)] pub fn get_header_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result, PropertyQueryError> { self.chainstate_ref.get_header_from_height(height) } pub fn get_block_header( &self, - id: Id, + id: &Id, ) -> Result, PropertyQueryError> { self.chainstate_ref.get_block_header(id) } pub fn get_block_id_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result>, PropertyQueryError> { self.chainstate_ref.get_block_id_by_height(height) } - pub fn get_block(&self, id: Id) -> Result, PropertyQueryError> { + pub fn get_block(&self, id: &Id) -> Result, PropertyQueryError> { self.chainstate_ref.get_block(id) } - pub fn get_existing_block(&self, id: Id) -> Result { - self.chainstate_ref.get_block(id)?.ok_or(PropertyQueryError::BlockNotFound(id)) + pub fn get_existing_block(&self, id: &Id) -> Result { + self.chainstate_ref.get_block(id)?.ok_or(PropertyQueryError::BlockNotFound(*id)) } pub fn get_mainchain_blocks( @@ -106,14 +106,14 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat let mut res = Vec::new(); for _ in 0..max_count { - match self.get_block_id_from_height(&from)? { + match self.get_block_id_from_height(from)? { Some(get_block_id) => { match get_block_id.classify(self.chainstate_ref.chain_config()) { common::chain::GenBlockId::Genesis(_) => { panic!("genesis block received at non-zero height {from}") } common::chain::GenBlockId::Block(block_id) => { - let block = self.get_block(block_id)?.unwrap_or_else(|| { + let block = self.get_block(&block_id)?.unwrap_or_else(|| { panic!("can't find block {block_id} at height {from}") }); res.push(block); @@ -182,7 +182,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat ) -> Result { let headers = locator_tip_distances() .map_while(|dist| height - dist) - .map(|ht| self.chainstate_ref.get_block_id_by_height(&ht)); + .map(|ht| self.chainstate_ref.get_block_id_by_height(ht)); itertools::process_results(headers, |iter| iter.flatten().collect::>()) .map(Locator::new) @@ -218,7 +218,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat let height = BlockHeight::new(height); Ok(( height, - self.chainstate_ref.get_existing_block_id_by_height(&height)?, + self.chainstate_ref.get_existing_block_id_by_height(height)?, )) }); @@ -259,7 +259,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat let headers = itertools::iterate(height.next_height(), |iter| iter.next_height()) .take_while(|height| height <= &limit) - .map(|height| self.chainstate_ref.get_header_from_height(&height)); + .map(|height| self.chainstate_ref.get_header_from_height(height)); itertools::process_results(headers, |iter| iter.flatten().collect::>()) } @@ -311,16 +311,16 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat pub fn get_token_info_for_rpc( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, PropertyQueryError> { - if let Some(token_data) = self.chainstate_ref.get_token_data(&token_id)? { + if let Some(token_data) = self.chainstate_ref.get_token_data(token_id)? { let circulating_supply = - self.chainstate_ref.get_circulating_supply(&token_id)?.unwrap_or(Amount::ZERO); + self.chainstate_ref.get_circulating_supply(token_id)?.unwrap_or(Amount::ZERO); match token_data { tokens_accounting::TokenData::FungibleToken(token_data) => { let rpc_issuance = RPCTokenInfo::new_fungible(RPCFungibleTokenInfo::new( - token_id, + *token_id, token_data.token_ticker().to_owned(), token_data.number_of_decimals(), token_data.metadata_uri().to_owned(), @@ -334,7 +334,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat } } } else { - let token_aux_data = match self.get_token_aux_data(&token_id)? { + let token_aux_data = match self.get_token_aux_data(token_id)? { Some(data) => data, None => return Ok(None), }; @@ -358,7 +358,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat TxOutput::IssueNft(_, issuance, _) => match issuance.as_ref() { NftIssuance::V0(nft) => { Some(RPCTokenInfo::new_nonfungible(RPCNonFungibleTokenInfo::new( - token_id, + *token_id, token_aux_data.issuance_tx().get_id(), token_aux_data.issuance_block_id(), &nft.metadata, @@ -378,7 +378,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat token_ids .iter() .map(|id| -> Result<_, PropertyQueryError> { - self.get_token_info_for_rpc(*id)? + self.get_token_info_for_rpc(id)? .ok_or(PropertyQueryError::TokenInfoMissing(*id)) }) .collect::>() @@ -509,7 +509,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat let ask_balance = self.get_order_ask_balance(order_id)?.unwrap_or(Amount::ZERO); let give_balance = self.get_order_give_balance(order_id)?.unwrap_or(Amount::ZERO); - let nonce = self.chainstate_ref.get_account_nonce_count(AccountType::Order(*order_id))?; + let nonce = self.chainstate_ref.get_account_nonce_count(&AccountType::Order(*order_id))?; let initially_asked = RpcOutputValue::from_output_value(order_data.ask()) .ok_or(PropertyQueryError::UnsupportedTokenV0InOrder(*order_id))?; diff --git a/chainstate/src/detail/test.rs b/chainstate/src/detail/test.rs index 67f6431db1..641d20ec84 100644 --- a/chainstate/src/detail/test.rs +++ b/chainstate/src/detail/test.rs @@ -71,7 +71,7 @@ fn process_genesis_block() { assert_eq!(genesis_index.block_height(), BlockHeight::from(0)); assert_eq!(genesis_index.block_id(), genesis_id); let block_at_0 = - chainstate_ref.get_block_id_by_height(&BlockHeight::from(0)).unwrap().unwrap(); + chainstate_ref.get_block_id_by_height(BlockHeight::from(0)).unwrap().unwrap(); assert_eq!(block_at_0, genesis_id); assert_eq!(genesis_index.chain_trust(), Uint256::ZERO); }); diff --git a/chainstate/src/interface/chainstate_interface.rs b/chainstate/src/interface/chainstate_interface.rs index ad7abcc0fd..a1ba1edcb3 100644 --- a/chainstate/src/interface/chainstate_interface.rs +++ b/chainstate/src/interface/chainstate_interface.rs @@ -79,9 +79,9 @@ pub trait ChainstateInterface: Send + Sync { fn get_best_block_header(&self) -> Result; fn get_block_id_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result>, ChainstateError>; - fn get_block(&self, block_id: Id) -> Result, ChainstateError>; + fn get_block(&self, block_id: &Id) -> Result, ChainstateError>; fn get_mainchain_blocks( &self, from: BlockHeight, @@ -89,7 +89,7 @@ pub trait ChainstateInterface: Send + Sync { ) -> Result, ChainstateError>; fn get_block_header( &self, - block_id: Id, + block_id: &Id, ) -> Result, ChainstateError>; /// Returns a list of block headers whose heights distances increase exponentially starting @@ -208,7 +208,7 @@ pub trait ChainstateInterface: Send + Sync { /// Returns token info by `token_id`. fn get_token_info_for_rpc( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError>; /// Return infos for the specified token ids. @@ -220,7 +220,7 @@ pub trait ChainstateInterface: Send + Sync { /// Return token's auxiliary data; available for NFTs only. fn get_token_aux_data( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError>; /// Obtain token id given the id of the issuing tx; available for NFTs only. fn get_token_id_from_issuance_tx( @@ -289,10 +289,10 @@ pub trait ChainstateInterface: Send + Sync { fn is_initial_block_download(&self) -> bool; /// Check whether stake pool with given ID exists. - fn stake_pool_exists(&self, pool_id: PoolId) -> Result; + fn stake_pool_exists(&self, pool_id: &PoolId) -> Result; /// Get stake pool balance. See [pos_accounting::PoSAccountingView::get_pool_balance]. - fn get_stake_pool_balance(&self, pool_id: PoolId) -> Result, ChainstateError>; + fn get_stake_pool_balance(&self, pool_id: &PoolId) -> Result, ChainstateError>; /// Get balances of the specified stake pools at the specified heights (i.e. at the points /// when the mainchain tip had that particular height). @@ -307,35 +307,35 @@ pub trait ChainstateInterface: Send + Sync { ) -> Result>, ChainstateError>; /// Get stake pool data. See [pos_accounting::PoSAccountingView::get_pool_data]. - fn get_stake_pool_data(&self, pool_id: PoolId) -> Result, ChainstateError>; + fn get_stake_pool_data(&self, pool_id: &PoolId) -> Result, ChainstateError>; /// Get all delegation shares for given stake pool. /// See [pos_accounting::PoSAccountingView::get_pool_delegations_shares]. fn get_stake_pool_delegations_shares( &self, - pool_id: PoolId, + pool_id: &PoolId, ) -> Result>, ChainstateError>; /// Get delegation balance for given stake pool delegation ID. /// See [pos_accounting::PoSAccountingView::get_delegation_balance]. fn get_stake_delegation_balance( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError>; /// Get data for given stake pool delegation ID. /// See [pos_accounting::PoSAccountingView::get_delegation_data]. fn get_stake_delegation_data( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError>; /// Get delegation share for given stake pool and delegation. /// See [pos_accounting::PoSAccountingView::get_pool_delegation_share]. fn get_stake_pool_delegation_share( &self, - pool_id: PoolId, - delegation_id: DelegationId, + pool_id: &PoolId, + delegation_id: &DelegationId, ) -> Result, ChainstateError>; /// Returns information about the chain. @@ -344,6 +344,6 @@ pub trait ChainstateInterface: Send + Sync { /// Returns account nonce for the account fn get_account_nonce_count( &self, - account: AccountType, + account: &AccountType, ) -> Result, ChainstateError>; } diff --git a/chainstate/src/interface/chainstate_interface_impl.rs b/chainstate/src/interface/chainstate_interface_impl.rs index 3ab6ea4a0a..aeeb944ea5 100644 --- a/chainstate/src/interface/chainstate_interface_impl.rs +++ b/chainstate/src/interface/chainstate_interface_impl.rs @@ -192,7 +192,7 @@ where #[tracing::instrument(skip_all, fields(height = %height))] fn get_block_id_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result>, ChainstateError> { self.chainstate .query() @@ -202,7 +202,7 @@ where } #[tracing::instrument(skip_all, fields(id = %block_id))] - fn get_block(&self, block_id: Id) -> Result, ChainstateError> { + fn get_block(&self, block_id: &Id) -> Result, ChainstateError> { self.chainstate .query() .map_err(ChainstateError::from)? @@ -226,7 +226,7 @@ where #[tracing::instrument(skip_all, fields(id = %block_id))] fn get_block_header( &self, - block_id: Id, + block_id: &Id, ) -> Result, ChainstateError> { self.chainstate .query() @@ -518,7 +518,7 @@ where #[tracing::instrument(skip_all, fields(token_id = %token_id))] fn get_token_info_for_rpc( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError> { self.chainstate .query() @@ -542,12 +542,12 @@ where #[tracing::instrument(skip_all, fields(token_id = %token_id))] fn get_token_aux_data( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError> { self.chainstate .query() .map_err(ChainstateError::from)? - .get_token_aux_data(&token_id) + .get_token_aux_data(token_id) .map_err(ChainstateError::FailedToReadProperty) } @@ -671,16 +671,16 @@ where } #[tracing::instrument(skip_all, fields(pool_id = %pool_id))] - fn stake_pool_exists(&self, pool_id: PoolId) -> Result { + fn stake_pool_exists(&self, pool_id: &PoolId) -> Result { self.get_stake_pool_data(pool_id).map(|v| v.is_some()) } #[tracing::instrument(skip_all, fields(pool_id = %pool_id))] - fn get_stake_pool_balance(&self, pool_id: PoolId) -> Result, ChainstateError> { + fn get_stake_pool_balance(&self, pool_id: &PoolId) -> Result, ChainstateError> { self.chainstate .make_db_tx_ro() .map_err(|e| ChainstateError::FailedToReadProperty(e.into()))? - .get_pool_balance(pool_id) + .get_pool_balance(*pool_id) .map_err(|e| ChainstateError::ProcessBlockError(e.into())) } @@ -699,60 +699,60 @@ where } #[tracing::instrument(skip_all, fields(pool_id = %pool_id))] - fn get_stake_pool_data(&self, pool_id: PoolId) -> Result, ChainstateError> { + fn get_stake_pool_data(&self, pool_id: &PoolId) -> Result, ChainstateError> { self.chainstate .make_db_tx_ro() .map_err(|e| ChainstateError::FailedToReadProperty(e.into()))? - .get_pool_data(pool_id) + .get_pool_data(*pool_id) .map_err(|e| ChainstateError::ProcessBlockError(e.into())) } #[tracing::instrument(skip_all, fields(pool_id = %pool_id))] fn get_stake_pool_delegations_shares( &self, - pool_id: PoolId, + pool_id: &PoolId, ) -> Result>, ChainstateError> { self.chainstate .make_db_tx_ro() .map_err(|e| ChainstateError::FailedToReadProperty(e.into()))? - .get_pool_delegations_shares(pool_id) + .get_pool_delegations_shares(*pool_id) .map_err(|e| ChainstateError::ProcessBlockError(e.into())) } #[tracing::instrument(skip_all, fields(delegation_id = %delegation_id))] fn get_stake_delegation_balance( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError> { self.chainstate .make_db_tx_ro() .map_err(|e| ChainstateError::FailedToReadProperty(e.into()))? - .get_delegation_balance(delegation_id) + .get_delegation_balance(*delegation_id) .map_err(|e| ChainstateError::ProcessBlockError(e.into())) } #[tracing::instrument(skip_all, fields(delegation_id = %delegation_id))] fn get_stake_delegation_data( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError> { self.chainstate .make_db_tx_ro() .map_err(|e| ChainstateError::FailedToReadProperty(e.into()))? - .get_delegation_data(delegation_id) + .get_delegation_data(*delegation_id) .map_err(|e| ChainstateError::ProcessBlockError(e.into())) } #[tracing::instrument(skip_all, fields(pool_id = %pool_id, delegation_id = %delegation_id))] fn get_stake_pool_delegation_share( &self, - pool_id: PoolId, - delegation_id: DelegationId, + pool_id: &PoolId, + delegation_id: &DelegationId, ) -> Result, ChainstateError> { self.chainstate .make_db_tx_ro() .map_err(|e| ChainstateError::FailedToReadProperty(e.into()))? - .get_pool_delegation_share(pool_id, delegation_id) + .get_pool_delegation_share(*pool_id, *delegation_id) .map_err(|e| ChainstateError::ProcessBlockError(e.into())) } @@ -779,7 +779,7 @@ where #[tracing::instrument(skip_all)] fn get_account_nonce_count( &self, - account: AccountType, + account: &AccountType, ) -> Result, ChainstateError> { self.chainstate .make_db_tx_ro() diff --git a/chainstate/src/interface/chainstate_interface_impl_delegation.rs b/chainstate/src/interface/chainstate_interface_impl_delegation.rs index a0fae05bba..8cb6c5701f 100644 --- a/chainstate/src/interface/chainstate_interface_impl_delegation.rs +++ b/chainstate/src/interface/chainstate_interface_impl_delegation.rs @@ -113,12 +113,12 @@ where fn get_block_id_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result>, ChainstateError> { self.deref().get_block_id_from_height(height) } - fn get_block(&self, block_id: Id) -> Result, ChainstateError> { + fn get_block(&self, block_id: &Id) -> Result, ChainstateError> { self.deref().get_block(block_id) } @@ -271,7 +271,7 @@ where fn get_token_info_for_rpc( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError> { self.deref().get_token_info_for_rpc(token_id) } @@ -285,7 +285,7 @@ where fn get_token_aux_data( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError> { self.deref().get_token_aux_data(token_id) } @@ -335,11 +335,11 @@ where self.deref().is_initial_block_download() } - fn stake_pool_exists(&self, pool_id: PoolId) -> Result { + fn stake_pool_exists(&self, pool_id: &PoolId) -> Result { self.deref().stake_pool_exists(pool_id) } - fn get_stake_pool_balance(&self, pool_id: PoolId) -> Result, ChainstateError> { + fn get_stake_pool_balance(&self, pool_id: &PoolId) -> Result, ChainstateError> { self.deref().get_stake_pool_balance(pool_id) } @@ -353,35 +353,35 @@ where .get_stake_pool_balances_at_heights(pool_ids, min_height, max_height) } - fn get_stake_pool_data(&self, pool_id: PoolId) -> Result, ChainstateError> { + fn get_stake_pool_data(&self, pool_id: &PoolId) -> Result, ChainstateError> { self.deref().get_stake_pool_data(pool_id) } fn get_stake_pool_delegations_shares( &self, - pool_id: PoolId, + pool_id: &PoolId, ) -> Result>, ChainstateError> { self.deref().get_stake_pool_delegations_shares(pool_id) } fn get_stake_delegation_balance( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError> { self.deref().get_stake_delegation_balance(delegation_id) } fn get_stake_delegation_data( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError> { self.deref().get_stake_delegation_data(delegation_id) } fn get_stake_pool_delegation_share( &self, - pool_id: PoolId, - delegation_id: DelegationId, + pool_id: &PoolId, + delegation_id: &DelegationId, ) -> Result, ChainstateError> { self.deref().get_stake_pool_delegation_share(pool_id, delegation_id) } @@ -392,14 +392,14 @@ where fn get_block_header( &self, - block_id: Id, + block_id: &Id, ) -> Result, ChainstateError> { self.deref().get_block_header(block_id) } fn get_account_nonce_count( &self, - account: AccountType, + account: &AccountType, ) -> Result, ChainstateError> { self.deref().get_account_nonce_count(account) } diff --git a/chainstate/src/rpc/mod.rs b/chainstate/src/rpc/mod.rs index 16508d0fde..0f06f72bd2 100644 --- a/chainstate/src/rpc/mod.rs +++ b/chainstate/src/rpc/mod.rs @@ -230,19 +230,19 @@ impl ChainstateRpcServer for super::ChainstateHandle { } async fn block_id_at_height(&self, height: BlockHeight) -> RpcResult>> { - rpc::handle_result(self.call(move |this| this.get_block_id_from_height(&height)).await) + rpc::handle_result(self.call(move |this| this.get_block_id_from_height(height)).await) } async fn get_block(&self, id: Id) -> RpcResult>> { let block: Option = - rpc::handle_result(self.call(move |this| this.get_block(id)).await)?; + rpc::handle_result(self.call(move |this| this.get_block(&id)).await)?; Ok(block.map(HexEncoded::new)) } async fn get_block_json(&self, id: Id) -> RpcResult> { let both: Option<(Block, BlockIndex)> = rpc::handle_result( self.call(move |this| { - let block = this.get_block(id); + let block = this.get_block(&id); let block_index = this.get_block_index_for_persisted_block(&id); match (block, block_index) { (Ok(block), Ok(block_index)) => Ok(block.zip(block_index)), @@ -377,7 +377,7 @@ impl ChainstateRpcServer for super::ChainstateHandle { self.call(move |this| { let chain_config = this.get_chain_config(); let id_result = pool_address.decode_object(chain_config); - id_result.map(|address| this.get_stake_pool_balance(address)) + id_result.map(|address| this.get_stake_pool_balance(&address)) }) .await, ) @@ -389,7 +389,7 @@ impl ChainstateRpcServer for super::ChainstateHandle { let chain_config = this.get_chain_config(); let result: Result, _> = dynamize_err(pool_address.decode_object(chain_config)) - .and_then(|pool_id| dynamize_err(this.get_stake_pool_data(pool_id))) + .and_then(|pool_id| dynamize_err(this.get_stake_pool_data(&pool_id))) .and_then(|pool_data| { dynamize_err(pool_data.map(|d| d.staker_balance()).transpose()) }); @@ -408,7 +408,7 @@ impl ChainstateRpcServer for super::ChainstateHandle { self.call(move |this| -> Result<_, DynamizedError> { let chain_config = this.get_chain_config(); let pool_id = dynamize_err(pool_address.decode_object(chain_config))?; - let pool_data = dynamize_err(this.get_stake_pool_data(pool_id))?; + let pool_data = dynamize_err(this.get_stake_pool_data(&pool_id))?; pool_data .map(|d| -> Result<_, DynamizedError> { @@ -441,7 +441,7 @@ impl ChainstateRpcServer for super::ChainstateHandle { let ids = pool_id_result.and_then(|x| delegation_id_result.map(|y| (x, y))); ids.and_then(|(pool_id, del_id)| { - dynamize_err(this.get_stake_pool_delegation_share(pool_id, del_id)) + dynamize_err(this.get_stake_pool_delegation_share(&pool_id, &del_id)) }) }) .await, @@ -454,7 +454,7 @@ impl ChainstateRpcServer for super::ChainstateHandle { let chain_config = this.get_chain_config(); let token_info_result: Result, _> = dynamize_err(token_id.decode_object(chain_config)) - .and_then(|token_id| dynamize_err(this.get_token_info_for_rpc(token_id))); + .and_then(|token_id| dynamize_err(this.get_token_info_for_rpc(&token_id))); token_info_result }) diff --git a/chainstate/storage/src/internal/mod.rs b/chainstate/storage/src/internal/mod.rs index 579758e6d9..3dd8c62ec7 100644 --- a/chainstate/storage/src/internal/mod.rs +++ b/chainstate/storage/src/internal/mod.rs @@ -57,7 +57,7 @@ impl Store { } if db_tx.get_magic_bytes()?.is_none() { - db_tx.set_magic_bytes(chain_config.magic_bytes())?; + db_tx.set_magic_bytes(*chain_config.magic_bytes())?; } if db_tx.get_chain_type()?.is_none() { diff --git a/chainstate/storage/src/internal/store_tx/read_impls.rs b/chainstate/storage/src/internal/store_tx/read_impls.rs index c075248292..c244b195bf 100644 --- a/chainstate/storage/src/internal/store_tx/read_impls.rs +++ b/chainstate/storage/src/internal/store_tx/read_impls.rs @@ -114,17 +114,17 @@ impl BlockchainStorageRead for super::StoreTxRo<'_, B } #[log_error] - fn get_block(&self, id: Id) -> crate::Result> { + fn get_block(&self, id: &Id) -> crate::Result> { self.read::(id) } #[log_error] - fn block_exists(&self, id: Id) -> crate::Result { + fn block_exists(&self, id: &Id) -> crate::Result { self.entry_exists::(id) } #[log_error] - fn get_block_header(&self, id: Id) -> crate::Result> { + fn get_block_header(&self, id: &Id) -> crate::Result> { let block_index = self.read::(id)?; Ok(block_index.map(|block_index| block_index.into_block_header())) } @@ -142,12 +142,12 @@ impl BlockchainStorageRead for super::StoreTxRo<'_, B } #[log_error] - fn get_block_id_by_height(&self, height: &BlockHeight) -> crate::Result>> { + fn get_block_id_by_height(&self, height: BlockHeight) -> crate::Result>> { self.read::(height) } #[log_error] - fn get_undo_data(&self, id: Id) -> crate::Result> { + fn get_undo_data(&self, id: &Id) -> crate::Result> { self.read::(id) } @@ -164,7 +164,7 @@ impl BlockchainStorageRead for super::StoreTxRo<'_, B #[log_error] fn get_tokens_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>> { self.read::(&id) } @@ -172,7 +172,7 @@ impl BlockchainStorageRead for super::StoreTxRo<'_, B #[log_error] fn get_orders_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>> { self.read::(id) } @@ -198,7 +198,7 @@ impl BlockchainStorageRead for super::StoreTxRo<'_, B #[log_error] fn get_pos_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>> { self.read::(id) } @@ -220,7 +220,10 @@ impl BlockchainStorageRead for super::StoreTxRo<'_, B } #[log_error] - fn get_account_nonce_count(&self, account: AccountType) -> crate::Result> { + fn get_account_nonce_count( + &self, + account: &AccountType, + ) -> crate::Result> { self.read::(account) } @@ -433,17 +436,17 @@ impl BlockchainStorageRead for super::StoreTxRw<'_, B } #[log_error] - fn get_block(&self, id: Id) -> crate::Result> { + fn get_block(&self, id: &Id) -> crate::Result> { self.read::(id) } #[log_error] - fn block_exists(&self, id: Id) -> crate::Result { + fn block_exists(&self, id: &Id) -> crate::Result { self.entry_exists::(id) } #[log_error] - fn get_block_header(&self, id: Id) -> crate::Result> { + fn get_block_header(&self, id: &Id) -> crate::Result> { let block_index = self.read::(id)?; Ok(block_index.map(|block_index| block_index.into_block_header())) } @@ -461,12 +464,12 @@ impl BlockchainStorageRead for super::StoreTxRw<'_, B } #[log_error] - fn get_block_id_by_height(&self, height: &BlockHeight) -> crate::Result>> { + fn get_block_id_by_height(&self, height: BlockHeight) -> crate::Result>> { self.read::(height) } #[log_error] - fn get_undo_data(&self, id: Id) -> crate::Result> { + fn get_undo_data(&self, id: &Id) -> crate::Result> { self.read::(id) } @@ -483,7 +486,7 @@ impl BlockchainStorageRead for super::StoreTxRw<'_, B #[log_error] fn get_tokens_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>> { self.read::(&id) } @@ -491,7 +494,7 @@ impl BlockchainStorageRead for super::StoreTxRw<'_, B #[log_error] fn get_orders_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>> { self.read::(id) } @@ -517,7 +520,7 @@ impl BlockchainStorageRead for super::StoreTxRw<'_, B #[log_error] fn get_pos_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>> { self.read::(id) } @@ -539,7 +542,10 @@ impl BlockchainStorageRead for super::StoreTxRw<'_, B } #[log_error] - fn get_account_nonce_count(&self, account: AccountType) -> crate::Result> { + fn get_account_nonce_count( + &self, + account: &AccountType, + ) -> crate::Result> { self.read::(account) } diff --git a/chainstate/storage/src/internal/store_tx/write_impls.rs b/chainstate/storage/src/internal/store_tx/write_impls.rs index 7ebb3e18be..8704d47d57 100644 --- a/chainstate/storage/src/internal/store_tx/write_impls.rs +++ b/chainstate/storage/src/internal/store_tx/write_impls.rs @@ -43,8 +43,8 @@ impl BlockchainStorageWrite for StoreTxRw<'_, B> { } #[log_error] - fn set_magic_bytes(&mut self, bytes: &MagicBytes) -> crate::Result<()> { - self.write_value::(bytes) + fn set_magic_bytes(&mut self, bytes: MagicBytes) -> crate::Result<()> { + self.write_value::(&bytes) } #[log_error] @@ -63,7 +63,7 @@ impl BlockchainStorageWrite for StoreTxRw<'_, B> { } #[log_error] - fn del_block(&mut self, id: Id) -> crate::Result<()> { + fn del_block(&mut self, id: &Id) -> crate::Result<()> { self.del::(id) } @@ -73,7 +73,7 @@ impl BlockchainStorageWrite for StoreTxRw<'_, B> { } #[log_error] - fn del_block_index(&mut self, block_id: Id) -> crate::Result<()> { + fn del_block_index(&mut self, block_id: &Id) -> crate::Result<()> { self.del::(block_id) } @@ -85,24 +85,24 @@ impl BlockchainStorageWrite for StoreTxRw<'_, B> { #[log_error] fn set_block_id_at_height( &mut self, - height: &BlockHeight, + height: BlockHeight, block_id: &Id, ) -> crate::Result<()> { self.write::(height, block_id) } #[log_error] - fn del_block_id_at_height(&mut self, height: &BlockHeight) -> crate::Result<()> { + fn del_block_id_at_height(&mut self, height: BlockHeight) -> crate::Result<()> { self.del::(height) } #[log_error] - fn set_undo_data(&mut self, id: Id, undo: &UtxosBlockUndo) -> crate::Result<()> { + fn set_undo_data(&mut self, id: &Id, undo: &UtxosBlockUndo) -> crate::Result<()> { self.write::(id, undo) } #[log_error] - fn del_undo_data(&mut self, id: Id) -> crate::Result<()> { + fn del_undo_data(&mut self, id: &Id) -> crate::Result<()> { self.del::(id) } @@ -137,42 +137,42 @@ impl BlockchainStorageWrite for StoreTxRw<'_, B> { #[log_error] fn set_tokens_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()> { self.write::(id, undo) } #[log_error] - fn del_tokens_accounting_undo_data(&mut self, id: Id) -> crate::Result<()> { + fn del_tokens_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()> { self.del::(id) } #[log_error] fn set_orders_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()> { self.write::(id, undo) } #[log_error] - fn del_orders_accounting_undo_data(&mut self, id: Id) -> crate::Result<()> { + fn del_orders_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()> { self.del::(id) } #[log_error] fn set_pos_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()> { self.write::(id, undo) } #[log_error] - fn del_pos_accounting_undo_data(&mut self, id: Id) -> crate::Result<()> { + fn del_pos_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()> { self.del::(id) } @@ -207,14 +207,14 @@ impl BlockchainStorageWrite for StoreTxRw<'_, B> { #[log_error] fn set_account_nonce_count( &mut self, - account: AccountType, + account: &AccountType, nonce: AccountNonce, ) -> crate::Result<()> { self.write::(account, nonce) } #[log_error] - fn del_account_nonce_count(&mut self, account: AccountType) -> crate::Result<()> { + fn del_account_nonce_count(&mut self, account: &AccountType) -> crate::Result<()> { self.del::(account) } } diff --git a/chainstate/storage/src/internal/test.rs b/chainstate/storage/src/internal/test.rs index baf1650752..27c3aad054 100644 --- a/chainstate/storage/src/internal/test.rs +++ b/chainstate/storage/src/internal/test.rs @@ -42,15 +42,15 @@ fn test_storage_get_default_version_in_tx() { fn assert_block_exists(db_tx: &DbTx, block: &Block) { assert_eq!( - db_tx.get_block(block.get_id()).unwrap().as_ref(), + db_tx.get_block(&block.get_id()).unwrap().as_ref(), Some(block) ); - assert!(db_tx.block_exists(block.get_id()).unwrap()); + assert!(db_tx.block_exists(&block.get_id()).unwrap()); } fn assert_no_block(db_tx: &DbTx, block_id: Id) { - assert_eq!(db_tx.get_block(block_id).unwrap().as_ref(), None); - assert!(!db_tx.block_exists(block_id).unwrap()); + assert_eq!(db_tx.get_block(&block_id).unwrap().as_ref(), None); + assert!(!db_tx.block_exists(&block_id).unwrap()); } #[test] @@ -115,7 +115,7 @@ fn test_storage_manipulation() { assert_block_exists(&db_tx, &block0); assert_block_exists(&db_tx, &block1); - assert_eq!(db_tx.del_block(block1.get_id()), Ok(())); + assert_eq!(db_tx.del_block(&block1.get_id()), Ok(())); assert_block_exists(&db_tx, &block0); assert_no_block(&db_tx, block1.get_id()); @@ -368,15 +368,18 @@ fn undo_test(#[case] seed: Seed) { let store = TestStore::new_empty().unwrap(); // store is empty, so no undo data should be found. - assert_eq!(store.transaction_ro().unwrap().get_undo_data(id0), Ok(None)); + assert_eq!( + store.transaction_ro().unwrap().get_undo_data(&id0), + Ok(None) + ); let mut db_tx = store.transaction_rw(None).unwrap(); // add undo data and check if it is there - assert_eq!(db_tx.set_undo_data(id0, &block_undo0), Ok(())); + assert_eq!(db_tx.set_undo_data(&id0, &block_undo0), Ok(())); db_tx.commit().unwrap(); assert_eq!( - store.transaction_ro().unwrap().get_undo_data(id0).unwrap().unwrap(), + store.transaction_ro().unwrap().get_undo_data(&id0).unwrap().unwrap(), block_undo0.clone() ); @@ -386,38 +389,44 @@ fn undo_test(#[case] seed: Seed) { // create id: let id1: Id = Id::new(H256::random_using(&mut rng)); - assert_eq!(store.transaction_ro().unwrap().get_undo_data(id1), Ok(None)); + assert_eq!( + store.transaction_ro().unwrap().get_undo_data(&id1), + Ok(None) + ); let mut db_tx = store.transaction_rw(None).unwrap(); - assert_eq!(db_tx.set_undo_data(id1, &block_undo1), Ok(())); + assert_eq!(db_tx.set_undo_data(&id1, &block_undo1), Ok(())); db_tx.commit().unwrap(); assert_eq!( - store.transaction_ro().unwrap().get_undo_data(id1).unwrap().unwrap(), + store.transaction_ro().unwrap().get_undo_data(&id1).unwrap().unwrap(), block_undo1.clone() ); assert_eq!( - store.transaction_ro().unwrap().get_undo_data(id0).unwrap().unwrap(), + store.transaction_ro().unwrap().get_undo_data(&id0).unwrap().unwrap(), block_undo0.clone() ); let mut db_tx = store.transaction_rw(None).unwrap(); - assert_eq!(db_tx.del_undo_data(id1), Ok(())); + assert_eq!(db_tx.del_undo_data(&id1), Ok(())); db_tx.commit().unwrap(); - assert_eq!(store.transaction_ro().unwrap().get_undo_data(id1), Ok(None)); assert_eq!( - store.transaction_ro().unwrap().get_undo_data(id0).unwrap().unwrap(), + store.transaction_ro().unwrap().get_undo_data(&id1), + Ok(None) + ); + assert_eq!( + store.transaction_ro().unwrap().get_undo_data(&id0).unwrap().unwrap(), block_undo0.clone() ); let mut db_tx = store.transaction_rw(None).unwrap(); - assert_eq!(db_tx.set_undo_data(id1, &block_undo1), Ok(())); + assert_eq!(db_tx.set_undo_data(&id1, &block_undo1), Ok(())); db_tx.commit().unwrap(); assert_eq!( - store.transaction_ro().unwrap().get_undo_data(id1).unwrap().unwrap(), + store.transaction_ro().unwrap().get_undo_data(&id1).unwrap().unwrap(), block_undo1 ); } diff --git a/chainstate/storage/src/lib.rs b/chainstate/storage/src/lib.rs index db452d08fd..2c62b0fa46 100644 --- a/chainstate/storage/src/lib.rs +++ b/chainstate/storage/src/lib.rs @@ -67,11 +67,6 @@ pub trait BlockchainStorageRead: + OrdersAccountingStorageRead + EpochStorageRead { - // TODO: below (and in lots of other places too) Id is sometimes passes by ref and sometimes - // by value. It's better to choose one "canonical" approach and use it everywhere. - // Same applies to other "primitive" types, like BlockHeight (the latter, being 64 bit long, - // should probably be passed by value even if we decide to pass Id by ref). - /// Get storage version fn get_storage_version(&self) -> crate::Result>; @@ -89,21 +84,21 @@ pub trait BlockchainStorageRead: fn get_block_reward(&self, block_index: &BlockIndex) -> crate::Result>; /// Get block by its hash - fn get_block(&self, id: Id) -> crate::Result>; + fn get_block(&self, id: &Id) -> crate::Result>; /// Return true if the block exists in the db and false otherwise. /// This is cheaper than calling `get_block` and checking for `is_some`. - fn block_exists(&self, id: Id) -> crate::Result; + fn block_exists(&self, id: &Id) -> crate::Result; - fn get_block_header(&self, id: Id) -> crate::Result>; + fn get_block_header(&self, id: &Id) -> crate::Result>; /// Get the height below which reorgs should not be allowed. fn get_min_height_with_allowed_reorg(&self) -> crate::Result>; /// Get mainchain block by its height - fn get_block_id_by_height(&self, height: &BlockHeight) -> crate::Result>>; + fn get_block_id_by_height(&self, height: BlockHeight) -> crate::Result>>; - fn get_undo_data(&self, id: Id) -> crate::Result>; + fn get_undo_data(&self, id: &Id) -> crate::Result>; /// Get token creation tx fn get_token_aux_data(&self, token_id: &TokenId) -> crate::Result>; @@ -120,19 +115,19 @@ pub trait BlockchainStorageRead: /// Get tokens accounting undo for specific block fn get_tokens_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>>; /// Get tokens accounting undo for specific block fn get_orders_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>>; /// Get accounting undo for specific block fn get_pos_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>>; /// Get accounting delta for specific epoch @@ -148,7 +143,8 @@ pub trait BlockchainStorageRead: ) -> crate::Result>; /// Get nonce value for specific account - fn get_account_nonce_count(&self, account: AccountType) -> crate::Result>; + fn get_account_nonce_count(&self, account: &AccountType) + -> crate::Result>; /// Get all keys (block ids) from the block map. This is used in the chainstate's /// "heavy" consistency checks. @@ -175,7 +171,7 @@ pub trait BlockchainStorageWrite: fn set_storage_version(&mut self, version: ChainstateStorageVersion) -> Result<()>; /// Set magic bytes - fn set_magic_bytes(&mut self, bytes: &MagicBytes) -> Result<()>; + fn set_magic_bytes(&mut self, bytes: MagicBytes) -> Result<()>; /// Set chain type name fn set_chain_type(&mut self, chain: &str) -> Result<()>; @@ -187,13 +183,13 @@ pub trait BlockchainStorageWrite: fn set_block_index(&mut self, block_index: &BlockIndex) -> Result<()>; /// Remove block index from the database - fn del_block_index(&mut self, block_id: Id) -> Result<()>; + fn del_block_index(&mut self, block_id: &Id) -> Result<()>; /// Add a new block into the database fn add_block(&mut self, block: &Block) -> Result<()>; /// Remove block from the database - fn del_block(&mut self, id: Id) -> Result<()>; + fn del_block(&mut self, id: &Id) -> Result<()>; /// Set the height below which reorgs should not be allowed. fn set_min_height_with_allowed_reorg(&mut self, height: BlockHeight) -> crate::Result<()>; @@ -201,15 +197,15 @@ pub trait BlockchainStorageWrite: /// Set the mainchain block at given height to be given block. fn set_block_id_at_height( &mut self, - height: &BlockHeight, + height: BlockHeight, block_id: &Id, ) -> Result<()>; /// Remove block id from given mainchain height - fn del_block_id_at_height(&mut self, height: &BlockHeight) -> Result<()>; + fn del_block_id_at_height(&mut self, height: BlockHeight) -> Result<()>; - fn set_undo_data(&mut self, id: Id, undo: &UtxosBlockUndo) -> Result<()>; - fn del_undo_data(&mut self, id: Id) -> Result<()>; + fn set_undo_data(&mut self, id: &Id, undo: &UtxosBlockUndo) -> Result<()>; + fn del_undo_data(&mut self, id: &Id) -> Result<()>; /// Set data associated with token issuance (and ACL changes in the future) fn set_token_aux_data(&mut self, token_id: &TokenId, data: &TokenAuxiliaryData) -> Result<()>; @@ -226,32 +222,32 @@ pub trait BlockchainStorageWrite: /// Set tokens accounting undo data for specific block fn set_tokens_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> Result<()>; /// Remove tokens accounting undo data for specific block - fn del_tokens_accounting_undo_data(&mut self, id: Id) -> Result<()>; + fn del_tokens_accounting_undo_data(&mut self, id: &Id) -> Result<()>; /// Set orders accounting undo data for specific block fn set_orders_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> Result<()>; /// Remove orders accounting undo data for specific block - fn del_orders_accounting_undo_data(&mut self, id: Id) -> Result<()>; + fn del_orders_accounting_undo_data(&mut self, id: &Id) -> Result<()>; /// Set accounting block undo data for specific block fn set_pos_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> Result<()>; /// Remove accounting block undo data for specific block - fn del_pos_accounting_undo_data(&mut self, id: Id) -> Result<()>; + fn del_pos_accounting_undo_data(&mut self, id: &Id) -> Result<()>; /// Set accounting delta for specific block fn set_accounting_epoch_delta( @@ -273,8 +269,9 @@ pub trait BlockchainStorageWrite: /// Remove accounting block undo data for specific block fn del_accounting_epoch_undo_delta(&mut self, epoch_index: EpochIndex) -> Result<()>; - fn set_account_nonce_count(&mut self, account: AccountType, nonce: AccountNonce) -> Result<()>; - fn del_account_nonce_count(&mut self, account: AccountType) -> Result<()>; + fn set_account_nonce_count(&mut self, account: &AccountType, nonce: AccountNonce) + -> Result<()>; + fn del_account_nonce_count(&mut self, account: &AccountType) -> Result<()>; } /// Operations on read-only transactions diff --git a/chainstate/storage/src/mock/mock_impl.rs b/chainstate/storage/src/mock/mock_impl.rs index f02505574f..961d72a29a 100644 --- a/chainstate/storage/src/mock/mock_impl.rs +++ b/chainstate/storage/src/mock/mock_impl.rs @@ -56,19 +56,19 @@ mockall::mock! { fn get_chain_type(&self) -> crate::Result>; fn get_best_block_id(&self) -> crate::Result>>; fn get_block_index(&self, id: &Id) -> crate::Result>; - fn get_block(&self, id: Id) -> crate::Result>; - fn block_exists(&self, id: Id) -> crate::Result; + fn get_block(&self, id: &Id) -> crate::Result>; + fn block_exists(&self, id: &Id) -> crate::Result; fn get_block_reward(&self, block_index: &BlockIndex) -> crate::Result>; - fn get_block_header(&self, id: Id) -> crate::Result>; + fn get_block_header(&self, id: &Id) -> crate::Result>; fn get_min_height_with_allowed_reorg(&self) -> crate::Result>; fn get_block_id_by_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> crate::Result>>; - fn get_undo_data(&self, id: Id) -> crate::Result>; + fn get_undo_data(&self, id: &Id) -> crate::Result>; fn get_token_aux_data(&self, token_id: &TokenId) -> crate::Result>; @@ -76,12 +76,12 @@ mockall::mock! { fn get_tokens_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>>; fn get_orders_accounting_undo( &self, - id: Id, + id: &Id, ) -> crate::Result>>; fn get_block_tree_by_height( @@ -89,7 +89,7 @@ mockall::mock! { start_from: BlockHeight, ) -> crate::Result>>>; - fn get_pos_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_pos_accounting_undo(&self, id: &Id) -> crate::Result>>; fn get_accounting_epoch_delta( &self, @@ -101,7 +101,7 @@ mockall::mock! { epoch_index: EpochIndex, ) -> crate::Result>; - fn get_account_nonce_count(&self, account: AccountType) -> crate::Result>; + fn get_account_nonce_count(&self, account: &AccountType) -> crate::Result>; fn get_block_map_keys(&self) -> crate::Result>>; fn get_block_index_map(&self) -> crate::Result, BlockIndex>>; @@ -178,26 +178,26 @@ mockall::mock! { impl crate::BlockchainStorageWrite for Store { fn set_storage_version(&mut self, version: ChainstateStorageVersion) -> crate::Result<()>; - fn set_magic_bytes(&mut self, bytes: &MagicBytes) -> crate::Result<()>; + fn set_magic_bytes(&mut self, bytes: MagicBytes) -> crate::Result<()>; fn set_chain_type(&mut self, chain: &str) -> crate::Result<()>; fn set_best_block_id(&mut self, id: &Id) -> crate::Result<()>; fn set_block_index(&mut self, block_index: &BlockIndex) -> crate::Result<()>; - fn del_block_index(&mut self, block_id: Id) -> crate::Result<()>; + fn del_block_index(&mut self, block_id: &Id) -> crate::Result<()>; fn add_block(&mut self, block: &Block) -> crate::Result<()>; - fn del_block(&mut self, id: Id) -> crate::Result<()>; + fn del_block(&mut self, id: &Id) -> crate::Result<()>; fn set_min_height_with_allowed_reorg(&mut self, height: BlockHeight) -> crate::Result<()>; fn set_block_id_at_height( &mut self, - height: &BlockHeight, + height: BlockHeight, block_id: &Id, ) -> crate::Result<()>; - fn del_block_id_at_height(&mut self, height: &BlockHeight) -> crate::Result<()>; + fn del_block_id_at_height(&mut self, height: BlockHeight) -> crate::Result<()>; - fn set_undo_data(&mut self, id: Id, undo: &UtxosBlockUndo) -> crate::Result<()>; - fn del_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn set_undo_data(&mut self, id: &Id, undo: &UtxosBlockUndo) -> crate::Result<()>; + fn del_undo_data(&mut self, id: &Id) -> crate::Result<()>; fn set_token_aux_data(&mut self, token_id: &TokenId, data: &TokenAuxiliaryData) -> crate::Result<()>; fn del_token_aux_data(&mut self, token_id: &TokenId) -> crate::Result<()>; @@ -206,20 +206,20 @@ mockall::mock! { fn set_tokens_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()>; - fn del_tokens_accounting_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn del_tokens_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()>; fn set_orders_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()>; - fn del_orders_accounting_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn del_orders_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()>; - fn set_pos_accounting_undo_data(&mut self, id: Id, undo: &accounting::BlockUndo) -> crate::Result<()>; - fn del_pos_accounting_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn set_pos_accounting_undo_data(&mut self, id: &Id, undo: &accounting::BlockUndo) -> crate::Result<()>; + fn del_pos_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()>; fn set_accounting_epoch_delta( &mut self, @@ -235,8 +235,8 @@ mockall::mock! { ) -> crate::Result<()>; fn del_accounting_epoch_undo_delta(&mut self, epoch_index: EpochIndex) -> crate::Result<()>; - fn set_account_nonce_count(&mut self, account: AccountType, nonce: AccountNonce) -> crate::Result<()>; - fn del_account_nonce_count(&mut self, account: AccountType) -> crate::Result<()>; + fn set_account_nonce_count(&mut self, account: &AccountType, nonce: AccountNonce) -> crate::Result<()>; + fn del_account_nonce_count(&mut self, account: &AccountType) -> crate::Result<()>; } impl EpochStorageWrite for Store { @@ -362,19 +362,19 @@ mockall::mock! { fn get_chain_type(&self) -> crate::Result>; fn get_best_block_id(&self) -> crate::Result>>; fn get_block_index(&self, id: &Id) -> crate::Result>; - fn get_block(&self, id: Id) -> crate::Result>; - fn block_exists(&self, id: Id) -> crate::Result; + fn get_block(&self, id: &Id) -> crate::Result>; + fn block_exists(&self, id: &Id) -> crate::Result; fn get_block_reward(&self, block_index: &BlockIndex) -> crate::Result>; - fn get_block_header(&self, id: Id) -> crate::Result>; + fn get_block_header(&self, id: &Id) -> crate::Result>; fn get_min_height_with_allowed_reorg(&self) -> crate::Result>; fn get_block_id_by_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> crate::Result>>; - fn get_undo_data(&self, id: Id) -> crate::Result>; + fn get_undo_data(&self, id: &Id) -> crate::Result>; fn get_token_aux_data(&self, token_id: &TokenId) -> crate::Result>; fn get_token_id(&self, tx_id: &Id) -> crate::Result>; @@ -383,11 +383,11 @@ mockall::mock! { start_from: BlockHeight, ) -> crate::Result>>>; - fn get_tokens_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_tokens_accounting_undo(&self, id: &Id) -> crate::Result>>; - fn get_orders_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_orders_accounting_undo(&self, id: &Id) -> crate::Result>>; - fn get_pos_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_pos_accounting_undo(&self, id: &Id) -> crate::Result>>; fn get_accounting_epoch_delta( &self, @@ -399,7 +399,7 @@ mockall::mock! { epoch_index: EpochIndex, ) -> crate::Result>; - fn get_account_nonce_count(&self, account: AccountType) -> crate::Result>; + fn get_account_nonce_count(&self, account: &AccountType) -> crate::Result>; fn get_block_map_keys(&self) -> crate::Result>>; fn get_block_index_map(&self) -> crate::Result, BlockIndex>>; @@ -477,7 +477,6 @@ mockall::mock! { impl crate::TransactionRo for StoreTxRo { fn close(self); } - } mockall::mock! { @@ -489,32 +488,32 @@ mockall::mock! { fn get_magic_bytes(&self) -> crate::Result>; fn get_chain_type(&self) -> crate::Result>; fn get_best_block_id(&self) -> crate::Result>>; - fn get_block(&self, id: Id) -> crate::Result>; - fn block_exists(&self, id: Id) -> crate::Result; + fn get_block(&self, id: &Id) -> crate::Result>; + fn block_exists(&self, id: &Id) -> crate::Result; fn get_block_index(&self, id: &Id) -> crate::Result>; fn get_block_reward(&self, block_index: &BlockIndex) -> crate::Result>; - fn get_block_header(&self, id: Id) -> crate::Result>; + fn get_block_header(&self, id: &Id) -> crate::Result>; fn get_min_height_with_allowed_reorg(&self) -> crate::Result>; fn get_block_id_by_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> crate::Result>>; - fn get_undo_data(&self, id: Id) -> crate::Result>; + fn get_undo_data(&self, id: &Id) -> crate::Result>; fn get_token_aux_data(&self, token_id: &TokenId) -> crate::Result>; fn get_token_id(&self, tx_id: &Id) -> crate::Result>; - fn get_tokens_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_tokens_accounting_undo(&self, id: &Id) -> crate::Result>>; fn get_block_tree_by_height( &self, start_from: BlockHeight, ) -> crate::Result>>>; - fn get_pos_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_pos_accounting_undo(&self, id: &Id) -> crate::Result>>; - fn get_orders_accounting_undo(&self, id: Id) -> crate::Result>>; + fn get_orders_accounting_undo(&self, id: &Id) -> crate::Result>>; fn get_accounting_epoch_delta( &self, @@ -526,7 +525,7 @@ mockall::mock! { epoch_index: EpochIndex, ) -> crate::Result>; - fn get_account_nonce_count(&self, account: AccountType) -> crate::Result>; + fn get_account_nonce_count(&self, account: &AccountType) -> crate::Result>; fn get_block_map_keys(&self) -> crate::Result>>; fn get_block_index_map(&self) -> crate::Result, BlockIndex>>; @@ -603,26 +602,26 @@ mockall::mock! { impl crate::BlockchainStorageWrite for StoreTxRw { fn set_storage_version(&mut self, version: ChainstateStorageVersion) -> crate::Result<()>; - fn set_magic_bytes(&mut self, bytes: &MagicBytes) -> crate::Result<()>; + fn set_magic_bytes(&mut self, bytes: MagicBytes) -> crate::Result<()>; fn set_chain_type(&mut self, chain: &str) -> crate::Result<()>; fn set_best_block_id(&mut self, id: &Id) -> crate::Result<()>; fn set_block_index(&mut self, block_index: &BlockIndex) -> crate::Result<()>; - fn del_block_index(&mut self, block_id: Id) -> crate::Result<()>; + fn del_block_index(&mut self, block_id: &Id) -> crate::Result<()>; fn add_block(&mut self, block: &Block) -> crate::Result<()>; - fn del_block(&mut self, id: Id) -> crate::Result<()>; + fn del_block(&mut self, id: &Id) -> crate::Result<()>; fn set_min_height_with_allowed_reorg(&mut self, height: BlockHeight) -> crate::Result<()>; fn set_block_id_at_height( &mut self, - height: &BlockHeight, + height: BlockHeight, block_id: &Id, ) -> crate::Result<()>; - fn set_undo_data(&mut self, id: Id, undo: &UtxosBlockUndo) -> crate::Result<()>; - fn del_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn set_undo_data(&mut self, id: &Id, undo: &UtxosBlockUndo) -> crate::Result<()>; + fn del_undo_data(&mut self, id: &Id) -> crate::Result<()>; - fn del_block_id_at_height(&mut self, height: &BlockHeight) -> crate::Result<()>; + fn del_block_id_at_height(&mut self, height: BlockHeight) -> crate::Result<()>; fn set_token_aux_data(&mut self, token_id: &TokenId, data: &TokenAuxiliaryData) -> crate::Result<()>; fn del_token_aux_data(&mut self, token_id: &TokenId) -> crate::Result<()>; @@ -631,20 +630,20 @@ mockall::mock! { fn set_tokens_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()>; - fn del_tokens_accounting_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn del_tokens_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()>; fn set_orders_accounting_undo_data( &mut self, - id: Id, + id: &Id, undo: &accounting::BlockUndo, ) -> crate::Result<()>; - fn del_orders_accounting_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn del_orders_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()>; - fn set_pos_accounting_undo_data(&mut self, id: Id, undo: &accounting::BlockUndo) -> crate::Result<()>; - fn del_pos_accounting_undo_data(&mut self, id: Id) -> crate::Result<()>; + fn set_pos_accounting_undo_data(&mut self, id: &Id, undo: &accounting::BlockUndo) -> crate::Result<()>; + fn del_pos_accounting_undo_data(&mut self, id: &Id) -> crate::Result<()>; fn set_accounting_epoch_delta( &mut self, @@ -660,8 +659,8 @@ mockall::mock! { ) -> crate::Result<()>; fn del_accounting_epoch_undo_delta(&mut self, epoch_index: EpochIndex) -> crate::Result<()>; - fn set_account_nonce_count(&mut self, account: AccountType, nonce: AccountNonce) -> crate::Result<()>; - fn del_account_nonce_count(&mut self, account: AccountType) -> crate::Result<()>; + fn set_account_nonce_count(&mut self, account: &AccountType, nonce: AccountNonce) -> crate::Result<()>; + fn del_account_nonce_count(&mut self, account: &AccountType) -> crate::Result<()>; } impl EpochStorageWrite for StoreTxRw { diff --git a/chainstate/test-framework/src/block_builder.rs b/chainstate/test-framework/src/block_builder.rs index 317e54dc4d..9244f418b6 100644 --- a/chainstate/test-framework/src/block_builder.rs +++ b/chainstate/test-framework/src/block_builder.rs @@ -156,7 +156,7 @@ impl<'f> BlockBuilder<'f> { let account_nonce_getter = Box::new(|account: AccountType| -> Option { self.account_nonce_tracker.get(&account).copied().or_else(|| { let db_tx = self.framework.storage.transaction_ro().unwrap(); - db_tx.get_account_nonce_count(account).unwrap() + db_tx.get_account_nonce_count(&account).unwrap() }) }); diff --git a/chainstate/test-framework/src/framework.rs b/chainstate/test-framework/src/framework.rs index 57b11b73c6..9fd20b3f71 100644 --- a/chainstate/test-framework/src/framework.rs +++ b/chainstate/test-framework/src/framework.rs @@ -430,7 +430,7 @@ impl TestFramework { #[track_caller] pub fn block_id(&self, height: u64) -> Id { self.chainstate - .get_block_id_from_height(&BlockHeight::from(height)) + .get_block_id_from_height(BlockHeight::from(height)) .unwrap() .unwrap() } @@ -445,7 +445,7 @@ impl TestFramework { outputs_from_genesis(self.chainstate.get_chain_config().genesis_block()) } GenBlockId::Block(id) => { - outputs_from_block(&self.chainstate.get_block(id).unwrap().unwrap()) + outputs_from_block(&self.chainstate.get_block(&id).unwrap().unwrap()) } } } @@ -454,7 +454,7 @@ impl TestFramework { #[track_caller] pub fn block_opt(&self, id: Id) -> Option { self.check_block_index_consistency(&id.into()); - self.chainstate.get_block(id).unwrap() + self.chainstate.get_block(&id).unwrap() } /// Return a block given an id. Perform consistency checks. @@ -502,10 +502,10 @@ impl TestFramework { persisted_block_index_opt.as_ref(), any_block_index_opt.as_ref(), ); - assert!(self.chainstate.get_block(*id).unwrap().is_some()); + assert!(self.chainstate.get_block(id).unwrap().is_some()); } else { assert_block_index_opt_identical_to(persisted_block_index_opt.as_ref(), None); - assert!(self.chainstate.get_block(*id).unwrap().is_none()); + assert!(self.chainstate.get_block(id).unwrap().is_none()); } let any_gen_block_index_opt2 = @@ -593,8 +593,8 @@ impl TestFramework { pub fn purge_block(&mut self, block_id: &Id) { let mut tx_rw = self.storage.transaction_rw(None).unwrap(); - tx_rw.del_block(*block_id).unwrap(); - tx_rw.del_block_index(*block_id).unwrap(); + tx_rw.del_block(block_id).unwrap(); + tx_rw.del_block_index(block_id).unwrap(); tx_rw.commit().unwrap(); } diff --git a/chainstate/test-framework/src/helpers.rs b/chainstate/test-framework/src/helpers.rs index 96187dcb16..5edc86240b 100644 --- a/chainstate/test-framework/src/helpers.rs +++ b/chainstate/test-framework/src/helpers.rs @@ -192,7 +192,7 @@ pub fn mint_tokens_in_block( let nonce = BlockchainStorageRead::get_account_nonce_count( &tf.storage.transaction_ro().unwrap(), - AccountType::Token(token_id), + &AccountType::Token(token_id), ) .unwrap() .map_or(AccountNonce::new(0), |n| n.increment().unwrap()); diff --git a/chainstate/test-framework/src/pos_block_builder.rs b/chainstate/test-framework/src/pos_block_builder.rs index 92f529fa67..43bf1f8959 100644 --- a/chainstate/test-framework/src/pos_block_builder.rs +++ b/chainstate/test-framework/src/pos_block_builder.rs @@ -392,7 +392,7 @@ impl<'f> PoSBlockBuilder<'f> { let account_nonce_getter = Box::new(|account: AccountType| -> Option { self.account_nonce_tracker.get(&account).copied().or_else(|| { let db_tx = self.framework.storage.transaction_ro().unwrap(); - db_tx.get_account_nonce_count(account).unwrap() + db_tx.get_account_nonce_count(&account).unwrap() }) }); diff --git a/chainstate/test-framework/src/random_tx_maker.rs b/chainstate/test-framework/src/random_tx_maker.rs index 322f54f9ff..61e729954b 100644 --- a/chainstate/test-framework/src/random_tx_maker.rs +++ b/chainstate/test-framework/src/random_tx_maker.rs @@ -1444,12 +1444,12 @@ impl<'a> RandomTxMaker<'a> { .unwrap(); let utxo_block_id = self .chainstate - .get_block_id_from_height(&utxo_block_height) + .get_block_id_from_height(utxo_block_height) .unwrap() .unwrap() .classify(self.chainstate.get_chain_config()); - let time_of_tx = match utxo_block_id { + let time_of_tx = match &utxo_block_id { GenBlockId::Block(id) => { self.chainstate.get_block_header(id).unwrap().unwrap().timestamp() } diff --git a/chainstate/test-suite/src/tests/chainstate_accounting_storage_tests.rs b/chainstate/test-suite/src/tests/chainstate_accounting_storage_tests.rs index 70a75473fe..adf51fc601 100644 --- a/chainstate/test-suite/src/tests/chainstate_accounting_storage_tests.rs +++ b/chainstate/test-suite/src/tests/chainstate_accounting_storage_tests.rs @@ -149,7 +149,7 @@ fn store_pool_data_and_balance(#[case] seed: Seed) { // utxo is stored db_tx.get_utxo(&tx_utxo_outpoint).expect("ok").expect("some"); assert_eq!( - db_tx.get_undo_data(block_id).expect("ok").expect("some").tx_undos().len(), + db_tx.get_undo_data(&block_id).expect("ok").expect("some").tx_undos().len(), 1 ); diff --git a/chainstate/test-suite/src/tests/chainstate_storage_tests.rs b/chainstate/test-suite/src/tests/chainstate_storage_tests.rs index 2534cad785..0325bf45f8 100644 --- a/chainstate/test-suite/src/tests/chainstate_storage_tests.rs +++ b/chainstate/test-suite/src/tests/chainstate_storage_tests.rs @@ -95,7 +95,7 @@ fn store_coin(#[case] seed: Seed) { .into(); assert_eq!( - *db_tx.get_undo_data(block_id).expect("ok").expect("some").tx_undos(), + *db_tx.get_undo_data(&block_id).expect("ok").expect("some").tx_undos(), expected_undo_utxo_data ); }); @@ -351,11 +351,11 @@ fn reorg_store_coin(#[case] seed: Seed) { // utxo from block_1 was deleted assert_eq!(db_tx.get_utxo(&tx_1_utxo_outpoint).expect("ok"), None); - assert_eq!(db_tx.get_undo_data(block_1_id).expect("ok"), None); + assert_eq!(db_tx.get_undo_data(&block_1_id).expect("ok"), None); // utxo from block_2 was deleted assert_eq!(db_tx.get_utxo(&tx_2_utxo_outpoint).expect("ok"), None); assert_eq!( - db_tx.get_undo_data(block_2_id).expect("ok").expect("some").tx_undos().len(), + db_tx.get_undo_data(&block_2_id).expect("ok").expect("some").tx_undos().len(), 1 ); // utxo from block_3 is stored @@ -364,7 +364,7 @@ fn reorg_store_coin(#[case] seed: Seed) { &tx_3_output ); assert_eq!( - db_tx.get_undo_data(block_3_id).expect("ok").expect("some").tx_undos().len(), + db_tx.get_undo_data(&block_3_id).expect("ok").expect("some").tx_undos().len(), 1 ); }); @@ -477,11 +477,11 @@ fn reorg_store_coin_disposable(#[case] seed: Seed) { // utxo from block_1 was deleted assert_eq!(db_tx.get_utxo(&tx_1_utxo_outpoint).expect("ok"), None); - assert_eq!(db_tx.get_undo_data(block_1_id).expect("ok"), None); + assert_eq!(db_tx.get_undo_data(&block_1_id).expect("ok"), None); // utxo from block_2 was deleted assert_eq!(db_tx.get_utxo(&tx_2_utxo_outpoint).expect("ok"), None); assert_eq!( - db_tx.get_undo_data(block_2_id).expect("ok").expect("some").tx_undos().len(), + db_tx.get_undo_data(&block_2_id).expect("ok").expect("some").tx_undos().len(), 1 ); // utxo from block_3 is stored @@ -490,7 +490,7 @@ fn reorg_store_coin_disposable(#[case] seed: Seed) { &tx_3_output ); assert_eq!( - db_tx.get_undo_data(block_3_id).expect("ok").expect("some").tx_undos().len(), + db_tx.get_undo_data(&block_3_id).expect("ok").expect("some").tx_undos().len(), 1 ); }); diff --git a/chainstate/test-suite/src/tests/delegation_tests.rs b/chainstate/test-suite/src/tests/delegation_tests.rs index c2d0b8fb2d..5c1b173a08 100644 --- a/chainstate/test-suite/src/tests/delegation_tests.rs +++ b/chainstate/test-suite/src/tests/delegation_tests.rs @@ -845,7 +845,7 @@ fn create_pool_and_delegation_and_delegate_same_block(#[case] seed: Seed) { .unwrap(); assert_eq!( - tf.chainstate.get_stake_delegation_balance(delegation_id).unwrap(), + tf.chainstate.get_stake_delegation_balance(&delegation_id).unwrap(), Some(amount_to_stake) ); }); diff --git a/chainstate/test-suite/src/tests/fungible_tokens_v1.rs b/chainstate/test-suite/src/tests/fungible_tokens_v1.rs index 1a7a146be2..ccb1a8f08e 100644 --- a/chainstate/test-suite/src/tests/fungible_tokens_v1.rs +++ b/chainstate/test-suite/src/tests/fungible_tokens_v1.rs @@ -79,7 +79,7 @@ fn unmint_tokens_in_block( let nonce = BlockchainStorageRead::get_account_nonce_count( &tf.storage.transaction_ro().unwrap(), - AccountType::Token(token_id), + &AccountType::Token(token_id), ) .unwrap() .map_or(AccountNonce::new(0), |n| n.increment().unwrap()); @@ -1839,7 +1839,7 @@ fn burn_zero_tokens_on_unmint(#[case] seed: Seed) { let nonce = BlockchainStorageRead::get_account_nonce_count( &tf.storage.transaction_ro().unwrap(), - AccountType::Token(token_id), + &AccountType::Token(token_id), ) .unwrap() .map_or(AccountNonce::new(0), |n| n.increment().unwrap()); @@ -1919,7 +1919,7 @@ fn burn_less_than_input_on_unmint(#[case] seed: Seed) { let nonce = BlockchainStorageRead::get_account_nonce_count( &tf.storage.transaction_ro().unwrap(), - AccountType::Token(token_id), + &AccountType::Token(token_id), ) .unwrap() .map_or(AccountNonce::new(0), |n| n.increment().unwrap()); @@ -2025,7 +2025,7 @@ fn burn_less_by_providing_smaller_input_utxo(#[case] seed: Seed) { let nonce = BlockchainStorageRead::get_account_nonce_count( &tf.storage.transaction_ro().unwrap(), - AccountType::Token(token_id), + &AccountType::Token(token_id), ) .unwrap() .map_or(AccountNonce::new(0), |n| n.increment().unwrap()); @@ -2127,7 +2127,7 @@ fn unmint_using_multiple_burn_utxos(#[case] seed: Seed) { let nonce = BlockchainStorageRead::get_account_nonce_count( &tf.storage.transaction_ro().unwrap(), - AccountType::Token(token_id), + &AccountType::Token(token_id), ) .unwrap() .map_or(AccountNonce::new(0), |n| n.increment().unwrap()); diff --git a/chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs b/chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs index b83cf8c906..865ffba3b4 100644 --- a/chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs +++ b/chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs @@ -326,8 +326,8 @@ fn get_cur_balances(tf: &TestFramework, pool_ids: &[PoolId]) -> BTreeMap { diff --git a/chainstate/test-suite/src/tests/helpers/in_memory_storage_wrapper.rs b/chainstate/test-suite/src/tests/helpers/in_memory_storage_wrapper.rs index 10d082dd38..05e22a5719 100644 --- a/chainstate/test-suite/src/tests/helpers/in_memory_storage_wrapper.rs +++ b/chainstate/test-suite/src/tests/helpers/in_memory_storage_wrapper.rs @@ -87,7 +87,7 @@ impl TransactionVerifierStorageRef for InMemoryStorageWrapper { &self, tx_source: TransactionSource, ) -> Result, TransactionVerifierStorageError> { - match tx_source { + match &tx_source { TransactionSource::Chain(id) => { let undo = self .storage @@ -118,7 +118,7 @@ impl TransactionVerifierStorageRef for InMemoryStorageWrapper { &self, tx_source: TransactionSource, ) -> Result>, TransactionVerifierStorageError> { - match tx_source { + match &tx_source { TransactionSource::Chain(id) => { let undo = self .storage @@ -139,7 +139,7 @@ impl TransactionVerifierStorageRef for InMemoryStorageWrapper { self.storage .transaction_ro() .unwrap() - .get_account_nonce_count(account) + .get_account_nonce_count(&account) .map_err(TransactionVerifierStorageError::from) } @@ -147,7 +147,7 @@ impl TransactionVerifierStorageRef for InMemoryStorageWrapper { &self, tx_source: TransactionSource, ) -> Result>, TransactionVerifierStorageError> { - match tx_source { + match &tx_source { TransactionSource::Chain(id) => { let undo = self .storage @@ -166,7 +166,7 @@ impl TransactionVerifierStorageRef for InMemoryStorageWrapper { tx_source: TransactionSource, ) -> Result>, TransactionVerifierStorageError> { - match tx_source { + match &tx_source { TransactionSource::Chain(id) => { let undo = self .storage diff --git a/chainstate/test-suite/src/tests/helpers/token_checks.rs b/chainstate/test-suite/src/tests/helpers/token_checks.rs index 469a6f3137..c7dd1a5b27 100644 --- a/chainstate/test-suite/src/tests/helpers/token_checks.rs +++ b/chainstate/test-suite/src/tests/helpers/token_checks.rs @@ -116,10 +116,10 @@ pub fn check_fungible_token( let random_token_id = TokenId::random_using(rng); // Check ChainstateInterface::get_token_info_for_rpc - let actual_info_for_rpc = tf.chainstate.get_token_info_for_rpc(*token_id).unwrap().unwrap(); + let actual_info_for_rpc = tf.chainstate.get_token_info_for_rpc(token_id).unwrap().unwrap(); assert_eq!(actual_info_for_rpc, expected_info_for_rpc); assert_eq!( - tf.chainstate.get_token_info_for_rpc(random_token_id).unwrap(), + tf.chainstate.get_token_info_for_rpc(&random_token_id).unwrap(), None ); @@ -144,7 +144,7 @@ pub fn check_fungible_token( // Check ChainstateInterface::get_token_aux_data; currently it's only stored for NFTs, // so the result should be None. - assert_eq!(tf.chainstate.get_token_aux_data(*token_id).unwrap(), None); + assert_eq!(tf.chainstate.get_token_aux_data(token_id).unwrap(), None); // Check ChainstateInterface::get_token_id_from_issuance_tx; this only works for NFTs too. assert_eq!( @@ -289,10 +289,10 @@ pub fn check_nft( let random_tx_id = Id::::random_using(rng); // Check ChainstateInterface::get_token_info_for_rpc - let actual_info_for_rpc = tf.chainstate.get_token_info_for_rpc(*token_id).unwrap().unwrap(); + let actual_info_for_rpc = tf.chainstate.get_token_info_for_rpc(token_id).unwrap().unwrap(); assert_eq!(actual_info_for_rpc, expected_info_for_rpc); assert_eq!( - tf.chainstate.get_token_info_for_rpc(random_token_id).unwrap(), + tf.chainstate.get_token_info_for_rpc(&random_token_id).unwrap(), None ); @@ -316,10 +316,10 @@ pub fn check_nft( ); // Check ChainstateInterface::get_token_aux_data - let actual_aux_data = tf.chainstate.get_token_aux_data(*token_id).unwrap().unwrap(); + let actual_aux_data = tf.chainstate.get_token_aux_data(token_id).unwrap().unwrap(); assert_eq!(actual_aux_data, expected_aux_data); assert_eq!( - tf.chainstate.get_token_aux_data(random_token_id).unwrap(), + tf.chainstate.get_token_aux_data(&random_token_id).unwrap(), None ); @@ -382,7 +382,7 @@ pub fn assert_token_missing( ) { // Check ChainstateInterface::get_token_info_for_rpc assert_eq!( - tf.chainstate.get_token_info_for_rpc(*token_id).unwrap(), + tf.chainstate.get_token_info_for_rpc(token_id).unwrap(), None ); @@ -395,7 +395,7 @@ pub fn assert_token_missing( ); // Check ChainstateInterface::get_token_aux_data - assert_eq!(tf.chainstate.get_token_aux_data(*token_id).unwrap(), None); + assert_eq!(tf.chainstate.get_token_aux_data(token_id).unwrap(), None); // Check ChainstateInterface::get_token_id_from_issuance_tx; this only works for NFTs too. assert_eq!( diff --git a/chainstate/test-suite/src/tests/nft_reorgs.rs b/chainstate/test-suite/src/tests/nft_reorgs.rs index 074bafb72e..a71fb24828 100644 --- a/chainstate/test-suite/src/tests/nft_reorgs.rs +++ b/chainstate/test-suite/src/tests/nft_reorgs.rs @@ -371,7 +371,7 @@ fn nft_reorgs_and_cleanup_data(#[case] seed: Seed) { // Check that reorg happened let height = block_index.block_height(); assert!( - tf.chainstate.get_block_id_from_height(&height).unwrap().is_some_and(|id| &id + tf.chainstate.get_block_id_from_height(height).unwrap().is_some_and(|id| &id .classify(tf.chainstate.get_chain_config()) .chain_block_id() .unwrap() diff --git a/chainstate/test-suite/src/tests/orders_tests.rs b/chainstate/test-suite/src/tests/orders_tests.rs index 86802fc9f3..0a5e167876 100644 --- a/chainstate/test-suite/src/tests/orders_tests.rs +++ b/chainstate/test-suite/src/tests/orders_tests.rs @@ -274,11 +274,11 @@ fn assert_order_exists( } let actual_nonce = - tf.chainstate.get_account_nonce_count(AccountType::Order(*order_id)).unwrap(); + tf.chainstate.get_account_nonce_count(&AccountType::Order(*order_id)).unwrap(); assert_eq!(actual_nonce, expected_data.nonce); assert_eq!( tf.chainstate - .get_account_nonce_count(AccountType::Order(random_order_id)) + .get_account_nonce_count(&AccountType::Order(random_order_id)) .unwrap(), None ); diff --git a/chainstate/test-suite/src/tests/pos_processing_tests.rs b/chainstate/test-suite/src/tests/pos_processing_tests.rs index 92d8cbf3ce..fd105ab8eb 100644 --- a/chainstate/test-suite/src/tests/pos_processing_tests.rs +++ b/chainstate/test-suite/src/tests/pos_processing_tests.rs @@ -1896,7 +1896,7 @@ fn spend_from_delegation_with_reward(#[case] seed: Seed) { // Process block_4 and spend some share including reward let delegation_balance = - tf.chainstate.get_stake_delegation_balance(delegation_id).unwrap().unwrap(); + tf.chainstate.get_stake_delegation_balance(&delegation_id).unwrap().unwrap(); // try overspend { diff --git a/chainstate/test-suite/src/tests/reorgs_tests.rs b/chainstate/test-suite/src/tests/reorgs_tests.rs index 84abd9e354..0dd5b9bfdf 100644 --- a/chainstate/test-suite/src/tests/reorgs_tests.rs +++ b/chainstate/test-suite/src/tests/reorgs_tests.rs @@ -444,7 +444,7 @@ fn check_block_at_height( expected_block_id: Option<&Id>, ) { if expected_block_id.is_some() { - let real_next_block_id = tf.chainstate.get_block_id_from_height(&block_height).unwrap(); + let real_next_block_id = tf.chainstate.get_block_id_from_height(block_height).unwrap(); let expected_block_id: Option> = expected_block_id.map(|id| (*id).into()); assert_eq!(real_next_block_id, expected_block_id); } diff --git a/chainstate/test-suite/src/tests/syncing_tests.rs b/chainstate/test-suite/src/tests/syncing_tests.rs index 9a8fb6c50b..e2a0e295df 100644 --- a/chainstate/test-suite/src/tests/syncing_tests.rs +++ b/chainstate/test-suite/src/tests/syncing_tests.rs @@ -91,7 +91,7 @@ fn get_locator(#[case] seed: Seed) { for (i, header) in locator.iter().skip(1).enumerate() { let idx = height - BlockDistance::new(2i64.pow(i as u32)); let expected = - btf.chainstate.get_block_id_from_height(&idx.unwrap()).unwrap().unwrap(); + btf.chainstate.get_block_id_from_height(idx.unwrap()).unwrap().unwrap(); assert_eq!(&expected, header); } } @@ -125,12 +125,12 @@ fn get_locator_from_height(#[case] seed: Seed) { // Check the locator headers. assert_eq!( &locator[0], - &btf.chainstate.get_block_id_from_height(&height.into()).unwrap().unwrap() + &btf.chainstate.get_block_id_from_height(height.into()).unwrap().unwrap() ); for (i, header) in locator.iter().skip(1).enumerate() { let idx = BlockHeight::from(height) - BlockDistance::new(2i64.pow(i as u32)); let expected = - btf.chainstate.get_block_id_from_height(&idx.unwrap()).unwrap().unwrap(); + btf.chainstate.get_block_id_from_height(idx.unwrap()).unwrap().unwrap(); assert_eq!(&expected, header); } } @@ -755,7 +755,7 @@ fn headers_check_with_checkpoints(#[case] seed: Seed) { .iter() .map(|id| { let id = tf.to_chain_block_id(id); - tf.chainstate.get_block_header(id).unwrap().unwrap() + tf.chainstate.get_block_header(&id).unwrap().unwrap() }) .collect::>(); (parent_block, block_headers) diff --git a/mempool/src/interface/mempool_interface_impl.rs b/mempool/src/interface/mempool_interface_impl.rs index 4c1e4005a1..e86200900f 100644 --- a/mempool/src/interface/mempool_interface_impl.rs +++ b/mempool/src/interface/mempool_interface_impl.rs @@ -45,7 +45,7 @@ pub struct MempoolInit { } impl MempoolInit { - fn new( + pub fn new( chain_config: Arc, mempool_config: MempoolConfig, chainstate_handle: chainstate::ChainstateHandle, @@ -212,13 +212,3 @@ impl subsystem::Subsystem for Mempool { self.has_work() } } - -/// Mempool constructor -pub fn make_mempool( - chain_config: Arc, - mempool_config: MempoolConfig, - chainstate_handle: chainstate::ChainstateHandle, - time_getter: TimeGetter, -) -> MempoolInit { - MempoolInit::new(chain_config, mempool_config, chainstate_handle, time_getter) -} diff --git a/mempool/src/interface/mod.rs b/mempool/src/interface/mod.rs index e1f10b3c91..f1e2879a0b 100644 --- a/mempool/src/interface/mod.rs +++ b/mempool/src/interface/mod.rs @@ -17,4 +17,4 @@ mod mempool_interface; mod mempool_interface_impl; pub use mempool_interface::MempoolInterface; -pub use mempool_interface_impl::make_mempool; +pub use mempool_interface_impl::MempoolInit; diff --git a/mempool/src/lib.rs b/mempool/src/lib.rs index e80891ec7b..d621839487 100644 --- a/mempool/src/lib.rs +++ b/mempool/src/lib.rs @@ -16,7 +16,7 @@ #![deny(clippy::clone_on_ref_ptr)] pub use config::MempoolMaxSize; -pub use interface::{make_mempool, MempoolInterface}; +pub use interface::{MempoolInit, MempoolInterface}; pub use mempool_types::{tx_options, tx_origin, TxOptions, TxStatus}; mod config; diff --git a/mempool/src/pool/tx_pool/reorg.rs b/mempool/src/pool/tx_pool/reorg.rs index e8d2712db3..31d3a1da3e 100644 --- a/mempool/src/pool/tx_pool/reorg.rs +++ b/mempool/src/pool/tx_pool/reorg.rs @@ -43,7 +43,7 @@ fn collect_blocks( .chain_block_id() .expect("Reached genesis before the stopping block"); let block = chainstate - .get_block(curr_block_id)? + .get_block(&curr_block_id)? .ok_or(ReorgError::BlockNotFound(curr_block_id))?; curr_id = block.prev_block_id(); result.push(block); diff --git a/mempool/src/pool/tx_pool/tx_verifier/chainstate_handle.rs b/mempool/src/pool/tx_pool/tx_verifier/chainstate_handle.rs index 64fa21fa24..cf1781552b 100644 --- a/mempool/src/pool/tx_pool/tx_verifier/chainstate_handle.rs +++ b/mempool/src/pool/tx_pool/tx_verifier/chainstate_handle.rs @@ -146,27 +146,28 @@ impl PoSAccountingView for ChainstateHandle { type Error = Error; fn pool_exists(&self, pool_id: PoolId) -> Result { - self.call(move |c| c.stake_pool_exists(pool_id)) + self.call(move |c| c.stake_pool_exists(&pool_id)) } fn get_pool_balance(&self, pool_id: PoolId) -> Result { - self.call(move |c| c.get_stake_pool_balance(pool_id).map(|v| v.unwrap_or(Amount::ZERO))) + self.call(move |c| c.get_stake_pool_balance(&pool_id).map(|v| v.unwrap_or(Amount::ZERO))) } fn get_pool_data(&self, pool_id: PoolId) -> Result, Error> { - self.call(move |c| c.get_stake_pool_data(pool_id)) + self.call(move |c| c.get_stake_pool_data(&pool_id)) } fn get_pool_delegations_shares( &self, pool_id: PoolId, ) -> Result>, Error> { - self.call(move |c| c.get_stake_pool_delegations_shares(pool_id)) + self.call(move |c| c.get_stake_pool_delegations_shares(&pool_id)) } fn get_delegation_balance(&self, delegation_id: DelegationId) -> Result { self.call(move |c| { - c.get_stake_delegation_balance(delegation_id).map(|v| v.unwrap_or(Amount::ZERO)) + c.get_stake_delegation_balance(&delegation_id) + .map(|v| v.unwrap_or(Amount::ZERO)) }) } @@ -174,7 +175,7 @@ impl PoSAccountingView for ChainstateHandle { &self, delegation_id: DelegationId, ) -> Result, Error> { - self.call(move |c| c.get_stake_delegation_data(delegation_id)) + self.call(move |c| c.get_stake_delegation_data(&delegation_id)) } fn get_pool_delegation_share( @@ -183,7 +184,7 @@ impl PoSAccountingView for ChainstateHandle { delegation_id: DelegationId, ) -> Result { self.call(move |c| { - c.get_stake_pool_delegation_share(pool_id, delegation_id) + c.get_stake_pool_delegation_share(&pool_id, &delegation_id) .map(|v| v.unwrap_or(Amount::ZERO)) }) } @@ -193,29 +194,29 @@ impl PoSAccountingStorageRead for ChainstateHandle { type Error = Error; fn get_pool_balance(&self, pool_id: PoolId) -> Result, Error> { - self.call(move |c| c.get_stake_pool_balance(pool_id)) + self.call(move |c| c.get_stake_pool_balance(&pool_id)) } fn get_pool_data(&self, pool_id: PoolId) -> Result, Error> { - self.call(move |c| c.get_stake_pool_data(pool_id)) + self.call(move |c| c.get_stake_pool_data(&pool_id)) } fn get_pool_delegations_shares( &self, pool_id: PoolId, ) -> Result>, Error> { - self.call(move |c| c.get_stake_pool_delegations_shares(pool_id)) + self.call(move |c| c.get_stake_pool_delegations_shares(&pool_id)) } fn get_delegation_balance(&self, delegation_id: DelegationId) -> Result, Error> { - self.call(move |c| c.get_stake_delegation_balance(delegation_id)) + self.call(move |c| c.get_stake_delegation_balance(&delegation_id)) } fn get_delegation_data( &self, delegation_id: DelegationId, ) -> Result, Error> { - self.call(move |c| c.get_stake_delegation_data(delegation_id)) + self.call(move |c| c.get_stake_delegation_data(&delegation_id)) } fn get_pool_delegation_share( @@ -223,7 +224,7 @@ impl PoSAccountingStorageRead for ChainstateHandle { pool_id: PoolId, delegation_id: DelegationId, ) -> Result, Error> { - self.call(move |c| c.get_stake_pool_delegation_share(pool_id, delegation_id)) + self.call(move |c| c.get_stake_pool_delegation_share(&pool_id, &delegation_id)) } } @@ -271,7 +272,7 @@ impl TransactionVerifierStorageRef for ChainstateHandle { fn get_token_aux_data(&self, token_id: &TokenId) -> Result, Error> { let token_id = *token_id; - self.call(move |c| c.get_token_aux_data(token_id)) + self.call(move |c| c.get_token_aux_data(&token_id)) } fn get_pos_accounting_undo( @@ -282,7 +283,7 @@ impl TransactionVerifierStorageRef for ChainstateHandle { } fn get_account_nonce_count(&self, account: AccountType) -> Result, Error> { - self.call(move |c| c.get_account_nonce_count(account)) + self.call(move |c| c.get_account_nonce_count(&account)) } fn get_tokens_accounting_undo( diff --git a/mocks/src/chainstate.rs b/mocks/src/chainstate.rs index b63ade8fe7..e7bbf53b67 100644 --- a/mocks/src/chainstate.rs +++ b/mocks/src/chainstate.rs @@ -67,15 +67,15 @@ mockall::mock! { ) -> Result, ChainstateError>; fn get_block_id_from_height( &self, - height: &BlockHeight, + height: BlockHeight, ) -> Result>, ChainstateError>; - fn get_block(&self, block_id: Id) -> Result, ChainstateError>; + fn get_block(&self, block_id: &Id) -> Result, ChainstateError>; fn get_mainchain_blocks( &self, start_block_height: BlockHeight, max_count: usize, ) -> Result, ChainstateError>; - fn get_block_header(&self, block_id: Id) -> Result, ChainstateError>; + fn get_block_header(&self, block_id: &Id) -> Result, ChainstateError>; fn get_locator(&self) -> Result; fn get_locator_from_height(&self, height: BlockHeight) -> Result; fn get_block_ids_as_checkpoints( @@ -142,11 +142,11 @@ mockall::mock! { block_index: &BlockIndex, ) -> Result, ChainstateError>; fn get_epoch_data(&self, epoch_index: u64) -> Result, ChainstateError>; - fn get_token_info_for_rpc(&self, token_id: TokenId) -> Result, ChainstateError>; + fn get_token_info_for_rpc(&self, token_id: &TokenId) -> Result, ChainstateError>; fn get_tokens_info_for_rpc(&self, token_ids: &BTreeSet) -> Result, ChainstateError>; fn get_token_aux_data( &self, - token_id: TokenId, + token_id: &TokenId, ) -> Result, ChainstateError>; fn get_token_id_from_issuance_tx( &self, @@ -174,36 +174,36 @@ mockall::mock! { ) -> Result<(), ChainstateError>; fn utxo(&self, outpoint: &UtxoOutPoint) -> Result, ChainstateError>; fn is_initial_block_download(&self) -> bool; - fn stake_pool_exists(&self, pool_id: PoolId) -> Result; - fn get_stake_pool_balance(&self, pool_id: PoolId) -> Result, ChainstateError>; + fn stake_pool_exists(&self, pool_id: &PoolId) -> Result; + fn get_stake_pool_balance(&self, pool_id: &PoolId) -> Result, ChainstateError>; fn get_stake_pool_balances_at_heights( &self, pool_ids: &[PoolId], min_height: BlockHeight, max_height: BlockHeight, ) -> Result>, ChainstateError>; - fn get_stake_pool_data(&self, pool_id: PoolId) -> Result, ChainstateError>; + fn get_stake_pool_data(&self, pool_id: &PoolId) -> Result, ChainstateError>; fn get_stake_pool_delegations_shares( &self, - pool_id: PoolId, + pool_id: &PoolId, ) -> Result>, ChainstateError>; fn get_stake_delegation_balance( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError>; fn get_stake_delegation_data( &self, - delegation_id: DelegationId, + delegation_id: &DelegationId, ) -> Result, ChainstateError>; fn get_stake_pool_delegation_share( &self, - pool_id: PoolId, - delegation_id: DelegationId, + pool_id: &PoolId, + delegation_id: &DelegationId, ) -> Result, ChainstateError>; fn info(&self) -> Result; fn get_account_nonce_count( &self, - account: AccountType, + account: &AccountType, ) -> Result, ChainstateError>; fn get_order_data(&self, id: &OrderId) -> Result, ChainstateError>; diff --git a/node-lib/src/runner.rs b/node-lib/src/runner.rs index 519c67375b..0b5589733e 100644 --- a/node-lib/src/runner.rs +++ b/node-lib/src/runner.rs @@ -29,7 +29,7 @@ use chainstate::{rpc::ChainstateRpcServer, ChainstateError, InitializationError} use chainstate_launcher::{ChainConfig, StorageBackendConfig}; use common::chain::config::{assert_no_ignore_consensus_in_chain_config, ChainType}; use logging::log; -use mempool::rpc::MempoolRpcServer; +use mempool::{rpc::MempoolRpcServer, MempoolInit}; use p2p::{error::P2pError, rpc::P2pRpcServer}; use rpc::rpc_creds::RpcCreds; use test_rpc_functions::{ @@ -93,13 +93,13 @@ async fn initialize( let chainstate = manager.add_subsystem("chainstate", chainstate); // Mempool subsystem - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( Arc::clone(&chain_config), node_config.mempool.unwrap_or_default().into(), subsystem::Handle::clone(&chainstate), Default::default(), ); - let mempool = manager.add_custom_subsystem("mempool", |handle| mempool.init(handle)); + let mempool = manager.add_custom_subsystem("mempool", |handle| mempool_init.init(handle)); // P2P subsystem let peerdb_storage = { diff --git a/p2p/src/sync/peer/block_manager.rs b/p2p/src/sync/peer/block_manager.rs index a4db04335d..27c3d77cce 100644 --- a/p2p/src/sync/peer/block_manager.rs +++ b/p2p/src/sync/peer/block_manager.rs @@ -498,7 +498,7 @@ where // Note that mainchain could have become shorter due to blocks // invalidation, so no block at that height may be present at all. if let Some(mainchain_block_id_at_height) = - c.get_block_id_from_height(&best_sent_block.block_height())? + c.get_block_id_from_height(best_sent_block.block_height())? { if &mainchain_block_id_at_height == best_sent_block.block_id() { return Err(P2pError::ProtocolError( @@ -838,7 +838,7 @@ where .chainstate_handle .call(move |c| { let index = c.get_block_index_for_persisted_block(&id); - let block = c.get_block(id); + let block = c.get_block(&id); Ok((block, index)) }) .await?; diff --git a/p2p/src/sync/tests/helpers/mod.rs b/p2p/src/sync/tests/helpers/mod.rs index 931095058c..a6bf61eb5d 100644 --- a/p2p/src/sync/tests/helpers/mod.rs +++ b/p2p/src/sync/tests/helpers/mod.rs @@ -45,7 +45,7 @@ use common::{ time_getter::TimeGetter, }; use logging::log; -use mempool::{event::TransactionProcessed, MempoolConfig, MempoolHandle}; +use mempool::{event::TransactionProcessed, MempoolConfig, MempoolHandle, MempoolInit}; use networking::transport::TcpTransportSocket; use p2p_test_utils::{expect_future_val, expect_no_recv, expect_recv, SHORT_TIMEOUT}; use p2p_types::{bannable_address::BannableAddress, socket_address::SocketAddress}; @@ -182,7 +182,7 @@ impl TestNode { pub async fn get_block(&self, block_id: Id) -> Option { self.chainstate_handle - .call(move |cs| cs.get_block(block_id)) + .call(move |cs| cs.get_block(&block_id)) .await .unwrap() .unwrap() @@ -608,13 +608,14 @@ impl TestNodeBuilder { } let chainstate = manager.add_subsystem("p2p-sync-test-chainstate", chainstate); - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( Arc::clone(&chain_config), mempool_config, chainstate.clone(), time_getter.clone(), ); - let mempool = manager.add_custom_subsystem("p2p-sync-test-mempool", |h| mempool.init(h)); + let mempool = + manager.add_custom_subsystem("p2p-sync-test-mempool", |h| mempool_init.init(h)); let manager_handle = manager.main_in_task(); @@ -925,10 +926,10 @@ pub async fn make_new_top_blocks_return_headers( .into_int() .saturating_sub(start_distance_from_top); let start_block_id = - this.get_block_id_from_height(&start_height.into()).unwrap().unwrap(); + this.get_block_id_from_height(start_height.into()).unwrap().unwrap(); let mut last_block = match start_block_id.classify(this.get_chain_config()) { common::chain::GenBlockId::Genesis(_) => None, - common::chain::GenBlockId::Block(id) => this.get_block(id).unwrap(), + common::chain::GenBlockId::Block(id) => this.get_block(&id).unwrap(), }; for _ in 0..count { diff --git a/p2p/src/sync/tests/network_sync.rs b/p2p/src/sync/tests/network_sync.rs index b2fa71c8e0..6913d5f3db 100644 --- a/p2p/src/sync/tests/network_sync.rs +++ b/p2p/src/sync/tests/network_sync.rs @@ -526,9 +526,9 @@ async fn send_block_from_the_future_again(#[case] seed: Seed) { .call(move |cs| { ( cs.get_block_index_for_any_block(&normal_block_id).unwrap(), - cs.get_block(normal_block_id).unwrap(), + cs.get_block(&normal_block_id).unwrap(), cs.get_block_index_for_any_block(&future_block_id).unwrap(), - cs.get_block(future_block_id).unwrap(), + cs.get_block(&future_block_id).unwrap(), ) }) .await @@ -572,7 +572,7 @@ async fn send_block_from_the_future_again(#[case] seed: Seed) { .call(move |cs| { ( cs.get_block_index_for_persisted_block(&future_block_id).unwrap(), - cs.get_block(future_block_id).unwrap(), + cs.get_block(&future_block_id).unwrap(), ) }) .await diff --git a/p2p/src/tests/helpers/test_node_group.rs b/p2p/src/tests/helpers/test_node_group.rs index ef9f9ea016..76558d5ff2 100644 --- a/p2p/src/tests/helpers/test_node_group.rs +++ b/p2p/src/tests/helpers/test_node_group.rs @@ -108,7 +108,7 @@ where for node in &self.nodes { let block = node .chainstate() - .call(move |cs| cs.get_block(block_id)) + .call(move |cs| cs.get_block(&block_id)) .await .unwrap() .unwrap(); diff --git a/p2p/test-utils/src/lib.rs b/p2p/test-utils/src/lib.rs index 24bac375a9..4144f7d910 100644 --- a/p2p/test-utils/src/lib.rs +++ b/p2p/test-utils/src/lib.rs @@ -34,7 +34,7 @@ use common::{ time_getter::TimeGetter, }; use logging::log; -use mempool::{MempoolConfig, MempoolHandle}; +use mempool::{MempoolConfig, MempoolHandle, MempoolInit}; use subsystem::{ManagerJoinHandle, ShutdownTrigger}; use test_utils::random::{CryptoRng, Rng}; @@ -87,13 +87,14 @@ pub fn start_subsystems_generic( let chainstate = manager.add_subsystem("p2p-test-chainstate", chainstate); - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( chain_config, mempool_config, chainstate.clone(), time_getter, ); - let mempool = manager.add_custom_subsystem("p2p-test-mempool", |handle| mempool.init(handle)); + let mempool = + manager.add_custom_subsystem("p2p-test-mempool", |handle| mempool_init.init(handle)); let manager_handle = manager.main_in_task_in_tracing_span(tracing_span); diff --git a/p2p/tests/shutdown.rs b/p2p/tests/shutdown.rs index 43b36d855f..175f7ec0fe 100644 --- a/p2p/tests/shutdown.rs +++ b/p2p/tests/shutdown.rs @@ -17,7 +17,7 @@ use std::{sync::Arc, time::Duration}; use chainstate::{make_chainstate, ChainstateConfig, DefaultTransactionVerificationStrategy}; use common::chain::config::create_unit_test_config; -use mempool::MempoolConfig; +use mempool::{MempoolConfig, MempoolInit}; use storage_inmemory::InMemory; use p2p::{ @@ -54,13 +54,14 @@ async fn shutdown_timeout() { let chainstate = manager.add_subsystem("shutdown-test-chainstate", chainstate); let mempool_config = MempoolConfig::new(); - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( Arc::clone(&chain_config), mempool_config, chainstate.clone(), Default::default(), ); - let mempool = manager.add_custom_subsystem("shutdown-test-mempool", |hdl| mempool.init(hdl)); + let mempool = + manager.add_custom_subsystem("shutdown-test-mempool", |hdl| mempool_init.init(hdl)); let peerdb_storage = PeerDbStorageImpl::new(InMemory::new()).unwrap(); let _p2p = make_p2p( diff --git a/pos-accounting/src/storage/mod.rs b/pos-accounting/src/storage/mod.rs index ef22a6e643..4c318046d4 100644 --- a/pos-accounting/src/storage/mod.rs +++ b/pos-accounting/src/storage/mod.rs @@ -32,6 +32,7 @@ pub trait StorageTag {} pub struct DefaultStorageTag; impl StorageTag for DefaultStorageTag {} +// TODO: here and in other places: pass Ids by ref pub trait PoSAccountingStorageRead { type Error: std::error::Error; diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 8ef7440944..6f7006a1a0 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -819,6 +819,12 @@ user-id = 267 # Tony Arcieri (tarcieri) start = "2022-05-24" end = "2026-10-15" +[[trusted.keccak]] +criteria = "safe-to-deploy" +user-id = 5059 # Artyom Pavlov (newpavlov) +start = "2026-02-13" +end = "2027-02-18" + [[trusted.libc]] criteria = "safe-to-deploy" user-id = 1 # Alex Crichton (alexcrichton) diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index e02fa6670c..2c70de09d0 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -930,11 +930,11 @@ user-id = 55123 user-login = "rust-lang-owner" [[publisher.keccak]] -version = "0.1.5" -when = "2024-01-12" -user-id = 267 -user-login = "tarcieri" -user-name = "Tony Arcieri" +version = "0.1.6" +when = "2026-02-13" +user-id = 5059 +user-login = "newpavlov" +user-name = "Artyom Pavlov" [[publisher.libc]] version = "0.2.177" diff --git a/wallet/wallet-controller/src/sync/tests/mod.rs b/wallet/wallet-controller/src/sync/tests/mod.rs index 8082f580c4..8dfae28f25 100644 --- a/wallet/wallet-controller/src/sync/tests/mod.rs +++ b/wallet/wallet-controller/src/sync/tests/mod.rs @@ -215,7 +215,7 @@ impl NodeInterface for MockNode { unreachable!() } async fn get_block(&self, block_id: Id) -> Result, Self::Error> { - Ok(self.tf.lock().unwrap().chainstate.get_block(block_id).unwrap()) + Ok(self.tf.lock().unwrap().chainstate.get_block(&block_id).unwrap()) } async fn get_mainchain_blocks( &self, @@ -251,7 +251,7 @@ impl NodeInterface for MockNode { &self, height: BlockHeight, ) -> Result>, Self::Error> { - Ok(self.tf.lock().unwrap().chainstate.get_block_id_from_height(&height).unwrap()) + Ok(self.tf.lock().unwrap().chainstate.get_block_id_from_height(height).unwrap()) } async fn get_last_common_ancestor( &self, @@ -453,7 +453,7 @@ impl NodeInterface for MockNode { fn create_chain(node: &MockNode, rng: &mut (impl Rng + CryptoRng), parent: u64, count: usize) { let mut tf = node.tf.lock().unwrap(); - let parent_id = tf.chainstate.get_block_id_from_height(&parent.into()).unwrap().unwrap(); + let parent_id = tf.chainstate.get_block_id_from_height(parent.into()).unwrap().unwrap(); tf.create_chain(&parent_id, count, rng).unwrap(); } diff --git a/wallet/wallet-node-client/src/handles_client/mod.rs b/wallet/wallet-node-client/src/handles_client/mod.rs index da5c45598e..593ba3936c 100644 --- a/wallet/wallet-node-client/src/handles_client/mod.rs +++ b/wallet/wallet-node-client/src/handles_client/mod.rs @@ -125,7 +125,7 @@ impl NodeInterface for WalletHandlesClient { } async fn get_block(&self, block_id: Id) -> Result, Self::Error> { - let result = self.chainstate.call(move |this| this.get_block(block_id)).await??; + let result = self.chainstate.call(move |this| this.get_block(&block_id)).await??; Ok(result) } @@ -165,7 +165,7 @@ impl NodeInterface for WalletHandlesClient { ) -> Result>, Self::Error> { let result = self .chainstate - .call(move |this| this.get_block_id_from_height(&height)) + .call(move |this| this.get_block_id_from_height(height)) .await??; Ok(result) } @@ -183,15 +183,17 @@ impl NodeInterface for WalletHandlesClient { } async fn get_stake_pool_balance(&self, pool_id: PoolId) -> Result, Self::Error> { - let result = - self.chainstate.call(move |this| this.get_stake_pool_balance(pool_id)).await??; + let result = self + .chainstate + .call(move |this| this.get_stake_pool_balance(&pool_id)) + .await??; Ok(result) } async fn get_staker_balance(&self, pool_id: PoolId) -> Result, Self::Error> { let result = self .chainstate - .call(move |this| this.get_stake_pool_data(pool_id)) + .call(move |this| this.get_stake_pool_data(&pool_id)) .await?? .map(|data| data.staker_balance()) .transpose() @@ -209,7 +211,7 @@ impl NodeInterface for WalletHandlesClient { ) -> Result, Self::Error> { let result = self .chainstate - .call(move |this| this.get_stake_pool_data(pool_id)) + .call(move |this| this.get_stake_pool_data(&pool_id)) .await?? .map(|data| data.decommission_destination().clone()); Ok(result) @@ -222,7 +224,7 @@ impl NodeInterface for WalletHandlesClient { ) -> Result, Self::Error> { let result = self .chainstate - .call(move |this| this.get_stake_pool_delegation_share(pool_id, delegation_id)) + .call(move |this| this.get_stake_pool_delegation_share(&pool_id, &delegation_id)) .await??; Ok(result) } @@ -230,7 +232,7 @@ impl NodeInterface for WalletHandlesClient { async fn get_token_info(&self, token_id: TokenId) -> Result, Self::Error> { let result = self .chainstate - .call(move |this| this.get_token_info_for_rpc(token_id)) + .call(move |this| this.get_token_info_for_rpc(&token_id)) .await??; Ok(result) } diff --git a/wallet/wallet-node-client/tests/call_tests.rs b/wallet/wallet-node-client/tests/call_tests.rs index dda2f7d474..52adb1a371 100644 --- a/wallet/wallet-node-client/tests/call_tests.rs +++ b/wallet/wallet-node-client/tests/call_tests.rs @@ -15,6 +15,8 @@ use std::{net::SocketAddr, str::FromStr, sync::Arc}; +use tokio::task::JoinHandle; + use blockprod::{test_blockprod_config, BlockProductionHandle}; use chainstate::{ make_chainstate, rpc::ChainstateRpcServer, ChainstateConfig, ChainstateHandle, @@ -27,12 +29,11 @@ use common::{ }, primitives::{Idable, H256}, }; -use mempool::{MempoolConfig, MempoolHandle}; +use mempool::{MempoolConfig, MempoolHandle, MempoolInit}; use node_comm::{make_handles_client, make_rpc_client, node_traits::NodeInterface}; use p2p::P2pHandle; use rpc::RpcAuthData; use subsystem::ShutdownTrigger; -use tokio::task::JoinHandle; pub async fn start_subsystems( chain_config: Arc, @@ -85,13 +86,13 @@ pub async fn start_subsystems( let chainstate_handle = manager.add_subsystem("test-chainstate", chainstate); - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( Arc::clone(&chain_config), mempool_config, chainstate_handle.clone(), Default::default(), ); - let mempool_handle = manager.add_custom_subsystem("test-mempool", |hdl| mempool.init(hdl)); + let mempool_handle = manager.add_custom_subsystem("test-mempool", |hdl| mempool_init.init(hdl)); let peerdb_storage = p2p::test_helpers::peerdb_inmemory_store(); let p2p_handle = p2p::make_p2p( diff --git a/wallet/wallet-test-node/src/lib.rs b/wallet/wallet-test-node/src/lib.rs index c763bf58a1..984e4115af 100644 --- a/wallet/wallet-test-node/src/lib.rs +++ b/wallet/wallet-test-node/src/lib.rs @@ -42,7 +42,7 @@ use common::{ }, primitives::{per_thousand::PerThousand, Amount, BlockHeight, H256}, }; -use mempool::{rpc::MempoolRpcServer, MempoolConfig}; +use mempool::{rpc::MempoolRpcServer, MempoolConfig, MempoolInit}; use p2p::rpc::P2pRpcServer; use rpc::rpc_creds::RpcCreds; @@ -208,13 +208,14 @@ pub async fn start_node(chain_config: Arc) -> (subsystem::Manager, let chainstate = manager.add_subsystem("wallet-cli-test-chainstate", chainstate); - let mempool = mempool::make_mempool( + let mempool_init = MempoolInit::new( Arc::clone(&chain_config), mempool_config, chainstate.clone(), Default::default(), ); - let mempool = manager.add_custom_subsystem("wallet-cli-test-mempool", |hdl| mempool.init(hdl)); + let mempool = + manager.add_custom_subsystem("wallet-cli-test-mempool", |hdl| mempool_init.init(hdl)); let peerdb_storage = p2p::test_helpers::peerdb_inmemory_store(); let p2p = p2p::make_p2p(