LeafValueEncoder

Trait LeafValueEncoder 

Source
pub trait LeafValueEncoder {
    type Value;
    type DeferredEncoder: DeferredValueEncoder;

    // Required method
    fn deferred_encoder(
        &self,
        key: B256,
        value: Self::Value,
    ) -> Self::DeferredEncoder;
}
Expand description

A trait for RLP-encoding values for proof calculation. This trait is designed to allow the lazy computation of leaf values in a generic way.

When calculating a leaf value in a storage trie the DeferredValueEncoder simply holds onto the slot value, and the encode method synchronously RLP-encodes it.

When calculating a leaf value in the accounts trie we create a DeferredValueEncoder to initiate any asynchronous computation of the account’s storage root we want to do. Later we call DeferredValueEncoder::encode to obtain the result of that computation and RLP-encode it.

Required Associated Types§

Source

type Value

The type of value being encoded (e.g., U256 for storage, Account for accounts).

Source

type DeferredEncoder: DeferredValueEncoder

The type that will compute and encode the value when needed.

Required Methods§

Source

fn deferred_encoder( &self, key: B256, value: Self::Value, ) -> Self::DeferredEncoder

Returns an encoder that will RLP-encode the value when its encode method is called.

§Arguments
  • key - The key the value was stored at in the DB
  • value - The value to encode

The returned deferred encoder will be called as late as possible in the algorithm to maximize the time available for parallel computation (e.g., storage root calculation).

Implementors§