Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
wip sync done

some more code

deleted some stuff

wip

more changes

wip code

wip

more wip
  • Loading branch information
SWvheerden committed Oct 5, 2023
1 parent ff5a5d8 commit 9c64b58
Show file tree
Hide file tree
Showing 57 changed files with 627 additions and 1,833 deletions.
9 changes: 4 additions & 5 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl From<BlockHeader> for grpc::BlockHeader {
timestamp: h.timestamp.as_u64(),
input_mr: h.input_mr.to_vec(),
output_mr: h.output_mr.to_vec(),
output_mmr_size: h.output_mmr_size,
output_mmr_size: h.output_smt_size,
kernel_mr: h.kernel_mr.to_vec(),
kernel_mmr_size: h.kernel_mmr_size,
total_kernel_offset: h.total_kernel_offset.to_vec(),
Expand Down Expand Up @@ -73,7 +73,7 @@ impl TryFrom<grpc::BlockHeader> for BlockHeader {
timestamp: EpochTime::from(header.timestamp),
input_mr: FixedHash::try_from(header.input_mr).map_err(|err| err.to_string())?,
output_mr: FixedHash::try_from(header.output_mr).map_err(|err| err.to_string())?,
output_mmr_size: header.output_mmr_size,
output_smt_size: header.output_mmr_size,
kernel_mr: FixedHash::try_from(header.kernel_mr).map_err(|err| err.to_string())?,
kernel_mmr_size: header.kernel_mmr_size,
total_kernel_offset,
Expand Down
3 changes: 1 addition & 2 deletions base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2018"
default = ["base_node"]
transactions = []
mempool_proto = []
base_node = ["croaring", "tari_mmr", "transactions", "mempool_proto", "base_node_proto", "monero", "randomx-rs"]
base_node = ["tari_mmr", "transactions", "mempool_proto", "base_node_proto", "monero", "randomx-rs"]
base_node_proto = []
benches = ["base_node", "criterion"]

Expand Down Expand Up @@ -45,7 +45,6 @@ bytes = "0.5"
chacha20poly1305 = "0.10.1"
chrono = { version = "0.4.19", default-features = false, features = ["serde"] }
criterion = { version = "0.4.0", optional = true }
croaring = { version = "0.9", optional = true }
decimal-rs = "0.1.42"
derivative = "2.2.0"
digest = "0.10"
Expand Down
61 changes: 22 additions & 39 deletions base_layer/core/src/base_node/comms_interface/inbound_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use crate::{
metrics,
},
blocks::{Block, BlockBuilder, BlockHeader, BlockHeaderValidationError, ChainBlock, NewBlock, NewBlockTemplate},
chain_storage::{async_db::AsyncBlockchainDb, BlockAddResult, BlockchainBackend, ChainStorageError, PrunedOutput},
chain_storage::{async_db::AsyncBlockchainDb, BlockAddResult, BlockchainBackend, ChainStorageError},
consensus::{ConsensusConstants, ConsensusManager},
mempool::Mempool,
proof_of_work::{
Expand Down Expand Up @@ -163,14 +163,12 @@ where B: BlockchainBackend + 'static
},
NodeCommsRequest::FetchMatchingUtxos(utxo_hashes) => {
let mut res = Vec::with_capacity(utxo_hashes.len());
for (pruned_output, spent) in (self.blockchain_db.fetch_utxos(utxo_hashes).await?)
for (output, spent) in (self.blockchain_db.fetch_utxos(utxo_hashes).await?)
.into_iter()
.flatten()
{
if let PrunedOutput::NotPruned { output } = pruned_output {
if !spent {
res.push(output);
}
if !spent {
res.push(output);
}
}
Ok(NodeCommsResponse::TransactionOutputs(res))
Expand Down Expand Up @@ -367,7 +365,7 @@ where B: BlockchainBackend + 'static
},
Some,
),
Some(block) => Some(block.try_into_block()?),
Some(block) => Some(block.into_block()),
};

Ok(NodeCommsResponse::Block(Box::new(maybe_block)))
Expand Down Expand Up @@ -417,12 +415,7 @@ where B: BlockchainBackend + 'static
},
NodeCommsRequest::FetchUnspentUtxosInBlock { block_hash } => {
let utxos = self.blockchain_db.fetch_outputs_in_block(block_hash).await?;
Ok(NodeCommsResponse::TransactionOutputs(
utxos
.into_iter()
.filter_map(|utxo| utxo.into_unpruned_output())
.collect(),
))
Ok(NodeCommsResponse::TransactionOutputs(utxos))
},
}
}
Expand Down Expand Up @@ -885,32 +878,22 @@ where B: BlockchainBackend + 'static
details: format!("Output {} to be spent does not exist in db", input.output_hash()),
})?;

