Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api-server/scanner-lib/src/sync/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand Down
20 changes: 10 additions & 10 deletions api-server/scanner-lib/src/sync/tests/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl PoSAccountingView for PoSAccountingAdapterToCheckFees<'_> {
&self,
pool_id: PoolId,
) -> Result<Option<pos_accounting::PoolData>, 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(
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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(),
Expand All @@ -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());
Expand All @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions blockprod/src/detail/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn get_pool_staker_balance<CS: ChainstateInterface + ?Sized>(
pool_id: &PoolId,
) -> Result<Amount, BlockProductionError> {
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()),
Expand All @@ -65,7 +65,7 @@ pub fn get_pool_total_balance<CS: ChainstateInterface + ?Sized>(
pool_id: &PoolId,
) -> Result<Amount, BlockProductionError> {
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,
Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn get_block_id_from_height<CS: ChainstateInterface + ?Sized>(
height: BlockHeight,
) -> Result<Id<GenBlock>, 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(
Expand Down
6 changes: 3 additions & 3 deletions blockprod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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()];
Expand Down
2 changes: 1 addition & 1 deletion chainstate/src/detail/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 16 additions & 16 deletions chainstate/src/detail/chainstateref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,34 +251,34 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
#[log_error]
pub fn get_block_id_by_height(
&self,
height: &BlockHeight,
height: BlockHeight,
) -> Result<Option<Id<GenBlock>>, PropertyQueryError> {
self.db_tx.get_block_id_by_height(height).map_err(PropertyQueryError::from)
}

#[log_error]
pub fn get_existing_block_id_by_height(
&self,
height: &BlockHeight,
height: BlockHeight,
) -> Result<Id<GenBlock>, 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<Block>) -> Result<Option<Block>, PropertyQueryError> {
pub fn get_block(&self, block_id: &Id<Block>) -> Result<Option<Block>, PropertyQueryError> {
self.db_tx.get_block(block_id).map_err(PropertyQueryError::from)
}

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

#[log_error]
pub fn get_block_header(
&self,
block_id: Id<Block>,
block_id: &Id<Block>,
) -> Result<Option<SignedBlockHeader>, PropertyQueryError> {
Ok(self.db_tx.get_block_header(block_id)?)
}
Expand Down Expand Up @@ -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<Option<SignedBlockHeader>, PropertyQueryError> {
let id = self.get_existing_block_id_by_height(height)?;
let id = id
Expand Down Expand Up @@ -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<Option<AccountNonce>, PropertyQueryError> {
self.db_tx.get_account_nonce_count(account).map_err(PropertyQueryError::from)
}
Expand All @@ -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.
Expand Down Expand Up @@ -887,7 +887,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
&self,
block_index: &BlockIndex,
) -> Result<Option<Block>, chainstate_storage::Error> {
self.db_tx.get_block(*block_index.block_id())
self.db_tx.get_block(block_index.block_id())
}

#[log_error]
Expand Down Expand Up @@ -958,7 +958,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
let id_from_height = |block_height: u64| -> Result<Id<Block>, 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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1340,7 +1340,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> 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())?;
Expand Down Expand Up @@ -1384,7 +1384,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> 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)
Expand Down Expand Up @@ -1415,7 +1415,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> ChainstateRe

#[log_error]
pub fn persist_block(&mut self, block: &WithId<Block>) -> 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()));
}

Expand Down Expand Up @@ -1450,7 +1450,7 @@ impl<S: BlockchainStorageWrite, V: TransactionVerificationStrategy> 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(())
}
Expand Down
Loading