Skip to content

Commit

Permalink
fix: horizon sync (#6197)
Browse files Browse the repository at this point in the history
Description
---
Fixes horizon sync

Motivation and Context
---
Burned outputs are counted as spent, so we should not sync them when
doing horizon sync.

How Has This Been Tested?
---
manual 

What process can a PR reviewer use to test or verify this change?
---

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
SWvheerden authored Mar 11, 2024
1 parent 4821660 commit c96be82
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 c96be82

Please sign in to comment.