Skip to content

Commit

Permalink
Move NamespaceTable to table.rs and change the visibility of the stru…
Browse files Browse the repository at this point in the history
…cts/fields.
  • Loading branch information
philippecamacho committed Feb 6, 2024
1 parent 976e2f5 commit dbf68c9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion sequencer/src/block2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod tables;
pub mod tx_iterator;

use crate::block2::entry::TxTableEntryWord;
use crate::block2::payload::NameSpaceTable;
use crate::block2::tables::NameSpaceTable;
use payload::Payload;

impl BlockPayload for Payload<TxTableEntryWord> {
Expand Down
18 changes: 5 additions & 13 deletions sequencer/src/block2/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use num_traits::PrimInt;
use serde::{Deserialize, Serialize};
use snafu::OptionExt;
use std::default::Default;
use std::marker::PhantomData;
use std::sync::OnceLock;
use std::{collections::HashMap, fmt::Display, ops::Range};

use crate::block2::tables::NameSpaceTable;
use trait_set::trait_set;

trait_set! {
Expand Down Expand Up @@ -59,23 +59,15 @@ pub(super) struct NamespaceInfo {
pub(crate) tx_table_len: TxTableEntry,
}

#[derive(Clone, Debug, Derivative, Deserialize, Eq, Serialize, Default)]
#[derivative(Hash, PartialEq)]
// TODO store only a reference to raw_payload.
pub struct NameSpaceTable<TableWord: TableWordTraits> {
pub(crate) raw_payload: Vec<u8>,
pub phantom: PhantomData<TableWord>,
}

#[allow(dead_code)] // TODO temporary
#[derive(Clone, Debug, Derivative, Deserialize, Eq, Serialize)]
#[derivative(Hash, PartialEq)]
pub struct Payload<TableWord: TableWordTraits> {
pub(super) struct Payload<TableWord: TableWordTraits> {
// Sequence of bytes representing the concatenated payloads for each namespace
pub(super) raw_payload: Vec<u8>,

// Sequence of bytes representing the namespace table
pub ns_table: NameSpaceTable<TableWord>,
pub(super) ns_table: NameSpaceTable<TableWord>,

// cache frequently used items
//
Expand Down Expand Up @@ -868,8 +860,8 @@ mod test {

mod helpers {
use crate::block2::entry::TxTableEntry;
use crate::block2::payload::{NameSpaceTable, TableWordTraits};
use crate::block2::tables::{Table, TxTableTest};
use crate::block2::payload::TableWordTraits;
use crate::block2::tables::{NameSpaceTable, Table, TxTableTest};
use crate::VmId;
use rand::RngCore;

Expand Down
4 changes: 2 additions & 2 deletions sequencer/src/block2/queryable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::block2::entry::TxTableEntryWord;
use crate::block2::payload::{test_vid_factory, NameSpaceTable, Payload, RangeProof};
use crate::block2::tables::TxTable;
use crate::block2::payload::{test_vid_factory, Payload, RangeProof};
use crate::block2::tables::{NameSpaceTable, TxTable};
use hotshot_query_service::availability::QueryablePayload;
use jf_primitives::vid::payload_prover::{PayloadProver, Statement};
use serde::{Deserialize, Serialize};
Expand Down
12 changes: 11 additions & 1 deletion sequencer/src/block2/tables.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::block2::entry::TxTableEntry;
use crate::block2::payload::{NameSpaceTable, Payload, TableWordTraits};
use crate::block2::payload::{Payload, TableWordTraits};
use crate::{BlockBuildingSnafu, Error, VmId};
use derivative::Derivative;
use serde::{Deserialize, Serialize};
use snafu::OptionExt;
use std::marker::PhantomData;
use std::mem::size_of;
Expand Down Expand Up @@ -40,6 +42,14 @@ impl<TableWord: TableWordTraits> Table<TableWord> for NameSpaceTable<TableWord>
}
}

#[derive(Clone, Debug, Derivative, Deserialize, Eq, Serialize, Default)]
#[derivative(Hash, PartialEq)]
// TODO store only a reference to raw_payload.
pub(super) struct NameSpaceTable<TableWord: TableWordTraits> {
pub(super) raw_payload: Vec<u8>,
pub(super) phantom: PhantomData<TableWord>,
}

impl<TableWord: TableWordTraits> NameSpaceTable<TableWord> {
pub fn from_vec(v: Vec<u8>) -> Self {
Self {
Expand Down
9 changes: 6 additions & 3 deletions sequencer/src/block2/tx_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::Range;

use crate::block2::payload::{NameSpaceTable, Payload, TableWordTraits};
use crate::block2::tables::TxTable;
use crate::block2::payload::{Payload, TableWordTraits};
use crate::block2::tables::{NameSpaceTable, TxTable};
use serde::{Deserialize, Serialize};

/// TODO do we really need `PartialOrd`, `Ord` here?
Expand All @@ -21,7 +21,10 @@ pub struct TxIterator<'a, TableWord: TableWordTraits> {
}

impl<'a, TableWord: TableWordTraits> TxIterator<'a, TableWord> {
pub fn new(ns_table: NameSpaceTable<TableWord>, block_payload: &'a Payload<TableWord>) -> Self {
pub(super) fn new(
ns_table: NameSpaceTable<TableWord>,
block_payload: &'a Payload<TableWord>,
) -> Self {
Self {
ns_idx: 0, // arbitrary value, changed in first call to next()
ns_iter: 0..ns_table.len(),
Expand Down

0 comments on commit dbf68c9

Please sign in to comment.