Skip to content

Commit

Permalink
Remove id from txn
Browse files Browse the repository at this point in the history
  • Loading branch information
shenkeyao committed Sep 18, 2023
1 parent e11b70e commit 562178a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
44 changes: 16 additions & 28 deletions crates/hotshot/src/block_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::{
collections::HashSet,
fmt::{Debug, Display},
ops::Deref,
};

use commit::{Commitment, Committable};
Expand All @@ -12,30 +11,17 @@ use snafu::Snafu;

/// The transaction in a [`VIDBlockPayload`].
#[derive(PartialEq, Eq, Hash, Serialize, Deserialize, Clone, Debug)]
pub struct VIDTransaction {
/// identifier for the transaction
pub id: u64,
/// padding to add to txn (to make it larger and thereby more realistic)
pub padding: Vec<u8>,
}

impl Deref for VIDTransaction {
type Target = u64;

fn deref(&self) -> &Self::Target {
&self.id
}
}
pub struct VIDTransaction(pub Vec<u8>);

impl Committable for VIDTransaction {
fn commit(&self) -> Commitment<Self> {
commit::RawCommitmentBuilder::new("SDemo Txn Comm")
.u64_field("id", self.id)
.finalize()
// TODO: Use use VID block commitment.
// <https://github.com/EspressoSystems/HotShot/issues/1730>
commit::RawCommitmentBuilder::new("Txn Comm").finalize()
}

fn tag() -> String {
"SEQUENCING_DEMO_TXN".to_string()
"SEQUENCING_TXN".to_string()
}
}

Expand All @@ -44,11 +30,14 @@ impl Transaction for VIDTransaction {}
impl VIDTransaction {
/// create a new transaction
#[must_use]
pub fn new(id: u64) -> Self {
Self {
id,
padding: vec![],
}
pub fn new() -> Self {
Self(Vec::new())
}
}

impl Default for VIDTransaction {
fn default() -> Self {
Self::new()
}
}

Expand All @@ -73,10 +62,9 @@ pub struct VIDBlockPayload(pub Vec<VIDTransaction>);

impl Committable for VIDBlockPayload {
fn commit(&self) -> Commitment<Self> {
let mut builder = commit::RawCommitmentBuilder::new("Normal Comm");
for txn in &self.0 {
builder = builder.u64_field("transaction", **txn);
}
// TODO: Use use VID block commitment.
// <https://github.com/EspressoSystems/HotShot/issues/1730>
let builder = commit::RawCommitmentBuilder::new("BlockPayload Comm");
builder.finalize()
}

Expand Down
7 changes: 2 additions & 5 deletions crates/hotshot/src/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,10 @@ impl State for SDemoState {
impl TestableState for SDemoState {
fn create_random_transaction(
_state: Option<&Self>,
rng: &mut dyn rand::RngCore,
_rng: &mut dyn rand::RngCore,
padding: u64,
) -> <Self::BlockType as BlockPayload>::Transaction {
VIDTransaction {
id: rng.gen_range(0..10),
padding: vec![0; padding as usize],
}
VIDTransaction(vec![0; padding as usize])
}
}
/// Implementation of [`NodeType`] for [`VDemoNode`]
Expand Down

0 comments on commit 562178a

Please sign in to comment.