Skip to content

Commit

Permalink
added trait Transaction to calc tx size
Browse files Browse the repository at this point in the history
  • Loading branch information
dailinsubjam committed Oct 25, 2024
1 parent fc7238e commit 8dc5943
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 46 deletions.
51 changes: 32 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,24 @@ dyn-clone = "1.0"
ethers = { version = "2.0", features = ["solc"] }
futures = "0.3"

hotshot = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
# Hotshot imports
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.78-patch4" }
hotshot-builder-core = { git = "https://github.com/EspressoSystems/marketplace-builder-core", tag = "0.1.53" }
marketplace-builder-core = { git = "https://github.com/EspressoSystems/marketplace-builder-core", tag = "0.1.53" }
marketplace-builder-shared = { git = "https://github.com/EspressoSystems/marketplace-builder-core", tag = "0.1.53" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.51" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", tag = "0.1.66" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", branch = "sishan/trait_builder_transaction" }
hotshot-builder-core = { git = "https://github.com/EspressoSystems/marketplace-builder-core", branch = "sishan/trait_builder_transaction" }
marketplace-builder-core = { git = "https://github.com/EspressoSystems/marketplace-builder-core", branch = "sishan/trait_builder_transaction" }
marketplace-builder-shared = { git = "https://github.com/EspressoSystems/marketplace-builder-core", branch = "sishan/trait_builder_transaction" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", branch = "sishan/trait_builder_transaction" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", branch = "sishan/trait_builder_transaction" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
hotshot-state-prover = { version = "0.1.0", path = "hotshot-state-prover" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot-testing = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
libp2p-networking = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
hotshot-testing = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
libp2p-networking = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }
hotshot-contract-adapter = { version = "0.1.0", path = "contracts/rust/adapter" }
# Temporary, used to pull in the mock auction results provider
hotshot-example-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.78-patch4" }
hotshot-example-types = { git = "https://github.com/EspressoSystems/hotshot", branch = "sishan/trait_builder_transaction" }

# Push CDN imports
cdn-broker = { git = "https://github.com/EspressoSystems/Push-CDN", features = [
Expand Down
6 changes: 3 additions & 3 deletions sequencer/src/block/full_payload/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl Payload {
let mut ns_builders = BTreeMap::<NamespaceId, NsPayloadBuilder>::new();
for tx in transactions.into_iter() {
// accounting for block byte length limit
block_byte_len += tx.payload().len() + NsPayloadBuilder::tx_table_entry_byte_len();
if !ns_builders.contains_key(&tx.namespace()) {
// each new namespace adds overhead
block_byte_len +=
NsTableBuilder::entry_byte_len() + NsPayloadBuilder::tx_table_header_byte_len();
block_byte_len += tx.minimum_block_size(true);
} else {
block_byte_len += tx.minimum_block_size(false);
}
if block_byte_len > max_block_byte_len {
tracing::warn!("transactions truncated to fit in maximum block byte length {max_block_byte_len}");
Expand Down
19 changes: 10 additions & 9 deletions types/src/v0/impls/block/full_payload/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use async_trait::async_trait;
use committable::Committable;
use hotshot_query_service::availability::QueryablePayload;
use hotshot_types::data::ViewNumber;
use hotshot_types::traits::block_contents::Transaction as HotShotTransaction;
use hotshot_types::{
traits::{BlockPayload, EncodeBytes},
utils::BuilderCommitment,
Expand All @@ -13,11 +14,12 @@ use jf_vid::VidScheme;
use sha2::Digest;
use thiserror::Error;

use crate::Transaction;
use crate::{
v0::impls::{NodeState, ValidatedState},
v0_1::ChainConfig,
Index, Iter, NamespaceId, NsIndex, NsPayload, NsPayloadBuilder, NsPayloadRange, NsTable,
NsTableBuilder, Payload, PayloadByteLen, SeqTypes, Transaction, TxProof,
NsTableBuilder, Payload, PayloadByteLen, SeqTypes, TxProof,
};

#[derive(serde::Deserialize, serde::Serialize, Error, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -79,23 +81,22 @@ impl Payload {
<Self as BlockPayload<SeqTypes>>::Error,
> {
// accounting for block byte length limit
let max_block_byte_len: usize = u64::from(chain_config.max_block_size)
.try_into()
.expect("too large max block size for architecture");
let mut block_byte_len = NsTableBuilder::header_byte_len();
let max_block_byte_len = u64::from(chain_config.max_block_size);
let mut block_byte_len = NsTableBuilder::header_byte_len() as u64;

// add each tx to its namespace
let mut ns_builders = BTreeMap::<NamespaceId, NsPayloadBuilder>::new();
for tx in transactions.into_iter() {
let mut tx_size = tx.payload().len() + NsPayloadBuilder::tx_table_entry_byte_len();
let mut tx_size = 0;
if !ns_builders.contains_key(&tx.namespace()) {
// each new namespace adds overhead
tx_size +=
NsTableBuilder::entry_byte_len() + NsPayloadBuilder::tx_table_header_byte_len();
tx_size += tx.minimum_block_size(true);
} else {
tx_size += tx.minimum_block_size(false);
}

if tx_size > max_block_byte_len {
// skip this transaction since it excceds the block size limit
// skip this transaction since it exceeds the block size limit
tracing::warn!(
"skip the transaction to fit in maximum block byte length {max_block_byte_len}, transaction size {tx_size}"
);
Expand Down
12 changes: 11 additions & 1 deletion types/src/v0/impls/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use serde::{de::Error, Deserialize, Deserializer};

use crate::{NamespaceId, Transaction};

use super::{NsPayloadBuilder, NsTableBuilder};

impl From<u32> for NamespaceId {
fn from(value: u32) -> Self {
Self(value as u64)
Expand Down Expand Up @@ -79,7 +81,15 @@ impl Transaction {
}
}

impl HotShotTransaction for Transaction {}
impl HotShotTransaction for Transaction {
fn minimum_block_size(&self, new_ns: bool) -> u64 {
let mut len = self.payload().len() + NsPayloadBuilder::tx_table_entry_byte_len();
if new_ns {
len += NsTableBuilder::entry_byte_len() + NsPayloadBuilder::tx_table_header_byte_len();
}
len as u64
}
}

impl Committable for Transaction {
fn commit(&self) -> Commitment<Self> {
Expand Down

0 comments on commit 8dc5943

Please sign in to comment.