Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes #10

Open
wants to merge 1 commit into
base: expend_vspcn
Choose a base branch
from
Open
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 components/consensusmanager/src/session.rs
Original file line number Diff line number Diff line change
@@ -358,8 +358,8 @@ impl ConsensusSessionOwned {
self.clone().spawn_blocking(move |c| c.get_block(hash)).await
}

pub async fn async_get_block_transactions(&self, hash: Hash, indices: &[usize]) -> ConsensusResult<Arc<Vec<Transaction>>> {
self.clone().spawn_blocking(move |c| c.get_block_transactions(hash, indices)).await
pub async fn async_get_block_transactions(&self, hash: Hash, indices: Box<[usize]>) -> ConsensusResult<Arc<Vec<Transaction>>> {
self.clone().spawn_blocking(move |c| c.get_block_transactions(hash, indices.as_ref())).await
}

pub async fn async_get_block_even_if_header_only(&self, hash: Hash) -> ConsensusResult<Block> {
11 changes: 8 additions & 3 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
@@ -896,8 +896,13 @@ impl ConsensusApi for Consensus {
if indices.len() > transactions.len() {
return Err(ConsensusError::TransactionQueryTooLarge(hash, transactions.len(), indices.len()));
};

let selected_transactions = Arc::new(indices.iter().map(|i| transactions.get(i).unwrap_option().ok_or(ConsensusError::TransactionIndexOutOfBounds(hash, i, transactions.len()))?.clone()).collect());

let selected_transactions = Arc::new(
indices
.into_iter()
.map(|i| transactions.get(*i).ok_or(ConsensusError::TransactionOutOfBounds(hash, *i, transactions.len())).cloned())
.collect::<ConsensusResult<Vec<_>>>()?,
);

Ok(selected_transactions)
}
@@ -968,7 +973,7 @@ impl ConsensusApi for Consensus {
.copied()
.map_while(|hash| {
let entry = self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash));
num_of_merged_blocks += entry.as_ref().map_or(0, |entry| entry.len());
num_of_merged_blocks += entry.as_ref().map_or(0, |entry| entry.mergeset.len());
if num_of_merged_blocks > merged_blocks_limit {
None
} else {
4 changes: 2 additions & 2 deletions consensus/src/model/stores/acceptance_data.rs
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ struct AcceptanceDataEntry(Arc<AcceptanceData>);

impl MemSizeEstimator for AcceptanceDataEntry {
fn estimate_mem_bytes(&self) -> usize {
self.0.iter().map(|l| l.accepted_transactions.len()).sum::<usize>() * size_of::<AcceptedTxEntry>()
+ self.0.len() * size_of::<MergesetBlockAcceptanceData>()
self.0.mergeset.iter().map(|l| l.accepted_transactions.len()).sum::<usize>() * size_of::<AcceptedTxEntry>()
+ self.0.mergeset.len() * size_of::<MergesetBlockAcceptanceData>()
+ size_of::<AcceptanceData>()
+ size_of::<Self>()
}
6 changes: 4 additions & 2 deletions consensus/src/pipeline/virtual_processor/processor.rs
Original file line number Diff line number Diff line change
@@ -431,13 +431,15 @@ impl VirtualStateProcessor {
let header = self.headers_store.get_header(current).unwrap();
let mergeset_data = self.ghostdag_store.get_data(current).unwrap();
let pov_daa_score = header.daa_score;
let pov_blue_score = header.blue_score;


let selected_parent_multiset_hash = self.utxo_multisets_store.get(selected_parent).unwrap();
let selected_parent_utxo_view = (&stores.utxo_set).compose(&*diff);

let mut ctx = UtxoProcessingContext::new(mergeset_data.into(), selected_parent_multiset_hash);

self.calculate_utxo_state(&mut ctx, &selected_parent_utxo_view, pov_daa_score);
self.calculate_utxo_state(&mut ctx, &selected_parent_utxo_view, pov_daa_score, pov_blue_score);
let res = self.verify_expected_utxo_state(&mut ctx, &selected_parent_utxo_view, &header);

if let Err(rule_error) = res {
@@ -517,7 +519,7 @@ impl VirtualStateProcessor {
let virtual_past_median_time = self.window_manager.calc_past_median_time(&virtual_ghostdag_data)?.0;

// Calc virtual UTXO state relative to selected parent
self.calculate_utxo_state(&mut ctx, &selected_parent_utxo_view, virtual_daa_window.daa_score);
self.calculate_utxo_state(&mut ctx, &selected_parent_utxo_view, virtual_daa_window.daa_score, todo!("pov blue score"));

// Update the accumulated diff
accumulated_diff.with_diff_in_place(&ctx.mergeset_diff).unwrap();
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ impl VirtualStateProcessor {
.collect(),
});
} else {
ctx.mergeset_acceptance_data.push(MergesetBlockAcceptanceData {
ctx.mergeset_acceptance_data.mergeset.push(MergesetBlockAcceptanceData {
block_hash: merged_block,
accepted_transactions: validated_transactions
.into_iter()
4 changes: 2 additions & 2 deletions rpc/core/src/convert/acceptance_data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use kaspa_consensus_core::acceptance_data::{AcceptanceData, AcceptedTxEntry, MergesetBlockAcceptanceData};

use kaspa_hashes::Hash;
use crate::{RpcAcceptanceData, RpcAcceptedTxEntry, RpcCompactTransaction, RpcMergesetBlockAcceptanceData, RpcTransaction};

impl From<&AcceptedTxEntry> for RpcAcceptedTxEntry {
@@ -17,7 +17,7 @@ impl From<&MergesetBlockAcceptanceData> for RpcMergesetBlockAcceptanceData {
fn from(item: &MergesetBlockAcceptanceData) -> Self {
Self {
merged_block_hash: item.block_hash.clone(),
accepted_transaction_entries: item.accepted_transaction_entry.iter().map(RpcAcceptedTxEntry::from).collect(),
accepted_transaction_entries: Some(item.accepted_transactions.iter().map(RpcAcceptedTxEntry::from).collect()), // todo possibly should be none in some cases
}
}
}
2 changes: 1 addition & 1 deletion rpc/core/src/convert/notification.rs
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ impl From<&consensus_notify::VirtualChainChangedNotification> for VirtualChainCh
accepting_block_hash: hash.to_owned(),
// We collect accepted tx ids from all mergeset blocks
accepted_transaction_ids: acceptance_data
.iter()
.mergeset.iter()
.flat_map(|x| x.accepted_transactions.iter().map(|tx| tx.transaction_id))
.collect(),
})
20 changes: 11 additions & 9 deletions rpc/core/src/convert/tx.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//! Conversion of Transaction related types

use crate::{RpcError, RpcResult, RpcTransaction, RpcTransactionInput, RpcTransactionOutput};
use crate::{RpcAcceptedTxEntry, RpcError, RpcResult, RpcTransaction, RpcTransactionInput, RpcTransactionOutput};
use kaspa_consensus_core::{acceptance_data::AcceptedTxEntry, tx::{Transaction, TransactionInput, TransactionOutput}};

// ----------------------------------------------------------------------------
// consensus_core to rpc_core
// ----------------------------------------------------------------------------

impl From<&AcceptedTxEntry> for RpcAcceptedTxEntry {
fn from(item: &AcceptedTxEntry) -> Self {
Self {
transaction_id: item.transaction_id.clone(),
index_within_block: item.index_within_block,
}
}
}
// impl From<&AcceptedTxEntry> for RpcAcceptedTxEntry {
// fn from(item: &AcceptedTxEntry) -> Self {
// Self {
// transaction_id: item.transaction_id.clone(),
// index_within_block: item.index_within_block,
// compact_transaction: None, // todo
// raw_transaction: None, // todo
// }
// }
// }


impl From<&Transaction> for RpcTransaction {
5 changes: 4 additions & 1 deletion rpc/core/src/model/acceptance_data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use crate::RpcCompactTransaction;
use super::{RpcAddress, RpcHash, RpcSubnetworkId, RpcTransaction, RpcTransactionId, RpcTransactionIndexType, RpcTransactionPayload};


@@ -6,7 +9,7 @@ use super::{RpcAddress, RpcHash, RpcSubnetworkId, RpcTransaction, RpcTransaction
pub struct RpcAcceptedTxEntry {
pub transaction_id: RpcTransactionId,
pub index_within_block: RpcTransactionIndexType,
pub compact_transaction: Option<RpcAcceptedTxEntryVerbsoseData>,
pub compact_transaction: Option<RpcCompactTransaction>,
pub raw_transaction: Option<RpcTransaction>,
}

16 changes: 8 additions & 8 deletions rpc/core/src/model/tx.rs
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ impl Deserializer for RpcUtxoEntry {
}

/// Represents a Kaspa transaction outpoint
#[derive(Eq, Hash, PartialEq, Debug, Copy, Clone, Serialize, Deserialize)]
#[derive(Eq, Hash, PartialEq, Debug, Copy, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionOutpoint {
#[serde(with = "serde_bytes_fixed_ref")]
@@ -137,7 +137,7 @@ impl Deserializer for RpcTransactionOutpoint {
}

/// Represents a Kaspa transaction input
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionInput {
pub previous_outpoint: RpcTransactionOutpoint,
@@ -205,7 +205,7 @@ impl Deserializer for RpcTransactionInput {
}

/// Represent Kaspa transaction input verbose data
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionInputVerboseData {}

@@ -224,7 +224,7 @@ impl Deserializer for RpcTransactionInputVerboseData {
}

/// Represents a Kaspad transaction output
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionOutput {
pub value: u64,
@@ -267,7 +267,7 @@ impl Deserializer for RpcTransactionOutput {
}

/// Represent Kaspa transaction output verbose data
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionOutputVerboseData {
pub script_public_key_type: RpcScriptClass,
@@ -295,7 +295,7 @@ impl Deserializer for RpcTransactionOutputVerboseData {
}

/// Represents a Kaspa transaction
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransaction {
pub version: u16,
@@ -361,7 +361,7 @@ impl Deserializer for RpcTransaction {
}

/// Represent Kaspa transaction verbose data
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionVerboseData {
pub transaction_id: RpcTransactionId,
@@ -405,7 +405,7 @@ pub struct RpcCompactTransactionHeader {
pub version: Option<RpcTransactionVersion>,
pub subnetwork_id: Option<RpcSubnetworkId>,
pub mass: Option<u64>,
#[serde(with = "hex::serde")]
#[serde(with = "kaspa_utils::serde_bytes_optional")]
pub payload: Option<RpcTransactionPayload>,
}

3 changes: 3 additions & 0 deletions rpc/core/src/verbosity/acceptance_data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use crate::{RpcHash, RpcTransaction};
use super::tx::RpcCompactTransactionHeaderVerbosity;

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
3 changes: 3 additions & 0 deletions rpc/core/src/verbosity/tx.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcCompactTransactionHeaderVerbosity {
8 changes: 4 additions & 4 deletions rpc/grpc/core/proto/messages.proto
Original file line number Diff line number Diff line change
@@ -65,9 +65,8 @@ message KaspadRequest {
GetFeeEstimateRequestMessage getFeeEstimateRequest = 1106;
GetFeeEstimateExperimentalRequestMessage getFeeEstimateExperimentalRequest = 1108;
GetCurrentBlockColorRequestMessage getCurrentBlockColorRequest = 1110;
GetVirtualChainFromBlockV2RequestMessage getVirtualChainFromBlockRequest = 1112;
NotifyVirtualChainChangedV2RequestMessage notifyVirtualChainChangedRequest = 1114;

GetVirtualChainFromBlockV2RequestMessage getVirtualChainFromBlockV2Request = 1112;
NotifyVirtualChainChangedV2RequestMessage notifyVirtualChainChangedV2Request = 1114;
}
}

@@ -133,7 +132,8 @@ message KaspadResponse {
GetFeeEstimateResponseMessage getFeeEstimateResponse = 1107;
GetFeeEstimateExperimentalResponseMessage getFeeEstimateExperimentalResponse = 1109;
GetCurrentBlockColorResponseMessage getCurrentBlockColorResponse = 1111;
GetVirtualChainFromBlockV2ResponseMessage getVirtualChainFromBlockResponse = 1113;
GetVirtualChainFromBlockV2ResponseMessage getVirtualChainFromBlockV2Response = 1113;
VirtualChainChangedV2NotificationMessage virtualChainChangedV2Notification = 1115;
}
}

4 changes: 2 additions & 2 deletions rpc/grpc/core/proto/rpc.proto
Original file line number Diff line number Diff line change
@@ -1072,7 +1072,7 @@ message NotifyVirtualChainChangedV2ResponseMessage{
// chain had changed.
//
// See: NotifyVirtualChainChangedRequestMessage
message VirtualChainChangedV2NotificationMessage{
message VirtualChainChangedV2NotificationMessage {
// The chain blocks that were removed, in high-to-low order
repeated string removedChainBlockHashes = 1;

@@ -1101,7 +1101,7 @@ message GetTransactionsRequestMessage {
TransactionAcceptanceLocator byAcceptance = 1;
TransactionInclusionLocator byInclusition = 2;
}
bool includeVerboseData = 2;
bool includeVerboseData = 3;
}

message GetTransactionsResponseMessage {
15 changes: 6 additions & 9 deletions rpc/service/src/converter/consensus.rs
Original file line number Diff line number Diff line change
@@ -8,9 +8,7 @@ use kaspa_consensusmanager::{ConsensusManager, ConsensusProxy};
use kaspa_math::Uint256;
use kaspa_mining::model::{owner_txs::OwnerTransactions, TransactionIdSet};
use kaspa_notify::converter::Converter;
use kaspa_rpc_core::{
BlockAddedNotification, Notification, RpcAcceptanceData, RpcAcceptedTransactionIds, RpcBlock, RpcBlockVerboseData, RpcHash, RpcMempoolEntry, RpcMempoolEntryByAddress, RpcResult, RpcTransaction, RpcTransactionInput, RpcTransactionOutput, RpcTransactionOutputVerboseData, RpcTransactionVerboseData
};
use kaspa_rpc_core::{BlockAddedNotification, Notification, RpcAcceptanceData, RpcAcceptedTransactionIds, RpcBlock, RpcBlockVerboseData, RpcHash, RpcMempoolEntry, RpcMempoolEntryByAddress, RpcMergesetBlockAcceptanceData, RpcResult, RpcTransaction, RpcTransactionInput, RpcTransactionOutput, RpcTransactionOutputVerboseData, RpcTransactionVerboseData};
use kaspa_txscript::{extract_script_pub_key_address, script_class::ScriptClass};
use std::{collections::HashMap, fmt::Debug, sync::Arc};

@@ -153,9 +151,9 @@ impl ConsensusConverter {
RpcTransactionOutput { value: output.value, script_public_key: output.script_public_key.clone(), verbose_data }
}

fn get_accepted_transaction(&self, accepted_tx_entry: AcceptedTxEntry, compact_tx_verbosity: Option<RpcCompactTransactionVerbosity>, include_raw_transactions: Option<RpcTransactionVerbosity>) {

}
// fn get_accepted_transaction(&self, accepted_tx_entry: AcceptedTxEntry, compact_tx_verbosity: Option<RpcCompactTransactionVerbosity>, include_raw_transactions: Option<RpcTransactionVerbosity>) {
//
// }

pub async fn get_virtual_chain_accepted_transaction_entries(
&self,
@@ -164,10 +162,9 @@ impl ConsensusConverter {
merged_blocks_limit: Option<usize>,
) -> RpcResult<Vec<RpcAcceptanceData>> {
let acceptance_data = consensus.async_get_blocks_acceptance_data(chain_path.added.clone(), merged_blocks_limit).await.unwrap();
acceptance_data.iter().map(|ad| ad.mergeset.iter().map(RpcAcceptanceData::from)).collect()
// acceptance_data.iter().map(|ad| ad.mergeset.iter().map(RpcAcceptanceData::from)).collect()
Ok(RpcAcceptanceData {
accepting_chain_block: chain_path.accepting.clone(),
accepting_blue_score: consensus.async_get_block_blue_score(&chain_path.accepting).await.unwrap(),
accepting_blue_score: consensus.async_get_block_blue_score(&chain_path.added).await.unwrap(),
mergeset_block_acceptance_data: chain_path
.added
.iter()