Skip to content

Commit 306d565

Browse files
authored
Merge pull request #2013 from mintlayer/minor_cleanup
Minor cleanup
2 parents 1b3aa0c + 03f9952 commit 306d565

59 files changed

Lines changed: 427 additions & 411 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api-server/scanner-lib/src/sync/tests/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn create_chain(
206206
count: usize,
207207
) {
208208
let mut tf = node.tf.lock().unwrap();
209-
let parent_id = tf.chainstate.get_block_id_from_height(&parent.into()).unwrap().unwrap();
209+
let parent_id = tf.chainstate.get_block_id_from_height(parent.into()).unwrap().unwrap();
210210
tf.create_chain(&parent_id, count, rng).unwrap();
211211
}
212212

@@ -1077,7 +1077,7 @@ async fn sync_and_compare(
10771077
.block_height();
10781078
local_state.scan_blocks(block_height, vec![block]).await.unwrap();
10791079

1080-
let node_data = tf.chainstate.get_stake_pool_data(pool_id).unwrap().unwrap();
1080+
let node_data = tf.chainstate.get_stake_pool_data(&pool_id).unwrap().unwrap();
10811081

10821082
let tx = local_state.storage().transaction_ro().await.unwrap();
10831083
let scanner_data = tx.get_pool_data(pool_id).await.unwrap().unwrap();
@@ -1101,7 +1101,7 @@ async fn sync_and_compare(
11011101

11021102
let node_delegations = tf
11031103
.chainstate
1104-
.get_stake_pool_delegations_shares(pool_id)
1104+
.get_stake_pool_delegations_shares(&pool_id)
11051105
.unwrap()
11061106
.unwrap_or_default();
11071107

api-server/scanner-lib/src/sync/tests/simulation.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl PoSAccountingView for PoSAccountingAdapterToCheckFees<'_> {
8282
&self,
8383
pool_id: PoolId,
8484
) -> Result<Option<pos_accounting::PoolData>, Self::Error> {
85-
Ok(self.chainstate.get_stake_pool_data(pool_id).unwrap())
85+
Ok(self.chainstate.get_stake_pool_data(&pool_id).unwrap())
8686
}
8787

8888
fn get_pool_delegations_shares(
@@ -366,7 +366,7 @@ async fn simulation(
366366
let block_height_to_continue_from = BlockHeight::new(height_to_continue_from as u64);
367367
let mut prev_block_hash = tf
368368
.chainstate
369-
.get_block_id_from_height(&block_height_to_continue_from)
369+
.get_block_id_from_height(block_height_to_continue_from)
370370
.unwrap()
371371
.unwrap();
372372

@@ -789,7 +789,7 @@ async fn check_utxo(
789789
let utxo_block_id = block_id.classify(tf.chainstate.get_chain_config());
790790
let time_of_tx = match utxo_block_id {
791791
GenBlockId::Block(id) => {
792-
tf.chainstate.get_block_header(id).unwrap().unwrap().timestamp()
792+
tf.chainstate.get_block_header(&id).unwrap().unwrap().timestamp()
793793
}
794794
GenBlockId::Genesis(_) => {
795795
tf.chainstate.get_chain_config().genesis_block().timestamp()
@@ -868,13 +868,13 @@ async fn check_pool(
868868
let tx = local_state.storage().transaction_ro().await.unwrap();
869869
let scanner_data = tx.get_pool_data(pool_id).await.unwrap().unwrap();
870870

871-
if let Some(node_data) = tf.chainstate.get_stake_pool_data(pool_id).unwrap() {
871+
if let Some(node_data) = tf.chainstate.get_stake_pool_data(&pool_id).unwrap() {
872872
// check all fields are the same
873873
assert_eq!(node_data, scanner_data.pool_data);
874874

875875
// check delegations_balance
876876
let node_pool_balance =
877-
tf.chainstate.get_stake_pool_balance(pool_id).unwrap().unwrap_or(Amount::ZERO);
877+
tf.chainstate.get_stake_pool_balance(&pool_id).unwrap().unwrap_or(Amount::ZERO);
878878
let scanner_pool_balance =
879879
(scanner_data.staker_balance().unwrap() + scanner_data.delegations_balance).unwrap();
880880
assert_eq!(node_pool_balance, scanner_pool_balance);
@@ -887,7 +887,7 @@ async fn check_pool(
887887
// Compare the delegation shares
888888
let node_delegations = tf
889889
.chainstate
890-
.get_stake_pool_delegations_shares(pool_id)
890+
.get_stake_pool_delegations_shares(&pool_id)
891891
.unwrap()
892892
.unwrap_or_default();
893893

@@ -926,7 +926,7 @@ async fn check_delegation(
926926
let tx = local_state.storage().transaction_ro().await.unwrap();
927927
let scanner_data = tx.get_delegation(delegation_id).await.unwrap().unwrap();
928928

929-
if let Some(node_data) = tf.chainstate.get_stake_delegation_data(delegation_id).unwrap() {
929+
if let Some(node_data) = tf.chainstate.get_stake_delegation_data(&delegation_id).unwrap() {
930930
assert_eq!(node_data.source_pool(), scanner_data.pool_id());
931931
assert_eq!(
932932
node_data.spend_destination(),
@@ -936,14 +936,14 @@ async fn check_delegation(
936936
// check delegation balances are the same
937937
let node_delegation_balance = tf
938938
.chainstate
939-
.get_stake_delegation_balance(delegation_id)
939+
.get_stake_delegation_balance(&delegation_id)
940940
.unwrap()
941941
.unwrap_or(Amount::ZERO);
942942
assert_eq!(node_delegation_balance, *scanner_data.balance());
943943

944944
let node_acc_next_nonce = tf
945945
.chainstate
946-
.get_account_nonce_count(AccountType::Delegation(delegation_id))
946+
.get_account_nonce_count(&AccountType::Delegation(delegation_id))
947947
.unwrap()
948948
.map_or(AccountNonce::new(0), |nonce| nonce.increment().unwrap());
949949
assert_eq!(&node_acc_next_nonce, scanner_data.next_nonce());
@@ -969,7 +969,7 @@ async fn check_token(
969969
token_id: TokenId,
970970
) {
971971
let tx = local_state.storage().transaction_ro().await.unwrap();
972-
let node_data = tf.chainstate.get_token_info_for_rpc(token_id).unwrap().unwrap();
972+
let node_data = tf.chainstate.get_token_info_for_rpc(&token_id).unwrap().unwrap();
973973

974974
match node_data {
975975
RPCTokenInfo::FungibleToken(node_data) => {

blockprod/src/detail/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn get_pool_staker_balance<CS: ChainstateInterface + ?Sized>(
4747
pool_id: &PoolId,
4848
) -> Result<Amount, BlockProductionError> {
4949
let balance = chainstate
50-
.get_stake_pool_data(*pool_id)
50+
.get_stake_pool_data(pool_id)
5151
.map_err(|err| {
5252
BlockProductionError::ChainstateError(
5353
consensus::ChainstateError::StakePoolDataReadError(*pool_id, err.to_string()),
@@ -65,7 +65,7 @@ pub fn get_pool_total_balance<CS: ChainstateInterface + ?Sized>(
6565
pool_id: &PoolId,
6666
) -> Result<Amount, BlockProductionError> {
6767
let pool_balance = chainstate
68-
.get_stake_pool_balance(*pool_id)
68+
.get_stake_pool_balance(pool_id)
6969
.map_err(|err| {
7070
BlockProductionError::ChainstateError(consensus::ChainstateError::PoolBalanceReadError(
7171
*pool_id,
@@ -263,7 +263,7 @@ pub fn get_block_id_from_height<CS: ChainstateInterface + ?Sized>(
263263
height: BlockHeight,
264264
) -> Result<Id<GenBlock>, BlockProductionError> {
265265
let block_id = chainstate
266-
.get_block_id_from_height(&height)
266+
.get_block_id_from_height(height)
267267
.map_err(|err| {
268268
BlockProductionError::ChainstateError(
269269
consensus::ChainstateError::FailedToObtainBlockIdFromHeight(

blockprod/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ mod tests {
178178
key::{KeyKind, PrivateKey},
179179
vrf::{VRFKeyKind, VRFPrivateKey},
180180
};
181-
use mempool::{MempoolConfig, MempoolHandle};
181+
use mempool::{MempoolConfig, MempoolHandle, MempoolInit};
182182
use p2p::{
183183
peer_manager::peerdb::storage_impl::PeerDbStorageImpl, test_helpers::test_p2p_config,
184184
};
@@ -291,13 +291,13 @@ mod tests {
291291

292292
let chainstate = manager.add_subsystem("chainstate", chainstate);
293293

294-
let mempool = mempool::make_mempool(
294+
let mempool_init = MempoolInit::new(
295295
Arc::clone(&chain_config),
296296
mempool_config,
297297
subsystem::Handle::clone(&chainstate),
298298
time_getter.clone(),
299299
);
300-
let mempool = manager.add_custom_subsystem("mempool", |hdl| mempool.init(hdl));
300+
let mempool = manager.add_custom_subsystem("mempool", |hdl| mempool_init.init(hdl));
301301

302302
let mut p2p_config = test_p2p_config();
303303
p2p_config.bind_addresses = vec![SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0).into()];

chainstate/src/detail/bootstrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ where
122122

123123
for block_id in blocks_list {
124124
writer.write_all(magic_bytes)?;
125-
let block = query_interface.get_existing_block(block_id)?;
125+
let block = query_interface.get_existing_block(&block_id)?;
126126
writer.write_all(&block.encode())?;
127127
}
128128
Ok(())

chainstate/src/detail/chainstateref/consistency_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a, DbTx: BlockchainStorageRead> ConsistencyChecker<'a, DbTx> {
137137
// in the block itself.
138138
if block_index.is_persisted() {
139139
let block =
140-
self.db_tx.get_block(*block_id)?.expect("The block is known to be present");
140+
self.db_tx.get_block(block_id)?.expect("The block is known to be present");
141141
let calculated_block_id = block.get_id();
142142
assert_eq!(
143143
calculated_block_id, *block_id,

chainstate/src/detail/chainstateref/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,34 +251,34 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
251251
#[log_error]
252252
pub fn get_block_id_by_height(
253253
&self,
254-
height: &BlockHeight,
254+
height: BlockHeight,
255255
) -> Result<Option<Id<GenBlock>>, PropertyQueryError> {
256256
self.db_tx.get_block_id_by_height(height).map_err(PropertyQueryError::from)
257257
}
258258

259259
#[log_error]
260260
pub fn get_existing_block_id_by_height(
261261
&self,
262-
height: &BlockHeight,
262+
height: BlockHeight,
263263
) -> Result<Id<GenBlock>, PropertyQueryError> {
264264
self.get_block_id_by_height(height)?
265-
.ok_or(PropertyQueryError::BlockForHeightNotFound(*height))
265+
.ok_or(PropertyQueryError::BlockForHeightNotFound(height))
266266
}
267267

268268
#[log_error]
269-
pub fn get_block(&self, block_id: Id<Block>) -> Result<Option<Block>, PropertyQueryError> {
269+
pub fn get_block(&self, block_id: &Id<Block>) -> Result<Option<Block>, PropertyQueryError> {
270270
self.db_tx.get_block(block_id).map_err(PropertyQueryError::from)
271271
}
272272

273273
#[log_error]
274-
pub fn block_exists(&self, block_id: Id<Block>) -> Result<bool, PropertyQueryError> {
274+
pub fn block_exists(&self, block_id: &Id<Block>) -> Result<bool, PropertyQueryError> {
275275
self.db_tx.block_exists(block_id).map_err(PropertyQueryError::from)
276276
}
277277

278278
#[log_error]
279279
pub fn get_block_header(
280280
&self,
281-
block_id: Id<Block>,
281+
block_id: &Id<Block>,
282282
) -> Result<Option<SignedBlockHeader>, PropertyQueryError> {
283283
Ok(self.db_tx.get_block_header(block_id)?)
284284
}
@@ -383,7 +383,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
383383
#[log_error]
384384
pub fn get_header_from_height(
385385
&self,
386-
height: &BlockHeight,
386+
height: BlockHeight,
387387
) -> Result<Option<SignedBlockHeader>, PropertyQueryError> {
388388
let id = self.get_existing_block_id_by_height(height)?;
389389
let id = id
@@ -413,7 +413,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
413413
#[log_error]
414414
pub fn get_account_nonce_count(
415415
&self,
416-
account: AccountType,
416+
account: &AccountType,
417417
) -> Result<Option<AccountNonce>, PropertyQueryError> {
418418
self.db_tx.get_account_nonce_count(account).map_err(PropertyQueryError::from)
419419
}
@@ -430,7 +430,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
430430
};
431431

432432
if let Some(block_index) = self.get_block_index(&id)? {
433-
let mainchain_block_id = self.get_block_id_by_height(&block_index.block_height())?;
433+
let mainchain_block_id = self.get_block_id_by_height(block_index.block_height())?;
434434

435435
// Note: this function may be called when the chain is still empty, so we don't unwrap
436436
// mainchain_block_id and wrap gen_id instead.
@@ -887,7 +887,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
887887
&self,
888888
block_index: &BlockIndex,
889889
) -> Result<Option<Block>, chainstate_storage::Error> {
890-
self.db_tx.get_block(*block_index.block_id())
890+
self.db_tx.get_block(block_index.block_id())
891891
}
892892

893893
#[log_error]
@@ -958,7 +958,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
958958
let id_from_height = |block_height: u64| -> Result<Id<Block>, PropertyQueryError> {
959959
let block_height: BlockHeight = block_height.into();
960960
let block_id = self
961-
.get_block_id_by_height(&block_height)?
961+
.get_block_id_by_height(block_height)?
962962
.expect("Since block_height is >= best_height, this must exist");
963963
let block_id = block_id
964964
.classify(self.chain_config)
@@ -1129,7 +1129,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
11291129
};
11301130

11311131
let lowest_block_id = self
1132-
.get_existing_block_id_by_height(&min_height)
1132+
.get_existing_block_id_by_height(min_height)
11331133
.map_err(BlockError::PropertyQueryError)?;
11341134

11351135
self.disconnect_tip_in_memory_until(
@@ -1340,7 +1340,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> ChainstateRe
13401340
self.connect_transactions(block_index, &block)?;
13411341

13421342
self.db_tx.set_block_id_at_height(
1343-
&block_index.block_height(),
1343+
block_index.block_height(),
13441344
&(*block_index.block_id()).into(),
13451345
)?;
13461346
self.db_tx.set_best_block_id(&(*block_index.block_id()).into())?;
@@ -1384,7 +1384,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> ChainstateRe
13841384
self.disconnect_transactions(&block.into())?;
13851385
self.db_tx.set_best_block_id(block_index.prev_block_id())?;
13861386
// Disconnect block
1387-
self.db_tx.del_block_id_at_height(&block_index.block_height())?;
1387+
self.db_tx.del_block_id_at_height(block_index.block_height())?;
13881388

13891389
let prev_block_index = self
13901390
.get_previous_block_index(&block_index)
@@ -1415,7 +1415,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> ChainstateRe
14151415

14161416
#[log_error]
14171417
pub fn persist_block(&mut self, block: &WithId<Block>) -> Result<(), BlockError> {
1418-
if self.db_tx.block_exists(block.get_id()).map_err(BlockError::from)? {
1418+
if self.db_tx.block_exists(&block.get_id()).map_err(BlockError::from)? {
14191419
return Err(BlockError::BlockAlreadyExists(block.get_id()));
14201420
}
14211421

@@ -1450,7 +1450,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> ChainstateRe
14501450
"Trying to delete a block index for a persisted block {block_id}"
14511451
);
14521452

1453-
self.db_tx.del_block_index(*block_id)?;
1453+
self.db_tx.del_block_index(block_id)?;
14541454
}
14551455
Ok(())
14561456
}

0 commit comments

Comments
 (0)