Skip to content

Commit

Permalink
feat: add input_mr and witness_mr to header (#3041)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jun 30, 2021
2 parents adb4a64 + 59f9675 commit 65552cb
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 455 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ and performing mining:
2021-02-26 11:28:19.687855700 [tari_mining_node::miner] INFO Mining thread 2 stopped
2021-02-26 11:28:19.688251200 [tari_mining_node] INFO Miner 2 found block header BlockHeader { hash: [...], version: 1,
height: 8493, prev_hash: [...], timestamp: Some(Timestamp { seconds: 1614331698, nanos: 0 }), output_mr: [...],
range_proof_mr: [...], total_kernel_offset: [...], nonce: 8415580256943728281, pow: Some(ProofOfWork { pow_algo: 2,
witness_mr: [...], total_kernel_offset: [...], nonce: 8415580256943728281, pow: Some(ProofOfWork { pow_algo: 2,
pow_data: [] }), kernel_mmr_size: 24983, output_mmr_size: 125474 } with difficulty 7316856839
```

Expand Down
18 changes: 10 additions & 8 deletions applications/tari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ message BlockHeader {
// This is the UTXO merkle root of the outputs
// This is calculated as Hash (txo MMR root || roaring bitmap hash of UTXO indices)
bytes output_mr = 6;
// This is the MMR root of the range proofs
bytes range_proof_mr = 7;
// This is the MMR root of the the output witness data
bytes witness_mr = 7;
// This is the MMR root of the kernels
bytes kernel_mr = 8;
// This is the Merkle root of the inputs in this block
bytes input_mr = 9;
// Total accumulated sum of kernel offsets since genesis block. We can derive the kernel offset sum for *this*
// block from the total kernel offset of the previous block header.
bytes total_kernel_offset = 9;
bytes total_kernel_offset = 10;
// Nonce increment used to mine this block.
uint64 nonce = 10;
uint64 nonce = 11;
// Proof of work metadata
ProofOfWork pow = 11;
ProofOfWork pow = 12;
// Kernel MMR size
uint64 kernel_mmr_size = 12;
uint64 kernel_mmr_size = 13;
// Output MMR size
uint64 output_mmr_size = 13;
uint64 output_mmr_size = 14;
// Sum of script offsets for all kernels in this block.
bytes total_script_offset = 14;
bytes total_script_offset = 15;
}

// Metadata required for validating the Proof of Work calculation
Expand Down
303 changes: 0 additions & 303 deletions applications/tari_app_grpc/src/blocks.rs

This file was deleted.

19 changes: 11 additions & 8 deletions applications/tari_app_grpc/src/conversions/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@ use tari_crypto::tari_utilities::{ByteArray, Hashable};

impl From<BlockHeader> for grpc::BlockHeader {
fn from(h: BlockHeader) -> Self {
let pow_algo = h.pow_algo();
Self {
hash: h.hash(),
version: h.version as u32,
height: h.height,
prev_hash: h.prev_hash.clone(),
prev_hash: h.prev_hash,
timestamp: Some(datetime_to_timestamp(h.timestamp)),
output_mr: h.output_mr.clone(),
range_proof_mr: h.range_proof_mr.clone(),
input_mr: h.input_mr,
output_mr: h.output_mr,
output_mmr_size: h.output_mmr_size,
kernel_mr: h.kernel_mr.clone(),
kernel_mr: h.kernel_mr,
kernel_mmr_size: h.kernel_mmr_size,
total_kernel_offset: Vec::from(h.total_kernel_offset.as_bytes()),
total_script_offset: Vec::from(h.total_script_offset.as_bytes()),
witness_mr: h.witness_mr,
total_kernel_offset: h.total_kernel_offset.to_vec(),
total_script_offset: h.total_script_offset.to_vec(),
nonce: h.nonce,
pow: Some(grpc::ProofOfWork {
pow_algo: h.pow_algo().as_u64(),
pow_algo: pow_algo.as_u64(),
pow_data: h.pow.pow_data,
}),
}
Expand Down Expand Up @@ -76,8 +78,9 @@ impl TryFrom<grpc::BlockHeader> for BlockHeader {
height: header.height,
prev_hash: header.prev_hash,
timestamp,
input_mr: header.input_mr,
output_mr: header.output_mr,
range_proof_mr: header.range_proof_mr,
witness_mr: header.witness_mr,
output_mmr_size: header.output_mmr_size,
kernel_mr: header.kernel_mr,
kernel_mmr_size: header.kernel_mmr_size,
Expand Down
Loading

0 comments on commit 65552cb

Please sign in to comment.