Skip to content

Commit 1193348

Browse files
authored
Merge branch 'bitcoindevkit:master' into refactor/recover-testing
2 parents 8f19aa3 + d99b3ef commit 1193348

File tree

41 files changed

+1550
-1134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1550
-1134
lines changed

.github/workflows/cont_integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
cargo update -p home --precise "0.5.5"
3636
cargo update -p proptest --precise "1.2.0"
3737
cargo update -p url --precise "2.5.0"
38+
cargo update -p cc --precise "1.0.105"
3839
- name: Build
3940
run: cargo build ${{ matrix.features }}
4041
- name: Test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ cargo update -p time --precise "0.3.20"
7373
cargo update -p home --precise "0.5.5"
7474
cargo update -p proptest --precise "1.2.0"
7575
cargo update -p url --precise "2.5.0"
76+
cargo update -p cc --precise "1.0.105"
7677
```
7778

7879
## License

crates/bitcoind_rpc/tests/test_emitter.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::collections::{BTreeMap, BTreeSet};
33
use bdk_bitcoind_rpc::Emitter;
44
use bdk_chain::{
55
bitcoin::{Address, Amount, Txid},
6-
keychain::Balance,
76
local_chain::{CheckPoint, LocalChain},
8-
Append, BlockId, IndexedTxGraph, SpkTxOutIndex,
7+
Balance, BlockId, IndexedTxGraph, Merge, SpkTxOutIndex,
98
};
109
use bdk_testenv::{anyhow, TestEnv};
1110
use bitcoin::{hashes::Hash, Block, OutPoint, ScriptBuf, WScriptHash};
@@ -392,7 +391,6 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
392391
get_balance(&recv_chain, &recv_graph)?,
393392
Balance {
394393
confirmed: SEND_AMOUNT * (ADDITIONAL_COUNT - reorg_count) as u64,
395-
trusted_pending: SEND_AMOUNT * reorg_count as u64,
396394
..Balance::default()
397395
},
398396
"reorg_count: {}",

crates/chain/src/keychain.rs renamed to crates/chain/src/balance.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
//! Module for keychain related structures.
2-
//!
3-
//! A keychain here is a set of application-defined indexes for a miniscript descriptor where we can
4-
//! derive script pubkeys at a particular derivation index. The application's index is simply
5-
//! anything that implements `Ord`.
6-
//!
7-
//! [`KeychainTxOutIndex`] indexes script pubkeys of keychains and scans in relevant outpoints (that
8-
//! has a `txout` containing an indexed script pubkey). Internally, this uses [`SpkTxOutIndex`], but
9-
//! also maintains "revealed" and "lookahead" index counts per keychain.
10-
//!
11-
//! [`SpkTxOutIndex`]: crate::SpkTxOutIndex
12-
13-
#[cfg(feature = "miniscript")]
14-
mod txout_index;
15-
use bitcoin::{Amount, ScriptBuf};
16-
#[cfg(feature = "miniscript")]
17-
pub use txout_index::*;
1+
use bitcoin::Amount;
182

193
/// Balance, differentiated into various categories.
204
#[derive(Debug, PartialEq, Eq, Clone, Default)]
@@ -49,11 +33,6 @@ impl Balance {
4933
}
5034
}
5135

52-
/// A tuple of keychain index and `T` representing the indexed value.
53-
pub type Indexed<T> = (u32, T);
54-
/// A tuple of keychain `K`, derivation index (`u32`) and a `T` associated with them.
55-
pub type KeychainIndexed<K, T> = ((K, u32), T);
56-
5736
impl core::fmt::Display for Balance {
5837
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5938
write!(

crates/chain/src/chain_data.rs

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ impl ConfirmationTime {
7474
}
7575
}
7676

77-
impl From<ChainPosition<ConfirmationTimeHeightAnchor>> for ConfirmationTime {
78-
fn from(observed_as: ChainPosition<ConfirmationTimeHeightAnchor>) -> Self {
77+
impl From<ChainPosition<ConfirmationBlockTime>> for ConfirmationTime {
78+
fn from(observed_as: ChainPosition<ConfirmationBlockTime>) -> Self {
7979
match observed_as {
8080
ChainPosition::Confirmed(a) => Self::Confirmed {
81-
height: a.confirmation_height,
81+
height: a.block_id.height,
8282
time: a.confirmation_time,
8383
},
8484
ChainPosition::Unconfirmed(last_seen) => Self::Unconfirmed { last_seen },
@@ -145,9 +145,7 @@ impl From<(&u32, &BlockHash)> for BlockId {
145145
}
146146
}
147147

148-
/// An [`Anchor`] implementation that also records the exact confirmation height of the transaction.
149-
///
150-
/// Note that the confirmation block and the anchor block can be different here.
148+
/// An [`Anchor`] implementation that also records the exact confirmation time of the transaction.
151149
///
152150
/// Refer to [`Anchor`] for more details.
153151
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
@@ -156,70 +154,27 @@ impl From<(&u32, &BlockHash)> for BlockId {
156154
derive(serde::Deserialize, serde::Serialize),
157155
serde(crate = "serde_crate")
158156
)]
159-
pub struct ConfirmationHeightAnchor {
160-
/// The exact confirmation height of the transaction.
161-
///
162-
/// It is assumed that this value is never larger than the height of the anchor block.
163-
pub confirmation_height: u32,
157+
pub struct ConfirmationBlockTime {
164158
/// The anchor block.
165-
pub anchor_block: BlockId,
166-
}
167-
168-
impl Anchor for ConfirmationHeightAnchor {
169-
fn anchor_block(&self) -> BlockId {
170-
self.anchor_block
171-
}
172-
173-
fn confirmation_height_upper_bound(&self) -> u32 {
174-
self.confirmation_height
175-
}
176-
}
177-
178-
impl AnchorFromBlockPosition for ConfirmationHeightAnchor {
179-
fn from_block_position(_block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
180-
Self {
181-
anchor_block: block_id,
182-
confirmation_height: block_id.height,
183-
}
184-
}
185-
}
186-
187-
/// An [`Anchor`] implementation that also records the exact confirmation time and height of the
188-
/// transaction.
189-
///
190-
/// Note that the confirmation block and the anchor block can be different here.
191-
///
192-
/// Refer to [`Anchor`] for more details.
193-
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
194-
#[cfg_attr(
195-
feature = "serde",
196-
derive(serde::Deserialize, serde::Serialize),
197-
serde(crate = "serde_crate")
198-
)]
199-
pub struct ConfirmationTimeHeightAnchor {
200-
/// The confirmation height of the transaction being anchored.
201-
pub confirmation_height: u32,
159+
pub block_id: BlockId,
202160
/// The confirmation time of the transaction being anchored.
203161
pub confirmation_time: u64,
204-
/// The anchor block.
205-
pub anchor_block: BlockId,
206162
}
207163

208-
impl Anchor for ConfirmationTimeHeightAnchor {
164+
impl Anchor for ConfirmationBlockTime {
209165
fn anchor_block(&self) -> BlockId {
210-
self.anchor_block
166+
self.block_id
211167
}
212168

213169
fn confirmation_height_upper_bound(&self) -> u32 {
214-
self.confirmation_height
170+
self.block_id.height
215171
}
216172
}
217173

218-
impl AnchorFromBlockPosition for ConfirmationTimeHeightAnchor {
174+
impl AnchorFromBlockPosition for ConfirmationBlockTime {
219175
fn from_block_position(block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
220176
Self {
221-
anchor_block: block_id,
222-
confirmation_height: block_id.height,
177+
block_id,
223178
confirmation_time: block.header.time as _,
224179
}
225180
}
@@ -305,19 +260,19 @@ mod test {
305260

306261
#[test]
307262
fn chain_position_ord() {
308-
let unconf1 = ChainPosition::<ConfirmationHeightAnchor>::Unconfirmed(10);
309-
let unconf2 = ChainPosition::<ConfirmationHeightAnchor>::Unconfirmed(20);
310-
let conf1 = ChainPosition::Confirmed(ConfirmationHeightAnchor {
311-
confirmation_height: 9,
312-
anchor_block: BlockId {
313-
height: 20,
263+
let unconf1 = ChainPosition::<ConfirmationBlockTime>::Unconfirmed(10);
264+
let unconf2 = ChainPosition::<ConfirmationBlockTime>::Unconfirmed(20);
265+
let conf1 = ChainPosition::Confirmed(ConfirmationBlockTime {
266+
confirmation_time: 20,
267+
block_id: BlockId {
268+
height: 9,
314269
..Default::default()
315270
},
316271
});
317-
let conf2 = ChainPosition::Confirmed(ConfirmationHeightAnchor {
318-
confirmation_height: 12,
319-
anchor_block: BlockId {
320-
height: 15,
272+
let conf2 = ChainPosition::Confirmed(ConfirmationBlockTime {
273+
confirmation_time: 15,
274+
block_id: BlockId {
275+
height: 12,
321276
..Default::default()
322277
},
323278
});

crates/chain/src/changeset.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub struct CombinedChangeSet<K, A> {
1616
/// Changes to the [`LocalChain`](crate::local_chain::LocalChain).
1717
pub chain: crate::local_chain::ChangeSet,
1818
/// Changes to [`IndexedTxGraph`](crate::indexed_tx_graph::IndexedTxGraph).
19-
pub indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>,
19+
pub indexed_tx_graph:
20+
crate::indexed_tx_graph::ChangeSet<A, crate::indexer::keychain_txout::ChangeSet<K>>,
2021
/// Stores the network type of the transaction data.
2122
pub network: Option<bitcoin::Network>,
2223
}
@@ -33,10 +34,10 @@ impl<K, A> core::default::Default for CombinedChangeSet<K, A> {
3334
}
3435

3536
#[cfg(feature = "miniscript")]
36-
impl<K: Ord, A: crate::Anchor> crate::Append for CombinedChangeSet<K, A> {
37-
fn append(&mut self, other: Self) {
38-
crate::Append::append(&mut self.chain, other.chain);
39-
crate::Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph);
37+
impl<K: Ord, A: crate::Anchor> crate::Merge for CombinedChangeSet<K, A> {
38+
fn merge(&mut self, other: Self) {
39+
crate::Merge::merge(&mut self.chain, other.chain);
40+
crate::Merge::merge(&mut self.indexed_tx_graph, other.indexed_tx_graph);
4041
if other.network.is_some() {
4142
debug_assert!(
4243
self.network.is_none() || self.network == other.network,
@@ -62,11 +63,14 @@ impl<K, A> From<crate::local_chain::ChangeSet> for CombinedChangeSet<K, A> {
6263
}
6364

6465
#[cfg(feature = "miniscript")]
65-
impl<K, A> From<crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>>
66+
impl<K, A> From<crate::indexed_tx_graph::ChangeSet<A, crate::indexer::keychain_txout::ChangeSet<K>>>
6667
for CombinedChangeSet<K, A>
6768
{
6869
fn from(
69-
indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>,
70+
indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<
71+
A,
72+
crate::indexer::keychain_txout::ChangeSet<K>,
73+
>,
7074
) -> Self {
7175
Self {
7276
indexed_tx_graph,
@@ -76,8 +80,8 @@ impl<K, A> From<crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet
7680
}
7781

7882
#[cfg(feature = "miniscript")]
79-
impl<K, A> From<crate::keychain::ChangeSet<K>> for CombinedChangeSet<K, A> {
80-
fn from(indexer: crate::keychain::ChangeSet<K>) -> Self {
83+
impl<K, A> From<crate::indexer::keychain_txout::ChangeSet<K>> for CombinedChangeSet<K, A> {
84+
fn from(indexer: crate::indexer::keychain_txout::ChangeSet<K>) -> Self {
8185
Self {
8286
indexed_tx_graph: crate::indexed_tx_graph::ChangeSet {
8387
indexer,

crates/chain/src/descriptor_ext.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use crate::{
2-
alloc::{string::ToString, vec::Vec},
3-
miniscript::{Descriptor, DescriptorPublicKey},
4-
};
1+
use crate::miniscript::{Descriptor, DescriptorPublicKey};
52
use bitcoin::hashes::{hash_newtype, sha256, Hash};
63

74
hash_newtype! {
8-
/// Represents the ID of a descriptor, defined as the sha256 hash of
9-
/// the descriptor string, checksum excluded.
5+
/// Represents the unique ID of a descriptor.
106
///
117
/// This is useful for having a fixed-length unique representation of a descriptor,
128
/// in particular, we use it to persist application state changes related to the
@@ -21,8 +17,8 @@ pub trait DescriptorExt {
2117
/// Panics if the descriptor wildcard is hardened.
2218
fn dust_value(&self) -> u64;
2319

24-
/// Returns the descriptor id, calculated as the sha256 of the descriptor, checksum not
25-
/// included.
20+
/// Returns the descriptor ID, calculated as the sha256 hash of the spk derived from the
21+
/// descriptor at index 0.
2622
fn descriptor_id(&self) -> DescriptorId;
2723
}
2824

@@ -36,9 +32,7 @@ impl DescriptorExt for Descriptor<DescriptorPublicKey> {
3632
}
3733

3834
fn descriptor_id(&self) -> DescriptorId {
39-
let desc = self.to_string();
40-
let desc_without_checksum = desc.split('#').next().expect("Must be here");
41-
let descriptor_bytes = <Vec<u8>>::from(desc_without_checksum.as_bytes());
42-
DescriptorId(sha256::Hash::hash(&descriptor_bytes))
35+
let spk = self.at_derivation_index(0).unwrap().script_pubkey();
36+
DescriptorId(sha256::Hash::hash(spk.as_bytes()))
4337
}
4438
}

0 commit comments

Comments
 (0)