match output_mined_info.output {
PrunedOutput::Pruned { .. } => {
return Err(CommsInterfaceError::InvalidFullBlock {
hash: block_hash,
details: format!("Output {} to be spent is pruned", input.output_hash()),
});
},
PrunedOutput::NotPruned { output } => {
let rp_hash = match output.proof {
Some(proof) => proof.hash(),
None => FixedHash::zero(),
};
input.add_output_data(
output.version,
output.features,
output.commitment,
output.script,
output.sender_offset_public_key,
output.covenant,
output.encrypted_data,
output.metadata_signature,
rp_hash,
output.minimum_value_promise,
);
},
}
let rp_hash = match output_mined_info.output.proof {
Some(proof) => proof.hash(),
None => FixedHash::zero(),
};
input.add_output_data(
output_mined_info.output.version,
output_mined_info.output.features,
output_mined_info.output.commitment,
output_mined_info.output.script,
output_mined_info.output.sender_offset_public_key,
output_mined_info.output.covenant,
output_mined_info.output.encrypted_data,
output_mined_info.output.metadata_signature,
rp_hash,
output_mined_info.output.minimum_value_promise,
);
}
debug!(
target: LOG_TARGET,
Expand Down
20 changes: 3 additions & 17 deletions base_layer/core/src/base_node/proto/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,12 @@ message SyncKernelsRequest {
}

message SyncUtxosRequest {
uint64 start = 1;
bytes start_header_hash = 1;
bytes end_header_hash = 2;
bool include_pruned_utxos = 3;
bool include_deleted_bitmaps = 4;
}
message SyncUtxosResponse {
oneof utxo_or_deleted {
SyncUtxo utxo = 1;
bytes deleted_diff = 2;
}
uint64 mmr_index = 3;
}

message SyncUtxo {
oneof utxo {
// The unspent transaction output
tari.types.TransactionOutput output = 1;
// If the UTXO is deleted/pruned, the hashes are returned
PrunedOutput pruned_output = 2;
}
tari.types.TransactionOutput output = 1;
bytes mined_header = 2;
}

message PrunedOutput {
Expand Down
34 changes: 17 additions & 17 deletions base_layer/core/src/base_node/proto/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::convert::{TryFrom, TryInto};

use tari_utilities::ByteArray;

use crate::{blocks::Block, chain_storage::PrunedOutput, mempool::FeePerGramStat, proto::base_node as proto};
use crate::{blocks::Block, mempool::FeePerGramStat, proto::base_node as proto};

impl TryFrom<Block> for proto::BlockBodyResponse {
type Error = String;
Expand All @@ -37,22 +37,22 @@ impl TryFrom<Block> for proto::BlockBodyResponse {
}
}

impl TryFrom<PrunedOutput> for proto::SyncUtxo {
type Error = String;

fn try_from(output: PrunedOutput) -> Result<Self, Self::Error> {
Ok(match output {
PrunedOutput::Pruned { output_hash } => proto::SyncUtxo {
utxo: Some(proto::sync_utxo::Utxo::PrunedOutput(proto::PrunedOutput {
hash: output_hash.to_vec(),
})),
},
PrunedOutput::NotPruned { output } => proto::SyncUtxo {
utxo: Some(proto::sync_utxo::Utxo::Output(output.try_into()?)),
},
})
}
}
// impl TryFrom<PrunedOutput> for proto::SyncUtxo {
// type Error = String;
//
// fn try_from(output: PrunedOutput) -> Result<Self, Self::Error> {
// Ok(match output {
// PrunedOutput::Pruned { output_hash } => proto::SyncUtxo {
// utxo: Some(proto::sync_utxo::Utxo::PrunedOutput(proto::PrunedOutput {
// hash: output_hash.to_vec(),
// })),
// },
// PrunedOutput::NotPruned { output } => proto::SyncUtxo {
// utxo: Some(proto::sync_utxo::Utxo::Output(output.try_into()?)),
// },
// })
// }
// }

impl From<Vec<FeePerGramStat>> for proto::GetMempoolFeePerGramStatsResponse {
fn from(stats: Vec<FeePerGramStat>) -> Self {
Expand Down
30 changes: 1 addition & 29 deletions base_layer/core/src/base_node/proto/wallet_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{
use serde::{Deserialize, Serialize};
use tari_common_types::types::{BlockHash, Signature};

use crate::proto::{base_node as proto, types};
use crate::proto::base_node as proto;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TxSubmissionResponse {
Expand Down Expand Up @@ -253,31 +253,3 @@ impl TryFrom<proto::TxQueryBatchResponse> for TxQueryBatchResponse {
})
}
}

impl proto::SyncUtxosResponse {
pub fn into_utxo(self) -> Option<proto::SyncUtxo> {
use proto::sync_utxos_response::UtxoOrDeleted::{DeletedDiff, Utxo};
match self.utxo_or_deleted? {
Utxo(utxo) => Some(utxo),
DeletedDiff(_) => None,
}
}

pub fn into_bitmap(self) -> Option<Vec<u8>> {
use proto::sync_utxos_response::UtxoOrDeleted::{DeletedDiff, Utxo};
match self.utxo_or_deleted? {
Utxo(_) => None,
DeletedDiff(bitmap) => Some(bitmap),
}
}
}

impl proto::sync_utxo::Utxo {
pub fn into_transaction_output(self) -> Option<types::TransactionOutput> {
use proto::sync_utxo::Utxo::{Output, PrunedOutput};
match self {
Output(output) => Some(output),
PrunedOutput(_) => None,
}
}
}
23 changes: 9 additions & 14 deletions base_layer/core/src/base_node/rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::{
state_machine_service::states::StateInfo,
StateMachineHandle,
},
chain_storage::{async_db::AsyncBlockchainDb, BlockchainBackend, PrunedOutput},
chain_storage::{async_db::AsyncBlockchainDb, BlockchainBackend},
mempool::{service::MempoolHandle, TxStorageResponse},
proto,
proto::{
Expand Down Expand Up @@ -352,11 +352,9 @@ impl<B: BlockchainBackend + 'static> BaseNodeWalletService for BaseNodeWalletRpc
.rpc_status_internal_error(LOG_TARGET)?
.into_iter()
.flatten();
for (pruned_output, spent) in utxos {
if let PrunedOutput::NotPruned { output } = pruned_output {
if !spent {
res.push(output);
}
for (output, spent) in utxos {
if !spent {
res.push(output);
}
}

Expand Down Expand Up @@ -432,14 +430,11 @@ impl<B: BlockchainBackend + 'static> BaseNodeWalletService for BaseNodeWalletRpc
mined_height: utxo.mined_height,
mined_in_block: utxo.header_hash.to_vec(),
output_hash: utxo.output.hash().to_vec(),
output: match utxo.output {
PrunedOutput::Pruned { .. } => None,
PrunedOutput::NotPruned { output } => Some(match output.try_into() {
Ok(output) => output,
Err(err) => {
return Err(err);
},
}),
output: match utxo.utput.try_into() {
Ok(output) => output,
Err(err) => {
return Err(err);
},
},
mined_timestamp: utxo.mined_timestamp,
})
Expand Down
Loading

0 comments on commit 9c64b58

Please sign in to comment.