Skip to content

Commit

Permalink
style fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
biryukovmaxim committed Dec 24, 2024
1 parent 5ffbf31 commit 52fa6b6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 27 deletions.
7 changes: 6 additions & 1 deletion consensus/notify/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ impl VirtualChainChangedNotification {
added_chain_blocks_acceptance_data: Arc<Vec<Arc<AcceptanceData>>>,
added_chain_block_blue_scores: Arc<Vec<u64>>,
) -> Self {
Self { added_chain_block_hashes, removed_chain_block_hashes, added_chain_block_blue_scores, added_chain_blocks_acceptance_data }
Self {
added_chain_block_hashes,
removed_chain_block_hashes,
added_chain_block_blue_scores,
added_chain_blocks_acceptance_data,
}
}
}

Expand Down
10 changes: 2 additions & 8 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,14 @@ use kaspa_consensus_core::{
pruning::PruningImportError,
tx::TxResult,
},
header::{
Header,
CompactHeaderData
},
header::{CompactHeaderData, Header},
merkle::calc_hash_merkle_root,
muhash::MuHashExtensions,
network::NetworkType,
pruning::{PruningPointProof, PruningPointTrustedData, PruningPointsList, PruningProofMetadata},
trusted::{ExternalGhostdagData, TrustedBlock},
tx::{MutableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
BlockHashSet,
BlueWorkType,
ChainPath,
HashMapCustomHasher,
BlockHashSet, BlueWorkType, ChainPath, HashMapCustomHasher,
};
use kaspa_consensus_notify::root::ConsensusNotificationRoot;

Expand Down
7 changes: 2 additions & 5 deletions consensus/src/processes/parents_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ mod tests {

use super::ParentsManager;
use itertools::Itertools;
use kaspa_consensus_core::header::CompactHeaderData;
use kaspa_consensus_core::{
blockhash::{BlockHashes, ORIGIN},
header::Header,
Expand All @@ -220,7 +221,6 @@ mod tests {
use kaspa_database::prelude::{ReadLock, StoreError, StoreResult};
use kaspa_hashes::Hash;
use parking_lot::RwLock;
use kaspa_consensus_core::header::CompactHeaderData;

struct HeaderStoreMock {
map: RwLock<BlockHashMap<HeaderWithBlockLevel>>,
Expand Down Expand Up @@ -250,10 +250,7 @@ mod tests {
Ok(self.map.read().get(&hash).unwrap().header.clone())
}

fn get_compact_header_data(
&self,
hash: kaspa_hashes::Hash,
) -> Result<CompactHeaderData, StoreError> {
fn get_compact_header_data(&self, hash: kaspa_hashes::Hash) -> Result<CompactHeaderData, StoreError> {
unimplemented!()
}

Expand Down
20 changes: 14 additions & 6 deletions rpc/core/src/convert/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ impl From<&consensus_notify::VirtualChainChangedNotification> for VirtualChainCh
.zip(item.added_chain_block_blue_scores.iter())
.map(|(acceptance_data, &accepting_blue_score)| RpcAcceptanceData {
accepting_blue_score,
mergeset_block_acceptance_data: acceptance_data.iter().map(|MergesetBlockAcceptanceData{ block_hash, accepted_transactions }| {
let mut accepted_transactions:Vec<_> = accepted_transactions.to_vec();
accepted_transactions.sort_unstable_by_key(|entry| entry.index_within_block);
RpcMergesetBlockAcceptanceData{ merged_block_hash: *block_hash, accepted_transaction_ids: accepted_transactions.into_iter().map(|AcceptedTxEntry{ transaction_id, .. }| transaction_id).collect() }
}).collect()

mergeset_block_acceptance_data: acceptance_data
.iter()
.map(|MergesetBlockAcceptanceData { block_hash, accepted_transactions }| {
let mut accepted_transactions: Vec<_> = accepted_transactions.to_vec();
accepted_transactions.sort_unstable_by_key(|entry| entry.index_within_block);
RpcMergesetBlockAcceptanceData {
merged_block_hash: *block_hash,
accepted_transaction_ids: accepted_transactions
.into_iter()
.map(|AcceptedTxEntry { transaction_id, .. }| transaction_id)
.collect(),
}
})
.collect(),
})
.collect()
}),
Expand Down
4 changes: 2 additions & 2 deletions rpc/core/src/model/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use kaspa_notify::subscription::{context::SubscriptionContext, single::UtxosChan
use kaspa_utils::hex::ToHex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::io::ErrorKind;
use std::{
fmt::{Display, Formatter},
sync::Arc,
};
use std::io::ErrorKind;
use workflow_serializer::prelude::*;

pub type RpcExtraData = Vec<u8>;
Expand Down Expand Up @@ -921,7 +921,7 @@ impl Deserializer for GetVirtualChainFromBlockResponse {
fn deserialize<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
let _version = load!(u16, reader)?;
if _version != 254 {
return Err(std::io::Error::new(ErrorKind::Other,"Expected 254-th version"))
return Err(std::io::Error::new(ErrorKind::Other, "Expected 254-th version"));
}
let removed_chain_block_hashes = load!(Vec<RpcHash>, reader)?;
let added_chain_block_hashes = load!(Vec<RpcHash>, reader)?;
Expand Down
4 changes: 2 additions & 2 deletions rpc/core/src/model/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,13 @@ mod mockery {

impl Mock for RpcMergesetBlockAcceptanceData {
fn mock() -> Self {
RpcMergesetBlockAcceptanceData{ merged_block_hash: mock(), accepted_transaction_ids: mock() }
RpcMergesetBlockAcceptanceData { merged_block_hash: mock(), accepted_transaction_ids: mock() }
}
}

impl Mock for RpcAcceptanceData {
fn mock() -> Self {
RpcAcceptanceData { accepting_blue_score: mock(), mergeset_block_acceptance_data: mock() }
RpcAcceptanceData { accepting_blue_score: mock(), mergeset_block_acceptance_data: mock() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/grpc/core/src/convert/tx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::protowire;
use crate::{from, try_from};
use kaspa_consensus_core::tx::TransactionId;
use kaspa_rpc_core::{FromRpcHex, RpcError, RpcHash, RpcMergesetBlockAcceptanceData, RpcResult, RpcScriptVec, ToRpcHex};
use std::str::FromStr;
use kaspa_consensus_core::tx::TransactionId;
// ----------------------------------------------------------------------------
// rpc_core to protowire
// ----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions rpc/service/src/converter/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kaspa_consensus_core::{
hashing::tx::hash,
header::Header,
tx::{MutableTransaction, Transaction, TransactionId, TransactionInput, TransactionOutput},
ChainPath
ChainPath,
};
use kaspa_consensus_notify::notification::{self as consensus_notify, Notification as ConsensusNotification};
use kaspa_consensusmanager::{ConsensusManager, ConsensusProxy};
Expand Down Expand Up @@ -170,7 +170,8 @@ impl ConsensusConverter {
for hash in chain_path.added.iter() {
acceptance_daa_scores.push(consensus.async_get_compact_header_data(*hash).await?.blue_score);
}
Ok(acceptance_data.iter()
Ok(acceptance_data
.iter()
.zip(acceptance_daa_scores)
.map(|(block_data, accepting_blue_score)| RpcAcceptanceData {
accepting_blue_score,
Expand Down

0 comments on commit 52fa6b6

Please sign in to comment.