Skip to content
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

chore: Use MerkleRootCalculator when only BMT root is needed #612

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- [#612](https://github.com/FuelLabs/fuel-vm/pull/612): Reduced the memory consumption in all places where we calculate BMT root.

#### Breaking

- [#609](https://github.com/FuelLabs/fuel-vm/pull/609): Checked transactions (`Create`, `Script`, and `Mint`) now enforce a maximum size. The maximum size is specified by `MAX_TRANSACTION_SIZE` in the transaction parameters, under consensus parameters. Checking a transaction above this size raises `CheckError::TransactionSizeLimitExceeded`.
Expand Down
2 changes: 1 addition & 1 deletion fuel-tx/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use derivative::Derivative;
use fuel_crypto::Hasher;
use fuel_merkle::{
binary::in_memory::MerkleTree as BinaryMerkleTree,
binary::root_calculator::MerkleRootCalculator as BinaryMerkleTree,
sparse::{
in_memory::MerkleTree as SparseMerkleTree,
MerkleTreeKey,
Expand Down
2 changes: 1 addition & 1 deletion fuel-vm/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Crypto implementations for the instructions

use fuel_merkle::binary::in_memory::MerkleTree;
use fuel_merkle::binary::root_calculator::MerkleRootCalculator as MerkleTree;
use fuel_types::Bytes32;

/// Calculate a binary merkle root with in-memory storage
Expand Down
10 changes: 5 additions & 5 deletions fuel-vm/src/interpreter/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
ops::Index,
};

use fuel_merkle::binary;
use fuel_merkle::binary::root_calculator::MerkleRootCalculator as MerkleTree;
use fuel_tx::Receipt;
use fuel_types::{
canonical::Serialize,
Expand All @@ -14,7 +14,7 @@ use fuel_types::{
#[derive(Debug, Default, Clone)]
pub(crate) struct ReceiptsCtx {
receipts: Vec<Receipt>,
receipts_tree: binary::in_memory::MerkleTree,
receipts_tree: MerkleTree,
}

impl ReceiptsCtx {
Expand All @@ -24,7 +24,7 @@ impl ReceiptsCtx {
}

pub fn clear(&mut self) {
self.receipts_tree.reset();
self.receipts_tree = MerkleTree::new();
self.receipts.clear();
}

Expand All @@ -33,7 +33,7 @@ impl ReceiptsCtx {
}

pub fn root(&self) -> Bytes32 {
self.receipts_tree.root().into()
self.receipts_tree.clone().root().into()
}

/// Get a mutable lock on this context
Expand All @@ -44,7 +44,7 @@ impl ReceiptsCtx {
/// Recalculates the Merkle root of the receipts from scratch. This should
/// only be used when the list of receipts has been mutated externally.
fn recalculate_root(&mut self) {
self.receipts_tree.reset();
self.receipts_tree = MerkleTree::new();
// TODO: Remove `clone()` when `to_bytes()` no longer requires `&mut self`
let receipts = self.as_ref().clone();
for receipt in receipts {
Expand Down
Loading