-
Notifications
You must be signed in to change notification settings - Fork 884
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
[ZCash ] Implement shard tree and shard storage #26477
base: shard_crate_impl
Are you sure you want to change the base?
Conversation
9192b28
to
a3ccf60
Compare
2eb3bc5
to
2d67e9d
Compare
a3ccf60
to
284506d
Compare
2d67e9d
to
6f8de17
Compare
@@ -312,10 +312,14 @@ static_library("browser") { | |||
|
|||
if (enable_orchard) { | |||
sources += [ | |||
"zcash/orchard_shard_tree_delegate_impl.cc", |
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.
these really need to move into their own BUILD.gn file in zcash directory
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.
meaning all of the files here, not just the new ones
@@ -57,6 +70,17 @@ source_set("orchard_impl") { | |||
] | |||
} | |||
|
|||
source_set("shard_store") { | |||
visibility = [ ":*" ] | |||
sources = [ "cxx/src/shard_store.h" ] |
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.
we don't want to use cxx directories anymore and it's not clear to me why this would go somewhere other than the existing ochrard_impl
target. In a separate PR we should move all the files in orchard_impl
into an internal
directory
Also generally speaking you shouldn't create a target in one directory that includes files in a subdirectory, especially if those are the only files it includes.
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.
it's not clear to me why this would go somewhere other than the existing ochrard_impl target.
There will be cycle dependency otherwise rust_lib depends on shard_store.h and orchard_impl depends on rust_lib
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 would use qr_code_generator
as an example to follow for this which would probably mean shard_store.h moves into this directory.
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.
it's a bit confusing that this directory is called rust
and also contains cpp files, but we should probably rename it in a separate PR
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.
Moved to the zcash/rust directory
components/brave_wallet/browser/zcash/rust/orchard_shard_tree_impl.cc
Outdated
Show resolved
Hide resolved
components/brave_wallet/browser/zcash/rust/cxx/src/shard_store.h
Outdated
Show resolved
Hide resolved
// Note witness is a Merkle path in the Orchard commitment tree from the | ||
// note to the tree root according some selected anchor(selected right border in | ||
// the commitment tree). | ||
struct OrchardNoteWitness { |
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 entire file is a problem, we should not just be dumping a bunch of structs in here like this. You don't necessarily need a file for each, but they should be organized in some sensible way because this file is a mess
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.
it seems like these probably belong with https://github.com/brave/brave-core/pull/26477/files#r1840956570
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.
Moved
std::vector<uint8_t> frontier; | ||
}; | ||
|
||
class OrchardShardTreeDelegate { |
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 definitely should go in its own file
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.
Moved to separate file
3964309
to
9e7ed49
Compare
|
||
namespace brave_wallet::orchard { | ||
|
||
class OrchardDecodedBlocksBundle { |
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.
please provide some comments for these new classes and also the need unit tests
OrchardDecodedBlocksBundleImpl::GetDiscoveredNotes() { | ||
std::vector<OrchardNote> result; | ||
|
||
for (size_t i = 0; i < batch_decode_result_->size(); i++) { |
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.
How big could this list be? Is there an upper bound?
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.
We should be calling result.reserve(batch_decode_result_->size())
before looping.
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.
Shouldn't be too big, this is sort of incoming transactions, in most cases it should be less than 10, i guess
orchard_action->ciphertext.size() != kOrchardCipherTextSize) { | ||
return std::nullopt; | ||
} | ||
std::unique_ptr<OrchardDecodedBlocksBundle> OrchardBlockDecoderImpl::ScanBlocks( |
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.
unit tests?
80425d6
to
c754ce2
Compare
443fd78
to
b801c0f
Compare
b801c0f
to
48bb0c5
Compare
|
||
namespace brave_wallet { | ||
|
||
OrchardTreeState::OrchardTreeState() = default; |
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 does not belong in common. Only code used in both browser and renderer process belongs in common
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.
Moved to orchard_types
a189121
to
0c59073
Compare
OrchardShardTreeManager::CalculateWitness( | ||
const std::vector<OrchardInput>& notes, | ||
uint32_t checkpoint_position) { | ||
std::vector<OrchardInput> result; |
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.
result.resever(notes.size());
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.
Done
return base::unexpected(witness.error()); | ||
} | ||
result.push_back(input); | ||
result.back().witness = witness.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.
std::move
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.
Done
static std::unique_ptr<OrchardShardTreeManager> Create( | ||
std::unique_ptr<OrchardShardTreeDelegate> delegate); | ||
|
||
// Creates shard tree size of 8 for testing. | ||
static std::unique_ptr<OrchardShardTreeManager> CreateForTesting( | ||
std::unique_ptr<OrchardShardTreeDelegate> delegate); |
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.
Do we really need these factory functions? Do you think it would be helpful if we simplified instantiation by just having it happening in place, rather than having this hidden behind this class?
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 file was deleted
auto result = CreateResultForTesting(prior_tree_state, commitments); | ||
tree_manager()->InsertCommitments(std::move(result)); | ||
|
||
{ |
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 there a particular reason to have these blocks at the end of the test?
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.
Removed
if (i == 2) { | ||
commitments.push_back(CreateCommitment( | ||
CreateMockCommitmentValue(i, kDefaultCommitmentSeed), true, | ||
std::nullopt)); | ||
} else if (i == 3) { | ||
commitments.push_back(CreateCommitment( | ||
CreateMockCommitmentValue(i, kDefaultCommitmentSeed), false, 1)); | ||
} else if (i == 5) { | ||
commitments.push_back(CreateCommitment( | ||
CreateMockCommitmentValue(i, kDefaultCommitmentSeed), false, 2)); | ||
} else { |
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.
A switch will make this terser and easier to read, don't you think?
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.
Done
components/brave_wallet/browser/internal/orchard_storage/orchard_shard_tree_delegate.h
Outdated
Show resolved
Hide resolved
~OrchardShardTreeDelegate(); | ||
|
||
base::expected<std::optional<OrchardShardTreeCap>, Error> GetCap() const; | ||
base::expected<bool, Error> PutCap(const OrchardShardTreeCap& cap); |
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.
There's an idiom for when you want to signal failure, but you don't have an error code:
base::expected<T, void>
I'm bringing this up because we have an Error
enum with a single value. I think using void
for type would better communicate the fact that we are passing an error, but we don't have anything useful about the error.
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 file was deleted
base::ranges::copy(orchard_action->nullifier, | ||
orchard_compact_action.nullifier.begin()); | ||
base::ranges::copy(orchard_action->cmx, | ||
orchard_compact_action.cmx.begin()); | ||
base::ranges::copy(orchard_action->ephemeral_key, | ||
orchard_compact_action.ephemeral_key.begin()); | ||
base::ranges::copy(orchard_action->ciphertext, | ||
orchard_compact_action.enc_cipher_text.begin()); |
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.
These copies are supposed to be something like:
base::span(orchard_compact_action.nullifier).copy_from(orchard_action->nullifier);
base::span(orchard_compact_action.cmx).copy_from(orchard_action->cmx);
base::span(orchard_compact_action.ephemeral_key).copy_from(orchard_action->ephemeral_key);
base::span(orchard_compact_action.enc_cipher_text).copy_from(orchard_action->ciphertext);
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.
Done
Resolves brave/brave-browser#39314
Crate pr : #26474
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: