-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wallet): add check for network and genesis_hash consistency #1777
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,6 @@ pub mod signer; | |
pub mod tx_builder; | ||
pub(crate) mod utils; | ||
|
||
use crate::collections::{BTreeMap, HashMap, HashSet}; | ||
use crate::descriptor::{ | ||
check_wallet_descriptor, error::Error as DescriptorError, policy::BuildSatisfaction, | ||
DerivedDescriptor, DescriptorMeta, ExtendedDescriptor, ExtractPolicy, IntoWalletDescriptor, | ||
|
@@ -74,6 +73,10 @@ use crate::wallet::{ | |
tx_builder::{FeePolicy, TxBuilder, TxParams}, | ||
utils::{check_nsequence_rbf, After, Older, SecpCtx}, | ||
}; | ||
use crate::{ | ||
collections::{BTreeMap, HashMap, HashSet}, | ||
descriptor::error::MismatchError, | ||
}; | ||
|
||
// re-exports | ||
pub use bdk_chain::Balance; | ||
|
@@ -372,6 +375,14 @@ impl Wallet { | |
let genesis_hash = params | ||
.genesis_hash | ||
.unwrap_or(genesis_block(network).block_hash()); | ||
|
||
if genesis_hash.ne(&genesis_block(network).block_hash()) { | ||
return Err(DescriptorError::Mismatch(MismatchError::Genesis { | ||
network: genesis_block(network).block_hash(), | ||
parameter: genesis_hash, | ||
})); | ||
} | ||
|
||
let (chain, chain_changeset) = LocalChain::from_genesis_hash(genesis_hash); | ||
|
||
let (descriptor, mut descriptor_keymap) = (params.descriptor)(&secp, network)?; | ||
|
@@ -506,6 +517,14 @@ impl Wallet { | |
expected: exp_genesis_hash, | ||
})); | ||
} | ||
|
||
let network_genesis_hash = genesis_block(network).block_hash(); | ||
if network_genesis_hash != exp_genesis_hash { | ||
return Err(LoadError::Mismatch(LoadMismatch::Genesis { | ||
loaded: network_genesis_hash, | ||
expected: exp_genesis_hash, | ||
})); | ||
} | ||
Comment on lines
+521
to
+527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still unsure of how to properly test this one (or if it's even needed), because I can't initially create a wallet with It'll always fail on the previous check. |
||
} | ||
|
||
let descriptor = changeset | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by @ValuedMammal, the intention here is so the caller can provide a custom genesis hash.
However, if the intention is to enforce a 1-possible-genesis-hash-per-network-variant invariance, changing the data structure to disallow the invariance would make a lot more sense. I.e. remove
params.genesis_hash
.