From c9a6a7a7f17ccdadae538fa95e35bed099d4aab1 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Wed, 28 Feb 2024 16:24:15 +0000 Subject: [PATCH] add qa for lt hash --- accounts-db/src/accounts_hash.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/accounts-db/src/accounts_hash.rs b/accounts-db/src/accounts_hash.rs index fd4870bdf06795..d6bfd4947855fc 100644 --- a/accounts-db/src/accounts_hash.rs +++ b/accounts-db/src/accounts_hash.rs @@ -1248,6 +1248,27 @@ pub struct AccountHash(pub Hash); // This also ensures there are no padding bytes, which is required to safely implement Pod const _: () = assert!(std::mem::size_of::() == std::mem::size_of::()); +/// # Account Lattice Hash Q/A +/// +/// ## What's account Lattice hash? +/// It is a new way to compute accounts hash based on the Algebra struct Lattice +/// defined on hash field. The field elements are 2048 bytes of hash of +/// individual accounts. This 2048 bytes of hash is computed from blake3 hash. +/// There are two operator defined on the field, add/sub, which are u16 x 1024 +/// wrapping add and subtract. +/// +/// ## How is the account Lattice hash used? +/// It is used to represent the account state for each slot. Each slot will +/// "add" in the new state of changed accounts and "sub" the old state of the +/// account. This way the accumulated hash of the slot is equal to sum all the +/// accounts state at that slot. The end goal is to replace the current merkle +/// tree hash. +/// +/// ## How to handle account deletion and account creation? +/// That's where the identity element in the lattice play it role. All accounts +/// with zero lamport are treated to have the "identity" hash. add/sub such +/// element don't impact the accumulated hash. +/// /// Lattice hash pub const LT_HASH_BYTES: usize = 2048; pub const LT_HASH_ELEMENT: usize = 1024;