INNER CODE UNIT · Rust
push_peak
risc0/risc0-ethereum · crates/aggregation/src/lib.rs:211
fn push_peak(&mut self, new_peak: Peak) -> Result<(), Error> {
// If the peak has a max-depth of 255, then the mountain range is finalized and no new
// peaks can be pushed to it. Note that this state can only be achieved by calling
// `finalize` since it is computationally infeasible to push 2^256 nodes onto the MMR,
// although it is theoretically consistent that if an MMR reached a state of being a
// single peak with max depth value of 255, it would be naturally finalized.
if self.is_finalized() {
return Err(Error::FinalizedError);
}
match self.0.last() {
// If the MerkleMountainRange is empty, push the new peak.
None => self.0.push(new_peak),
// If the tail subtree is larger, push the new subtree onto the end.
Some(peak) if peak.max_depth > new_peak.max_depth => {
self.0.push(new_peak);
}
// If the tail subtree is the same size, combine them and recurse.
Some(peak) if peak.max_depth == new_peak.max_depth => {