Returns the RLP payload length of the [`TrieNode`].
(&self)
| 470 | |
| 471 | /// Returns the RLP payload length of the [`TrieNode`]. |
| 472 | pub(crate) fn payload_length(&self) -> usize { |
| 473 | match self { |
| 474 | Self::Empty => 0, |
| 475 | Self::Blinded { commitment } => commitment.len(), |
| 476 | Self::Leaf { prefix, value } => { |
| 477 | let mut encoded_key_len = prefix.len() / 2 + 1; |
| 478 | if encoded_key_len != 1 { |
| 479 | encoded_key_len += length_of_length(encoded_key_len); |
| 480 | } |
| 481 | encoded_key_len + value.length() |
| 482 | } |
| 483 | Self::Extension { prefix, node } => { |
| 484 | let mut encoded_key_len = prefix.len() / 2 + 1; |
| 485 | if encoded_key_len != 1 { |
| 486 | encoded_key_len += length_of_length(encoded_key_len); |
| 487 | } |
| 488 | encoded_key_len + node.blinded_length() |
| 489 | } |
| 490 | Self::Branch { stack } => { |
| 491 | // In branch nodes, if an element is longer than an encoded 32 byte string, it is |
| 492 | // blinded. Assuming we have an open trie node, we must re-hash the |
| 493 | // elements that are longer than an encoded 32 byte string |
| 494 | // in length. |
| 495 | stack.iter().fold(0, |mut acc, node| { |
| 496 | acc += node.blinded_length(); |
| 497 | acc |
| 498 | }) |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /// Returns the encoded length of the trie node, blinding it if it is longer than an encoded |
| 504 | /// [B256] string in length. |