-
Notifications
You must be signed in to change notification settings - Fork 251
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
Basic put_block
function for the memory wallet
#1298
Basic put_block
function for the memory wallet
#1298
Conversation
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.
I am pretty new to the codebase so i have a lot of unknowns and questions.
@@ -98,6 +98,7 @@ impl<AccountId, N> Recipient<AccountId, Option<N>> { | |||
/// The shielded subset of a [`Transaction`]'s data that is relevant to a particular wallet. | |||
/// | |||
/// [`Transaction`]: zcash_primitives::transaction::Transaction | |||
#[derive(Clone)] |
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.
I had to do this for my version of put_blocks
as i was not able to make it otherwise, it might be not needed and not wanted.
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.
Sorry it's taken me a bit to get to commenting on this; it's been a busy time getting Zashi 1.0 out. :)
@@ -236,7 +235,10 @@ impl WalletRead for MemoryWalletDb { | |||
} | |||
|
|||
fn chain_height(&self) -> Result<Option<BlockHeight>, Self::Error> { | |||
todo!() | |||
match self.blocks.last_key_value() { |
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.
Something to take into consideration here is how this is handled in zcash_client_sqlite
: in that context, the chain tip may not yet have been scanned, so we get the current chain height as the maximum height known to the scan queue, rather than the blocks table.
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.
Blocks are added to the memory wallet database by put_blocks
which currently receives a vector of ScannedBlock
. Do we plan to change that ?
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.
Whatever is the case, ill open a separated PR for this.
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.
Blocks are added to the memory wallet database by
put_blocks
which currently receives a vector ofScannedBlock
. Do we plan to change that ?
No; the main distinction here is that the chain tip height is used in computing how to prioritize the scanning queue; we scan blocks out-of-order in many cases to improve time to spendability. The important related operation is update_chain_tip
; basically, chain_height
should return whatever is correct as of the last call to update_chain_tip
, not the last call to put_blocks
.
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.
In update_chain_tip
where do you store the height that is passed by argument so you can use it in chain_height
?
fn put_blocks( | ||
&mut self, | ||
// TODO: Figure out what to do with this field. | ||
_from_state: &super::chain::ChainState, |
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.
This is used to ensure we have a correct "starting point" for adding to the note commitment trees in https://github.com/zcash/librustzcash/blob/main/zcash_client_sqlite/src/lib.rs#L928-L934 and https://github.com/zcash/librustzcash/blob/main/zcash_client_sqlite/src/lib.rs#L977-L983
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.
Thanks, i added that at a4323c2
|
||
self.blocks.insert(block.block_height, memory_block); | ||
|
||
// Add the sapling commitments to the sapling tree. |
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.
Is this still needed now that we added the frontier?
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.
Yes; the frontier just provides a starting point, but the note commitments for each note in the block, and the commitment for the block-end checkpoint, must also be added.
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.
Thanks, i added the orchard version of this at 370a4aa
put_block
function for the memory walletput_block
function for the memory wallet
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.
The incorrect start to the note commitment tree position is blocking.
if let Some(value) = from_state.final_sapling_tree().value() { | ||
self.sapling_tree | ||
.batch_insert(value.position(), block_commitments.sapling.into_iter()); | ||
} |
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.
This is a bug, in that it doesn't handle constructing the tree starting from Sapling activation properly. I think something like this is necessary. Also, the final position of the previous frontier is one less than the starting position of new note commitments being added to the tree.
if let Some(value) = from_state.final_sapling_tree().value() { | |
self.sapling_tree | |
.batch_insert(value.position(), block_commitments.sapling.into_iter()); | |
} | |
let start_position = from_state.final_sapling_tree().value().map_or(0.into(), |t| t.position() + 1); | |
self.sapling_tree.batch_insert(start_position, block_commitments.sapling.into_iter()); |
// Add the Orchard commitments to the orchard tree. | ||
if let Some(value) = from_state.final_orchard_tree().value() { | ||
self.orchard_tree | ||
.batch_insert(value.position(), block_commitments.orchard.into_iter()); | ||
} |
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.
// Add the Orchard commitments to the orchard tree. | |
if let Some(value) = from_state.final_orchard_tree().value() { | |
self.orchard_tree | |
.batch_insert(value.position(), block_commitments.orchard.into_iter()); | |
} | |
{ | |
// Add the Orchard commitments to the orchard tree. | |
let start_position = from_state.final_orchard_tree().value().map_or(0.into(), |t| t.position() + 1); | |
self.orchard_tree.batch_insert(start_position, block_commitments.orchard.into_iter()); |
Co-authored-by: Kris Nuttycombe <[email protected]>
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.
utACK c9a236e
I want to create the most basic version of a
put_blocks
function for the memory wallet, one where we assume that the blocks will be in order.This PR is for @nuttycom to take a look, it has some comments and questions in the code and also review comments.