-
Notifications
You must be signed in to change notification settings - Fork 884
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implelent shard tree and shard storage
Resolves brave/brave-browser#39314
- Loading branch information
Showing
53 changed files
with
5,627 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
components/brave_wallet/browser/internal/orchard_shard_tree_manager.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/brave_wallet/browser/internal/orchard_shard_tree_manager.h" | ||
|
||
#include "brave/components/brave_wallet/common/zcash_utils.h" | ||
|
||
namespace brave_wallet { | ||
|
||
// static | ||
std::unique_ptr<OrchardShardTreeManager> OrchardShardTreeManager::Create( | ||
std::unique_ptr<OrchardShardTreeDelegate> delegate) { | ||
auto shard_tree = orchard::OrchardShardTree::Create(std::move(delegate)); | ||
if (!shard_tree) { | ||
return nullptr; | ||
} | ||
return std::make_unique<OrchardShardTreeManager>(std::move(shard_tree)); | ||
} | ||
|
||
// static | ||
std::unique_ptr<OrchardShardTreeManager> | ||
OrchardShardTreeManager::CreateForTesting( | ||
std::unique_ptr<OrchardShardTreeDelegate> delegate) { | ||
auto shard_tree = | ||
orchard::OrchardShardTree::CreateForTesting(std::move(delegate)); | ||
if (!shard_tree) { | ||
return nullptr; | ||
} | ||
return std::make_unique<OrchardShardTreeManager>(std::move(shard_tree)); | ||
} | ||
|
||
OrchardShardTreeManager::OrchardShardTreeManager( | ||
std::unique_ptr<::brave_wallet::orchard::OrchardShardTree> shard_tree) { | ||
orchard_shard_tree_ = std::move(shard_tree); | ||
} | ||
|
||
OrchardShardTreeManager::~OrchardShardTreeManager() {} | ||
|
||
bool OrchardShardTreeManager::InsertCommitments( | ||
OrchardBlockScanner::Result result) { | ||
return orchard_shard_tree_->ApplyScanResults( | ||
std::move(result.scanned_blocks)); | ||
} | ||
|
||
base::expected<std::vector<OrchardInput>, std::string> | ||
OrchardShardTreeManager::CalculateWitness(std::vector<OrchardInput> notes, | ||
uint32_t checkpoint_position) { | ||
for (auto& input : notes) { | ||
auto witness = orchard_shard_tree_->CalculateWitness( | ||
input.note.orchard_commitment_tree_position, checkpoint_position); | ||
if (!witness.has_value()) { | ||
return base::unexpected(witness.error()); | ||
} | ||
input.witness = witness.value(); | ||
} | ||
return notes; | ||
} | ||
|
||
bool OrchardShardTreeManager::Truncate(uint32_t checkpoint) { | ||
return orchard_shard_tree_->TruncateToCheckpoint(checkpoint); | ||
} | ||
|
||
} // namespace brave_wallet |
47 changes: 47 additions & 0 deletions
47
components/brave_wallet/browser/internal/orchard_shard_tree_manager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_INTERNAL_ORCHARD_SHARD_TREE_MANAGER_H_ | ||
#define BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_INTERNAL_ORCHARD_SHARD_TREE_MANAGER_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "base/types/expected.h" | ||
#include "brave/components/brave_wallet/browser/internal/orchard_block_scanner.h" | ||
#include "brave/components/brave_wallet/browser/zcash/rust/orchard_shard_tree.h" | ||
#include "brave/components/brave_wallet/common/zcash_utils.h" | ||
|
||
namespace brave_wallet { | ||
|
||
class OrchardShardTreeManager { | ||
public: | ||
OrchardShardTreeManager( | ||
std::unique_ptr<::brave_wallet::orchard::OrchardShardTree> shard_tree); | ||
~OrchardShardTreeManager(); | ||
bool InsertCommitments(OrchardBlockScanner::Result commitments); | ||
base::expected<std::vector<OrchardInput>, std::string> CalculateWitness( | ||
std::vector<OrchardInput> notes, | ||
uint32_t checkpoint_position); | ||
bool Truncate(uint32_t checkpoint); | ||
base::expected<bool, std::string> VerifyCheckpoint(); | ||
|
||
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); | ||
|
||
private: | ||
std::unique_ptr<::brave_wallet::orchard::OrchardShardTree> | ||
orchard_shard_tree_; | ||
}; | ||
|
||
} // namespace brave_wallet | ||
|
||
#endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_INTERNAL_ORCHARD_SHARD_TREE_MANAGER_H_ |
Oops, something went wrong.