-
Notifications
You must be signed in to change notification settings - Fork 160
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
Introduce MastForestStore
#1359
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a94d52d
Introduce `ExternalNode`
plafer f8ad339
Replace `Assembler.node_id_by_digest` map
plafer 06f421b
add TODOP
plafer bcf2a9b
Add `Host::get_mast_forest`
plafer 980713d
Move kernel and entrypoint out of `MastForest`
plafer d2bbcd2
Add Host::get_mast_forest
plafer 32e757e
Remove ProgramError
plafer f87217a
docs
plafer 71f35f1
cleanup Program constructors
plafer a39f74f
fix docs
plafer f7e98af
Make `Program.kernel` an `Arc`
plafer b5538c5
fix executable
plafer 2eab574
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer 188651b
invoke_mast_root: fix external node creation logic
plafer b15263c
add failing test
plafer a94a095
don't make root in `combine_mast_node_ids` and `compile_body`
plafer 7af0bfa
fix External docs
plafer a6fcf47
fmt
plafer c66db6f
fix `entrypoint` doc
plafer 572fc7e
Rename `Program::new_with_kernel()`
plafer 08ce2c7
Document `MastForestStore` and `MemMastForestStore`
plafer 50e01e9
fix syscall
plafer 071ab54
execute_* functions: use `MastForest`
plafer 49de40d
`Program`: Remove `Arc` around kernel
plafer c28c876
remove `Arc` around `MastForest` in `Program`
plafer 78b2b16
Return error on malformed host
plafer 4883b44
Simplify `DefaultHost`
plafer 155a798
`MastForest::add_node()`: add docs
plafer bc6d13e
fmt
plafer be24320
add failing `duplicate_procedure()` test
plafer 32aedd6
Introduce `MastForestBuilder`
plafer 088de82
Rename `mod tests` -> `testing`
plafer 9d48fda
add `duplicate_node()` test
plafer 6c62d9b
changelog
plafer 039bba0
Program: use `assert!()` instead of `debug_assert!()`
plafer 9c9e171
`MastForest::make_root()`: add assert
plafer 8e4dc5e
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer c34e985
fmt
plafer 25fe82f
fix exec invocation
plafer 36ecdd7
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer 3c26bd6
no else blk special case
plafer 34c2f7f
add procedure roots comment
plafer 97d3de8
Merge remote-tracking branch 'origin/next' into plafer-object-store
plafer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use core::ops::Index; | ||
|
||
use alloc::collections::BTreeMap; | ||
use vm_core::{ | ||
crypto::hash::RpoDigest, | ||
mast::{MastForest, MastNode, MastNodeId, MerkleTreeNode}, | ||
}; | ||
|
||
/// Builder for a [`MastForest`]. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct MastForestBuilder { | ||
mast_forest: MastForest, | ||
node_id_by_hash: BTreeMap<RpoDigest, MastNodeId>, | ||
} | ||
|
||
impl MastForestBuilder { | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
pub fn build(self) -> MastForest { | ||
self.mast_forest | ||
} | ||
} | ||
|
||
/// Accessors | ||
impl MastForestBuilder { | ||
/// Returns the underlying [`MastForest`] being built | ||
pub fn forest(&self) -> &MastForest { | ||
&self.mast_forest | ||
} | ||
|
||
/// Returns the [`MastNodeId`] of the procedure associated with a given digest, if any. | ||
#[inline(always)] | ||
pub fn find_procedure_root(&self, digest: RpoDigest) -> Option<MastNodeId> { | ||
self.mast_forest.find_procedure_root(digest) | ||
} | ||
} | ||
|
||
/// Mutators | ||
impl MastForestBuilder { | ||
/// Adds a node to the forest, and returns the [`MastNodeId`] associated with it. | ||
/// | ||
/// If a [`MastNode`] which is equal to the current node was previously added, the previously | ||
/// returned [`MastNodeId`] will be returned. This enforces this invariant that equal | ||
/// [`MastNode`]s have equal [`MastNodeId`]s. | ||
pub fn ensure_node(&mut self, node: MastNode) -> MastNodeId { | ||
let node_digest = node.digest(); | ||
|
||
if let Some(node_id) = self.node_id_by_hash.get(&node_digest) { | ||
// node already exists in the forest; return previously assigned id | ||
*node_id | ||
} else { | ||
let new_node_id = self.mast_forest.add_node(node); | ||
self.node_id_by_hash.insert(node_digest, new_node_id); | ||
|
||
new_node_id | ||
} | ||
} | ||
|
||
/// Marks the given [`MastNodeId`] as being the root of a procedure. | ||
pub fn make_root(&mut self, new_root_id: MastNodeId) { | ||
self.mast_forest.make_root(new_root_id) | ||
} | ||
} | ||
|
||
impl Index<MastNodeId> for MastForestBuilder { | ||
type Output = MastNode; | ||
|
||
#[inline(always)] | ||
fn index(&self, node_id: MastNodeId) -> &Self::Output { | ||
&self.mast_forest[node_id] | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm confused how we have ended up back here again -
exec
andcall
are identical in every respect, with the sole exception of their execution context semantics. Why are we treatingexec
differently thancall
here?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.
As discussed offline, this was updated to act similarly to call: 25fe82f