Skip to content

Commit

Permalink
fix horizon sync
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Mar 11, 2024
1 parent 4821660 commit 0fd3e32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,35 +651,37 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {

let constants = self.rules.consensus_constants(current_header.height).clone();
let output = TransactionOutput::try_from(output).map_err(HorizonSyncError::ConversionError)?;
debug!(
target: LOG_TARGET,
"UTXO `{}` received from sync peer ({} of {})",
output.hash(),
utxo_counter,
self.num_outputs,
);
helpers::check_tari_script_byte_size(&output.script, constants.max_script_byte_size())?;

batch_verify_range_proofs(&self.prover, &[&output])?;
let smt_key = NodeKey::try_from(output.commitment.as_bytes())?;
let smt_node = ValueHash::try_from(output.smt_hash(current_header.height).as_slice())?;
if let Err(e) = output_smt.insert(smt_key, smt_node) {
error!(
if !output.is_burned() {
debug!(
target: LOG_TARGET,
"Output commitment({}) already in SMT",
output.commitment.to_hex(),
"UTXO `{}` received from sync peer ({} of {})",
output.hash(),
utxo_counter,
self.num_outputs,
);
return Err(e.into());
}
txn.insert_output_via_horizon_sync(
output,
current_header.hash(),
current_header.height,
current_header.timestamp.as_u64(),
);
helpers::check_tari_script_byte_size(&output.script, constants.max_script_byte_size())?;

// We have checked the range proof, and we have checked that the linked to header exists.
txn.commit().await?;
batch_verify_range_proofs(&self.prover, &[&output])?;
let smt_key = NodeKey::try_from(output.commitment.as_bytes())?;
let smt_node = ValueHash::try_from(output.smt_hash(current_header.height).as_slice())?;
if let Err(e) = output_smt.insert(smt_key, smt_node) {
error!(
target: LOG_TARGET,
"Output commitment({}) already in SMT",
output.commitment.to_hex(),
);
return Err(e.into());
}
txn.insert_output_via_horizon_sync(
output,
current_header.hash(),
current_header.height,
current_header.timestamp.as_u64(),
);

// We have checked the range proof, and we have checked that the linked to header exists.
txn.commit().await?;
}
},
Txo::Commitment(commitment_bytes) => {
stxo_counter += 1;
Expand Down
3 changes: 3 additions & 0 deletions base_layer/core/src/base_node/sync/rpc/sync_utxos_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ where B: BlockchainBackend + 'static

let mut outputs = Vec::with_capacity(outputs_with_statuses.len());
for (output, spent) in outputs_with_statuses {
if output.is_burned() {
continue;
}
if !spent {
match proto::types::TransactionOutput::try_from(output.clone()) {
Ok(tx_ouput) => {
Expand Down

0 comments on commit 0fd3e32

Please sign in to comment.