FuelLabs / fuel-merkle

Fuel Merkle trees in Rust.
Apache License 2.0
7 stars 5 forks source link

`ParentNode` and `PathIter` must operate on `Result` #132

Closed bvrooman closed 1 year ago

bvrooman commented 1 year ago

Currently, ParentNode is defined by:

pub trait ParentNode: Node {
    fn left_child(&self) -> Self;
    fn right_child(&self) -> Self;
}

However, implementations may not be able to guarantee the presence of a left or right child, or the infallibility of the get operations. Right now, implementations of ParentNode assume that the operation is guaranteed to succeed, and use unwraps. In the case of database-backed storage nodes, the operations may fail for various reasons, including data corruption or connection failures. Therefore, the trait functions should return Result<Option<Self>> instead.

pub trait ParentNode: Node {
    fn left_child(&self) -> Result<Option<Self>>;
    fn right_child(&self) -> Result<Option<Self>>;
}

Because ParentNode is used in the PathIter, PathIter will have to be refactored to accommodate the modified interface. This means using Item = (Result<Option<T>>, Result<Option<T>>).