Use `OrderedUtxo` in `CheckpointVerifiedBlock` (#6971)
This commit is contained in:
parent
231f5be403
commit
abcabd1931
|
@ -183,7 +183,8 @@ impl CheckpointVerifiedBlock {
|
||||||
height: block::Height,
|
height: block::Height,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let transaction_hashes: Arc<[_]> = block.transactions.iter().map(|tx| tx.hash()).collect();
|
let transaction_hashes: Arc<[_]> = block.transactions.iter().map(|tx| tx.hash()).collect();
|
||||||
let new_outputs = transparent::new_outputs_with_height(&block, height, &transaction_hashes);
|
let new_outputs =
|
||||||
|
transparent::new_ordered_outputs_with_height(&block, height, &transaction_hashes);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
block,
|
block,
|
||||||
|
|
|
@ -235,7 +235,7 @@ pub struct CheckpointVerifiedBlock {
|
||||||
/// earlier transaction.
|
/// earlier transaction.
|
||||||
///
|
///
|
||||||
/// This field can also contain unrelated outputs, which are ignored.
|
/// This field can also contain unrelated outputs, which are ignored.
|
||||||
pub(crate) new_outputs: HashMap<transparent::OutPoint, transparent::Utxo>,
|
pub(crate) new_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
||||||
/// A precomputed list of the hashes of the transactions in this block,
|
/// A precomputed list of the hashes of the transactions in this block,
|
||||||
/// in the same order as `block.transactions`.
|
/// in the same order as `block.transactions`.
|
||||||
pub transaction_hashes: Arc<[transaction::Hash]>,
|
pub transaction_hashes: Arc<[transaction::Hash]>,
|
||||||
|
@ -369,7 +369,7 @@ impl CheckpointVerifiedBlock {
|
||||||
.coinbase_height()
|
.coinbase_height()
|
||||||
.expect("coinbase height was already checked");
|
.expect("coinbase height was already checked");
|
||||||
let transaction_hashes: Arc<[_]> = block.transactions.iter().map(|tx| tx.hash()).collect();
|
let transaction_hashes: Arc<[_]> = block.transactions.iter().map(|tx| tx.hash()).collect();
|
||||||
let new_outputs = transparent::new_outputs(&block, &transaction_hashes);
|
let new_outputs = transparent::new_ordered_outputs(&block, &transaction_hashes);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
block,
|
block,
|
||||||
|
@ -405,7 +405,7 @@ impl From<ContextuallyVerifiedBlock> for CheckpointVerifiedBlock {
|
||||||
block,
|
block,
|
||||||
hash,
|
hash,
|
||||||
height,
|
height,
|
||||||
new_outputs: utxos_from_ordered_utxos(new_outputs),
|
new_outputs,
|
||||||
transaction_hashes,
|
transaction_hashes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -976,7 +976,8 @@ impl Service<Request> for StateService {
|
||||||
// even though it is redundant for most finalized blocks.
|
// even though it is redundant for most finalized blocks.
|
||||||
// (Finalized blocks are verified using block hash checkpoints
|
// (Finalized blocks are verified using block hash checkpoints
|
||||||
// and transaction merkle tree block header commitments.)
|
// and transaction merkle tree block header commitments.)
|
||||||
self.pending_utxos.check_against(&finalized.new_outputs);
|
self.pending_utxos
|
||||||
|
.check_against_ordered(&finalized.new_outputs);
|
||||||
|
|
||||||
// # Performance
|
// # Performance
|
||||||
//
|
//
|
||||||
|
|
|
@ -305,10 +305,10 @@ impl ZebraDb {
|
||||||
let new_outputs_by_out_loc: BTreeMap<OutputLocation, transparent::Utxo> = finalized
|
let new_outputs_by_out_loc: BTreeMap<OutputLocation, transparent::Utxo> = finalized
|
||||||
.new_outputs
|
.new_outputs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(outpoint, utxo)| {
|
.map(|(outpoint, ordered_utxo)| {
|
||||||
(
|
(
|
||||||
lookup_out_loc(finalized.height, outpoint, &tx_hash_indexes),
|
lookup_out_loc(finalized.height, outpoint, &tx_hash_indexes),
|
||||||
utxo.clone(),
|
ordered_utxo.utxo.clone(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -331,7 +331,12 @@ impl ZebraDb {
|
||||||
}),
|
}),
|
||||||
self.utxo(&outpoint)
|
self.utxo(&outpoint)
|
||||||
.map(|ordered_utxo| ordered_utxo.utxo)
|
.map(|ordered_utxo| ordered_utxo.utxo)
|
||||||
.or_else(|| finalized.new_outputs.get(&outpoint).cloned())
|
.or_else(|| {
|
||||||
|
finalized
|
||||||
|
.new_outputs
|
||||||
|
.get(&outpoint)
|
||||||
|
.map(|ordered_utxo| ordered_utxo.utxo.clone())
|
||||||
|
})
|
||||||
.expect("already checked UTXO was in state or block"),
|
.expect("already checked UTXO was in state or block"),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -350,7 +355,12 @@ impl ZebraDb {
|
||||||
// Get the transparent addresses with changed balances/UTXOs
|
// Get the transparent addresses with changed balances/UTXOs
|
||||||
let changed_addresses: HashSet<transparent::Address> = spent_utxos_by_out_loc
|
let changed_addresses: HashSet<transparent::Address> = spent_utxos_by_out_loc
|
||||||
.values()
|
.values()
|
||||||
.chain(finalized.new_outputs.values())
|
.chain(
|
||||||
|
finalized
|
||||||
|
.new_outputs
|
||||||
|
.values()
|
||||||
|
.map(|ordered_utxo| &ordered_utxo.utxo),
|
||||||
|
)
|
||||||
.filter_map(|utxo| utxo.output.address(network))
|
.filter_map(|utxo| utxo.output.address(network))
|
||||||
.unique()
|
.unique()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -60,14 +60,6 @@ impl PendingUtxos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check the list of pending UTXO requests against the supplied [`transparent::Utxo`] index.
|
|
||||||
#[inline]
|
|
||||||
pub fn check_against(&mut self, utxos: &HashMap<transparent::OutPoint, transparent::Utxo>) {
|
|
||||||
for (outpoint, utxo) in utxos.iter() {
|
|
||||||
self.respond(outpoint, utxo.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Scan the set of waiting utxo requests for channels where all receivers
|
/// Scan the set of waiting utxo requests for channels where all receivers
|
||||||
/// have been dropped and remove the corresponding sender.
|
/// have been dropped and remove the corresponding sender.
|
||||||
pub fn prune(&mut self) {
|
pub fn prune(&mut self) {
|
||||||
|
|
|
@ -279,8 +279,9 @@ impl SentHashes {
|
||||||
let outpoints = block
|
let outpoints = block
|
||||||
.new_outputs
|
.new_outputs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(outpoint, utxo)| {
|
.map(|(outpoint, ordered_utxo)| {
|
||||||
self.known_utxos.insert(*outpoint, utxo.clone());
|
self.known_utxos
|
||||||
|
.insert(*outpoint, ordered_utxo.utxo.clone());
|
||||||
outpoint
|
outpoint
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
@ -419,7 +419,7 @@ proptest! {
|
||||||
// the genesis block has a zero-valued transparent output,
|
// the genesis block has a zero-valued transparent output,
|
||||||
// which is not included in the UTXO set
|
// which is not included in the UTXO set
|
||||||
if block.height > block::Height(0) {
|
if block.height > block::Height(0) {
|
||||||
let utxos = &block.new_outputs;
|
let utxos = &block.new_outputs.iter().map(|(k, ordered_utxo)| (*k, ordered_utxo.utxo.clone())).collect();
|
||||||
let block_value_pool = &block.block.chain_value_pool_change(utxos)?;
|
let block_value_pool = &block.block.chain_value_pool_change(utxos)?;
|
||||||
expected_finalized_value_pool += *block_value_pool;
|
expected_finalized_value_pool += *block_value_pool;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue