LocalChain with hardwired genesis block#1178
LocalChain with hardwired genesis block#1178notmandatory merged 13 commits intobitcoindevkit:masterfrom
LocalChain with hardwired genesis block#1178Conversation
6dadc40 to
01ee8c3
Compare
7c6164d to
eb39808
Compare
LocalChain with hardwired genesis blockLocalChain with hardwired genesis block
This comment was marked as resolved.
This comment was marked as resolved.
97c78e7 to
7e0cd98
Compare
632b806 to
63e06fd
Compare
crates/bitcoind_rpc/src/lib.rs
Outdated
| /// | ||
| /// `start_height` is the block height to start emitting blocks from. | ||
| pub fn from_height(client: &'c C, start_height: u32) -> Self { | ||
| /// TODO |
There was a problem hiding this comment.
I wonder what we can do so that we don't forget to write this doc.
There was a problem hiding this comment.
Looks like docs here should be something like:
| /// TODO | |
| /// Construct a new [`Emitter`] with the given RPC `client`, `last_cp` and `start_height`. | |
| /// | |
| /// `last_cp` is the check point used to find the latest block which is still part of the best chain. | |
| /// `start_height` is the block height to start emitting blocks from. |
vladimirfomene
left a comment
There was a problem hiding this comment.
Great work Evan! I just have some nits.
| impl<D> Wallet<D> { | ||
| /// Create a wallet from a `descriptor` (and an optional `change_descriptor`) and load related | ||
| /// transaction data from `db`. | ||
| /// Initialize an empty [`Wallet`]. |
There was a problem hiding this comment.
What does empty here mean? From my understanding, it means the wallet has an empty state (empty IndexedTxGraph, empty localchain). We might want to improve the doc here.
| Self::load_from_changeset(descriptor, change_descriptor, db, changeset) | ||
| } | ||
|
|
||
| fn load_from_changeset<E: IntoWalletDescriptor>( |
There was a problem hiding this comment.
nits: I will change the name of this method to init_from_changeset. Feel free to ignore if it doesn't resonate.
| C: Append + serde::Serialize + serde::de::DeserializeOwned, | ||
| { | ||
| /// Creates a new store from a [`File`]. | ||
| /// Create a new [`Store`] file in write-only mode; error if the file exists. |
There was a problem hiding this comment.
Is it really in write only mode given that the file is also given read option on line 65
notmandatory
left a comment
There was a problem hiding this comment.
ACK e342a8c
Looks good, nice to have that chain tip Option removed!
crates/bitcoind_rpc/src/lib.rs
Outdated
| /// | ||
| /// `start_height` is the block height to start emitting blocks from. | ||
| pub fn from_height(client: &'c C, start_height: u32) -> Self { | ||
| /// TODO |
There was a problem hiding this comment.
Looks like docs here should be something like:
| /// TODO | |
| /// Construct a new [`Emitter`] with the given RPC `client`, `last_cp` and `start_height`. | |
| /// | |
| /// `last_cp` is the check point used to find the latest block which is still part of the best chain. | |
| /// `start_height` is the block height to start emitting blocks from. |
|
This should also close #1107 . |
|
@evanlinjin looks like this one has a conflict so needs a rebase before I can merge it. |
This ensures that `LocalChain` will always have a tip. The `ChainOracle` trait's `get_chain_tip` method no longer needs to return an option.
`Wallet::new` now creates a new wallet. `Wallet::load` loads an existing wallet. The network type is now recoverable from persistence. Error types have been simplified.
e342a8c to
b216585
Compare
These methods try to load wallet from persistence and initializes the wallet instead if non-existant. An internal helper method `create_signers` is added to reuse code. Documentation is also improved.
`PersistBackend::is_empty` is removed. Instead, `load_from_persistence` returns an option of the changeset. `None` means persistence is empty. This is a better API than a separate method. We can now differentiate between a persisted single changeset and nothing persisted. `Store::aggregate_changeset` is refactored to return a `Result` instead of a tuple. A new error type (`AggregateChangesetsError`) is introduced to include the partially-aggregated changeset in the error. This is a more idiomatic API.
b216585 to
79b84be
Compare
|
@notmandatory don't merge yet, I want to address comments and make clippy happier. |
closes #1079
closes #1107
Description
Many methods of
TxGraphrequire achain_tip: BlockIdinput to use against aChainOracleimplementation. This is used to ask theChainOracleimplementation whether a certain block exists in the chain identified by thechain_tip. This guarantees that theTxGraphmethods will return a consistent history of transactions.However, the
ChainOracletrait'sget_chain_tipmethod returns an option ofBlockId. It becomes unclear what to do whenget_chain_tipreturnsNone.This PR changes the
ChainOracle::get_chain_tipmethod to always return aBlockId(noOption).LocalChainnow hardwires the genesis block in order to implementChainOracle.bdk::Walletandbdk_file_store::Storeare changed to have separate constructor methods for initializing a fresh instance and recovering a previous instance from persistence.Notes to the reviewers
Changelog notice
ChainOracle::get_chain_tipmethod to return aBlockIdinstead of anOptionof aBlockId.LocalChainso that the genesisBlockIdis hardwired. This way, theChainOracle::get_chain_tipimplementation can always return a tip.is_emptymethod toPersistBackend. This returns true when there is no data in the persistence.Wallet::newto initialize a fresh wallet only.Wallet::loadto restore an instance of a wallet.Store::newwith separate methods to create/open the database file.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features: