Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ kv = "0.24"
miniscript = { version = "12.3", default-features = false }
rand = "0.8"
rcgen = { version = "0.14", default-features = false, features = ["aws_lc_rs", "pem"] }
rustreexo = "0.4"
rustreexo = "0.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = { version = "0.10", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/floresta-chain/benches/chain_state_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use floresta_chain::AssumeValidArg;
use floresta_chain::ChainState;
use floresta_chain::FlatChainStore;
use floresta_chain::FlatChainStoreConfig;
use rustreexo::accumulator::proof::Proof;
use rustreexo::proof::Proof;

/// Reads the first 151 blocks (or 150 blocks on top of genesis) from blocks.txt, which are regtest
fn read_blocks_txt() -> Vec<Block> {
Expand Down
4 changes: 2 additions & 2 deletions crates/floresta-chain/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ mod tests {
use bitcoin::OutPoint;
use bitcoin::Transaction;
use bitcoin::Txid;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
use rustreexo::proof::Proof;
use rustreexo::stump::Stump;

use super::*;
use crate::BlockConsumer;
Expand Down
18 changes: 11 additions & 7 deletions crates/floresta-chain/src/pruned_utreexo/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use core::cell::UnsafeCell;
use bitcoin::block::Header as BlockHeader;
use bitcoin::blockdata::constants::genesis_block;
use bitcoin::hashes::sha256;
use bitcoin::hashes::Hash;
use bitcoin::Block;
use bitcoin::BlockHash;
use bitcoin::Network;
Expand All @@ -37,9 +38,9 @@ use bitcoin::Work;
use floresta_common::Channel;
#[cfg(feature = "metrics")]
use metrics;
use rustreexo::accumulator::node_hash::BitcoinNodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
use rustreexo::node_hash::BitcoinNodeHash;
use rustreexo::proof::Proof;
use rustreexo::stump::Stump;
use spin::RwLock;
use tracing::debug;
use tracing::info;
Expand Down Expand Up @@ -576,7 +577,7 @@ impl<PersistedState: ChainStore> ChainState<PersistedState> {
};

let mut acc = acc.as_slice();
let acc = Stump::deserialize(&mut acc).map_err(BlockchainError::UtreexoError)?;
let acc = Stump::deserialize(&mut acc)?;
Ok(Some(acc))
}

Expand Down Expand Up @@ -1000,7 +1001,10 @@ impl<PersistedState: ChainStore> BlockchainInterface for ChainState<PersistedSta
acc: Stump,
) -> Result<(), Self::Error> {
// Convert to BitcoinNodeHashes, from rustreexo
let del_hashes: Vec<_> = del_hashes.into_iter().map(Into::into).collect();
let del_hashes: Vec<_> = del_hashes
.into_iter()
.map(|hash| BitcoinNodeHash::Some(hash.to_byte_array()))
.collect();

if !acc.verify(&proof, &del_hashes)? {
return Err(BlockValidationErrors::InvalidProof)?;
Expand Down Expand Up @@ -1452,8 +1456,8 @@ mod test {
use floresta_common::assert_ok;
use floresta_common::bhash;
use rand::Rng;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
use rustreexo::proof::Proof;
use rustreexo::stump::Stump;

use super::BlockchainInterface;
use super::ChainParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use bitcoin::block::Header as BlockHeader;
use bitcoin::BlockHash;
use bitcoin::Network;
use rustreexo::accumulator::stump::Stump;
use rustreexo::stump::Stump;

use super::chain_state::ChainState;
use super::chainparams::ChainParams;
Expand Down
2 changes: 1 addition & 1 deletion crates/floresta-chain/src/pruned_utreexo/chainparams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bitcoin::Network;
use floresta_common::acchashes;
use floresta_common::bhash;
use floresta_common::service_flags;
use rustreexo::accumulator::node_hash::BitcoinNodeHash;
use rustreexo::node_hash::BitcoinNodeHash;

use crate::prelude::*;
use crate::AssumeValidArg;
Expand Down
11 changes: 8 additions & 3 deletions crates/floresta-chain/src/pruned_utreexo/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bitcoin::blockdata::Weight;
#[cfg(feature = "bitcoinkernel")]
use bitcoin::consensus::serialize;
use bitcoin::hashes::sha256;
use bitcoin::hashes::Hash;
use bitcoin::merkle_tree;
use bitcoin::script;
use bitcoin::Amount;
Expand All @@ -25,8 +26,9 @@ use bitcoin::Txid;
#[cfg(feature = "bitcoinkernel")]
use bitcoinkernel::PrecomputedTransactionData;
use floresta_common::prelude::*;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
use rustreexo::node_hash::BitcoinNodeHash;
use rustreexo::proof::Proof;
use rustreexo::stump::Stump;

use super::chainparams::ChainParams;
use super::error::BlockValidationErrors;
Expand Down Expand Up @@ -498,7 +500,10 @@ impl Consensus {
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer able to do this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do what? 😂

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer able to do this?

This what? I don't see any highlighted lines on your review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wtf, I just commented a deleted line. I mean the Into::into for the BitcoinNodeHash conversion, no longer possible I see

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is due to rustreexo using a different version of bitcoin-hashes than rust-bitcoin. Rust seems them as two different types. Rustreexo do implement that from, but until rust-bitcoin bumps their version, we can't really use it :/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cooked


// Convert to BitcoinNodeHash, from rustreexo
let del_hashes: Vec<_> = del_hashes.into_iter().map(Into::into).collect();
let del_hashes: Vec<_> = del_hashes
.into_iter()
.map(|hash| BitcoinNodeHash::Some(hash.to_byte_array()))
.collect();

let adds = udata::proof_util::get_block_adds(block, height, block_hash);

Expand Down
5 changes: 3 additions & 2 deletions crates/floresta-chain/src/pruned_utreexo/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bitcoin::OutPoint;
use bitcoin::Txid;
use floresta_common::impl_error_from;
use floresta_common::prelude::*;
use rustreexo::stump::StumpError;

use crate::proof_util::UtreexoLeafError;
use crate::pruned_utreexo::chain_state_builder::BlockchainBuilderError;
Expand All @@ -35,7 +36,7 @@ pub enum BlockchainError {
BlockValidation(BlockValidationErrors),
TransactionError(TransactionError),
InvalidProof,
UtreexoError(String),
UtreexoError(StumpError),
UtreexoLeaf(UtreexoLeafError),
Database(Box<dyn DatabaseError>),
ConsensusDecode(bitcoin::consensus::encode::Error),
Expand Down Expand Up @@ -196,7 +197,7 @@ impl_error_from!(
ConsensusDecode
);
impl_error_from!(BlockchainError, BlockValidationErrors, BlockValidation);
impl_error_from!(BlockchainError, String, UtreexoError);
impl_error_from!(BlockchainError, StumpError, UtreexoError);

impl Display for BlockchainError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Expand Down
6 changes: 3 additions & 3 deletions crates/floresta-chain/src/pruned_utreexo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use bitcoin::hashes::sha256;
use bitcoin::Block;
use bitcoin::BlockHash;
use bitcoin::OutPoint;
use rustreexo::accumulator::node_hash::BitcoinNodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
use rustreexo::node_hash::BitcoinNodeHash;
use rustreexo::proof::Proof;
use rustreexo::stump::Stump;

use self::partial_chain::PartialChainState;
use crate::prelude::*;
Expand Down
18 changes: 9 additions & 9 deletions crates/floresta-chain/src/pruned_utreexo/partial_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use bitcoin::block::Header as BlockHeader;
use bitcoin::Block;
use bitcoin::BlockHash;
use floresta_common::prelude::*;
use rustreexo::accumulator::node_hash::BitcoinNodeHash;
use rustreexo::accumulator::stump::Stump;
use rustreexo::node_hash::BitcoinNodeHash;
use rustreexo::stump::Stump;
use tracing::info;

use super::chainparams::ChainParams;
Expand Down Expand Up @@ -131,7 +131,7 @@ impl PartialChainStateInner {
pub fn process_block(
&mut self,
block: &bitcoin::Block,
proof: rustreexo::accumulator::proof::Proof,
proof: rustreexo::proof::Proof,
inputs: HashMap<bitcoin::OutPoint, UtxoData>,
del_hashes: Vec<bitcoin::hashes::sha256::Hash>,
) -> Result<u32, BlockchainError> {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl UpdatableChainstate for PartialChainState {
fn connect_block(
&self,
block: &bitcoin::Block,
proof: rustreexo::accumulator::proof::Proof,
proof: rustreexo::proof::Proof,
inputs: HashMap<bitcoin::OutPoint, UtxoData>,
del_hashes: Vec<bitcoin::hashes::sha256::Hash>,
) -> Result<u32, BlockchainError> {
Expand Down Expand Up @@ -400,7 +400,7 @@ impl BlockchainInterface for PartialChainState {
fn validate_block(
&self,
_block: &bitcoin::Block,
_proof: rustreexo::accumulator::proof::Proof,
_proof: rustreexo::proof::Proof,
_inputs: HashMap<bitcoin::OutPoint, UtxoData>,
_del_hashes: Vec<bitcoin::hashes::sha256::Hash>,
_acc: Stump,
Expand All @@ -417,7 +417,7 @@ impl BlockchainInterface for PartialChainState {
_acc: Stump,
_block: &Block,
_height: u32,
_proof: rustreexo::accumulator::proof::Proof,
_proof: rustreexo::proof::Proof,
_del_hashes: Vec<bitcoin::hashes::sha256::Hash>,
) -> Result<Stump, Self::Error> {
unimplemented!("PartialChainState::update_acc")
Expand Down Expand Up @@ -467,9 +467,9 @@ mod tests {
use bitcoin::Block;
use bitcoin::Network;
use floresta_common::acchashes;
use rustreexo::accumulator::node_hash::BitcoinNodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
use rustreexo::node_hash::BitcoinNodeHash;
use rustreexo::proof::Proof;
use rustreexo::stump::Stump;

use super::PartialChainState;
use crate::pruned_utreexo::chainparams::ChainParams;
Expand Down
9 changes: 5 additions & 4 deletions crates/floresta-chain/src/pruned_utreexo/udata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub mod proof_util {
use bitcoin::WPubkeyHash;
use bitcoin::WScriptHash;
use floresta_common::impl_error_from;
use rustreexo::accumulator::node_hash::BitcoinNodeHash;
use rustreexo::node_hash::BitcoinNodeHash;
use sha2::Digest;
use sha2::Sha512_256;

Expand Down Expand Up @@ -378,9 +378,10 @@ pub mod proof_util {
// Do not add unspendable nor already spent utxos
continue;
}
adds.push(
get_leaf_hashes(txid, is_cb, vout as u32, output, height, block_hash).into(),
);

let leaf_hash =
get_leaf_hashes(txid, is_cb, vout as u32, output, height, block_hash);
adds.push(BitcoinNodeHash::Some(leaf_hash.to_byte_array()));
}
}

Expand Down
Loading
Loading