Skip to content
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

Add NetworkMismatch error type #485

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elnosh
Copy link
Contributor

@elnosh elnosh commented Mar 17, 2025

for #117

Added a NetworkMismatch error type if the node is restarted with a different network. This is caught when trying to load bdk wallet.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this!

src/builder.rs Outdated
@@ -189,6 +191,7 @@ impl fmt::Display for BuildError {
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
Self::InvalidNodeAlias => write!(f, "Given node alias is invalid."),
Self::NetworkMismatch => write!(f, "Given network does match."),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Could you specify what it doesn't match?

BuildError::WalletSetupFailed
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network { .. }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems we might also want to match on the Genesis variant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm, since the genesis hash is not a configuration that can be directly set by the user I think the check on the network mismatch will already catch it? Because to do the check on the genesis hash we would first need to get it with something like: bitcoin::blockdata::constants::genesis_block(config.network).block_hash(); which depends on the network provided by the user. So it doesn't seem possible to pass the network check but fail the Genesis one. That's how I saw it but lmk if this is wrong and I'll change it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean, technically yes, but are we sure BDK won't ever emit a Genesis variant if we set the wrong Network?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we set the wrong network, yes I guess any of these two errors (Network or Genesis mismatch) could be thrown.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, that's why I'd prefer to match on both and return the mismatch error if either variant is returned.

@elnosh elnosh force-pushed the check-network-switch branch from 8991768 to 206a092 Compare March 19, 2025 12:37
Copy link
Contributor

@G8XSU G8XSU left a comment

Choose a reason for hiding this comment

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

Changes look good to me overall.

src/builder.rs Outdated
@@ -189,6 +191,7 @@ impl fmt::Display for BuildError {
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
Self::InvalidNodeAlias => write!(f, "Given node alias is invalid."),
Self::NetworkMismatch => write!(f, "Given network does not match the node's network."),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit : Given network does not match the node's previously configured network.

Return specific error if the node is restarted with a different network
from the one it was first created with. This will be caught when trying
to load the `BDK` wallet.
@elnosh elnosh force-pushed the check-network-switch branch from 206a092 to b1b2caf Compare March 20, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants