espresso-sequencer icon indicating copy to clipboard operation
espresso-sequencer copied to clipboard

refactor: block and namespace logic

Open akonring opened this issue 1 year ago • 2 comments

tl;dr

  • Removes the generic parameter TableWord.
  • Removes the TxTableEntry and TxTableEntryWord.
  • Introduces a TableWord struct using const generics with an implementation that mimics the "old" TxTableEntry but makes room for other implementations of TableWord (Offset, TableLen, NsId).

Direction

This PR is a proposal for the direction of block/namespace logic:

  • Table interaction should be through appropriate methods on NamespaceTable and TxTable. Fx Payload should not deal with this. See comment: https://github.com/EspressoSystems/espresso-sequencer/blob/6dfaebf134dbcb47a485bc937ee756ef69bde0a8/sequencer/src/block/payload.rs#L55-L58

  • Different implementations of TableWord can support different words types (Offset, TableLen, NsId).
    Example Below:

pub trait Table {
    type TableLenWord: TableLenTraits;
    type NsIdWord: NsIdTraits;
    fn get_table_len(&self, offset: usize) -> TableLenWord;
    ...
} 


pub struct NameSpaceTable {
    pub(super) bytes: Vec<u8>,
}
impl Table for NameSpaceTable {
    // the word of table length is 4 bytes and is represented as u32
    type TableLenWord = TableWord<u32, 4>;
    type NsIdWord = TableWord<u64, 8>;
    ...

akonring avatar Feb 27 '24 10:02 akonring

This this PR looks like a step in the right direction. If we can achieve to implement the example shown above (see "Different implementations of TableWord can support different words types (Offset, TableLen, NsId). Example Below:") it feels to me that we would have achieved our goal of abstracting the complexity of dealing with table words.

philippecamacho avatar Feb 29 '24 14:02 philippecamacho

Just had a call with Anders to discuss plans.

ggutoski avatar Feb 29 '24 21:02 ggutoski