-
Notifications
You must be signed in to change notification settings - Fork 332
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
refactor: Implement generics for CheckPoint
, LocalChain
, and spk_client
types
#1582
base: master
Are you sure you want to change the base?
Conversation
CheckPoint
takes a genericCheckPoint
and LocalChain
a899049
to
7c13781
Compare
7c13781
to
d934a6c
Compare
ea1cf8b
to
bf90ea5
Compare
c278804
to
6300d7c
Compare
CheckPoint
and LocalChain
CheckPoint
, LocalChain
, and spk_client
types
6300d7c
to
315f687
Compare
7ef16f5
to
b7c5a9a
Compare
CheckPoint
, LocalChain
, and spk_client
typesCheckPoint
, LocalChain
, and spk_client
types
5f2d199
to
6b3ffa9
Compare
6b3ffa9
to
367099a
Compare
367099a
to
27fe3bb
Compare
27fe3bb
to
179ec5e
Compare
struct CPInner<B> { | ||
/// Block data. | ||
block_id: BlockId, | ||
/// Data. | ||
data: B, |
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.
When B
is a blockhash, won't this be storing the same block hash twice? 🤔
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.
+1 on this. Maybe data: Option<B>
or just keep the height as part of CPInner
?
struct CPInner<B> {
height: u32,
data: B,
prev: Option<Arc<CPinner<B>>>,
}
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.
Let's look at this from the API/performance perspective.
I think the "killer feature" of this PR is to be able to put Headers in Checkpoints.
Ideally, we want something like this: CheckPoint<Header>
. However, with the proposed changes, it will mean we will be hashing the Header
every time we want the block hash from the checkpoint (which will be extremely frequent).
To fix this, we can introduce another data type HeaderWithHash
- which, as the name suggests, contains the Header
and the BlockHash
together. I'm honestly not a fan of this as it becomes clunky.
Since memory is cheap, I think it is okay to duplicate the BlockHash
.
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.
If we really don't want to duplicate the BlockHash
, another solution would be to use an enum or option internally. It's honestly not pretty and we need to worry about unwraps and how to store the data. Not a fan.
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.
HeaderWithHash
sounds reasonable. (or HashedHeader
)
@@ -380,6 +381,88 @@ fn local_chain_insert_block() { | |||
} | |||
} | |||
|
|||
#[test] | |||
fn local_chain_insert_header() { |
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.
What do you think about constructing an array of consecutive headers first?
Then test cases can be constructed from a subset from this array.
The benefits of this is more correctness. The block hashes line up. The header-to-insert can be constructed from the previous block hash.
struct CPInner<B> { | ||
/// Block data. | ||
block_id: BlockId, | ||
/// Data. | ||
data: B, |
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.
Let's look at this from the API/performance perspective.
I think the "killer feature" of this PR is to be able to put Headers in Checkpoints.
Ideally, we want something like this: CheckPoint<Header>
. However, with the proposed changes, it will mean we will be hashing the Header
every time we want the block hash from the checkpoint (which will be extremely frequent).
To fix this, we can introduce another data type HeaderWithHash
- which, as the name suggests, contains the Header
and the BlockHash
together. I'm honestly not a fan of this as it becomes clunky.
Since memory is cheap, I think it is okay to duplicate the BlockHash
.
Since this one is still having design discussions can I move it out of the 1.1 milestone? |
Implements #1757.
Description
This PR is a step towards header checkpointing for
bdk_electrum
. The goal is to be able to store whole headers inCheckPoint
so they do not have to be re-downloaded. Storing headers this way would be a prerequisite for caching of merkle proofs and for median time passed.TODO:
CheckPoint
to take in a generic.LocalChange
to take in a generic.spk_client
types to take in generics.Notes to the reviewers
Changelog notice
CheckPoint
takes in a generic.LocalChain
andChangeSet
take in generics.spk_client
types can take in generics.Checklists
All Submissions:
cargo fmt
andcargo clippy
before committing