Skip to content

Commit bc796f4

Browse files
committed
fix(example): bitcoind_rpc_polling now initializes local_chain properly
Previously, the genesis block is not initialized properly. Thank you @notmandatory for identifying this bug.
1 parent 4fd539b commit bc796f4

File tree

1 file changed

+13
-3
lines changed
  • example-crates/example_bitcoind_rpc_polling/src

1 file changed

+13
-3
lines changed

example-crates/example_bitcoind_rpc_polling/src/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bdk_bitcoind_rpc::{
1212
Emitter,
1313
};
1414
use bdk_chain::{
15-
bitcoin::{Block, Transaction},
15+
bitcoin::{constants::genesis_block, Block, Transaction},
1616
indexed_tx_graph, keychain,
1717
local_chain::{self, CheckPoint, LocalChain},
1818
ConfirmationTimeHeightAnchor, IndexedTxGraph,
@@ -117,18 +117,28 @@ fn main() -> anyhow::Result<()> {
117117
"[{:>10}s] loaded initial changeset from db",
118118
start.elapsed().as_secs_f32()
119119
);
120+
let (init_chain_changeset, init_graph_changeset) = init_changeset;
120121

121122
let graph = Mutex::new({
122123
let mut graph = IndexedTxGraph::new(index);
123-
graph.apply_changeset(init_changeset.1);
124+
graph.apply_changeset(init_graph_changeset);
124125
graph
125126
});
126127
println!(
127128
"[{:>10}s] loaded indexed tx graph from changeset",
128129
start.elapsed().as_secs_f32()
129130
);
130131

131-
let chain = Mutex::new(LocalChain::from_changeset(init_changeset.0)?);
132+
let chain = Mutex::new(if init_chain_changeset.is_empty() {
133+
let genesis_hash = genesis_block(args.network).block_hash();
134+
let (chain, chain_changeset) = LocalChain::from_genesis_hash(genesis_hash);
135+
let mut db = db.lock().unwrap();
136+
db.stage((chain_changeset, Default::default()));
137+
db.commit()?;
138+
chain
139+
} else {
140+
LocalChain::from_changeset(init_chain_changeset)?
141+
});
132142
println!(
133143
"[{:>10}s] loaded local chain from changeset",
134144
start.elapsed().as_secs_f32()

0 commit comments

Comments
 (0)