Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a trait for calculation of exact encoded transaction #3800

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/example-types/src/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use committable::{Commitment, Committable, RawCommitmentBuilder};
use hotshot_types::{
data::{BlockError, Leaf},
traits::{
block_contents::{BlockHeader, BuilderFee, EncodeBytes, TestableBlock, Transaction},
block_contents::{
BlockHeader, BuilderFee, BuilderTransaction, EncodeBytes, TestableBlock, Transaction,
},
node_implementation::NodeType,
BlockPayload, ValidatedState,
},
Expand Down Expand Up @@ -55,6 +57,13 @@ impl TryFrom<Vec<u8>> for TestTransaction {
}
}

impl BuilderTransaction for TestTransaction {
fn minimum_block_size(&self, additional_length_overhead: u64) -> u64 {
// the estimation on transaction size is the length of the transaction plus the additional overhead
self.0.len() as u64 + additional_length_overhead
}
}

impl TestTransaction {
/// Construct a new transaction
///
Expand Down
7 changes: 7 additions & 0 deletions crates/types/src/traits/block_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ pub trait Transaction:
{
}

/// Abstraction over the minimum block size for transaction submitted to the builder
pub trait BuilderTransaction {
/// The function to estimate transaction size
/// It takes in the transaction itself plus additional_length_overhead which includes transaction table header, transaction table entry etc.
fn minimum_block_size(&self, additional_length_overhead: u64) -> u64;
}

/// Abstraction over the full contents of a block
///
/// This trait encapsulates the behaviors that the transactions of a block must have in order to be
Expand Down
4 changes: 2 additions & 2 deletions crates/types/src/traits/node_implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use vbs::version::StaticVersionType;

use super::{
auction_results_provider::AuctionResultsProvider,
block_contents::{BlockHeader, TestableBlock, Transaction},
block_contents::{BlockHeader, BuilderTransaction, TestableBlock, Transaction},
network::{
AsyncGenerator, ConnectedNetwork, NetworkReliability, TestableNetworkingImplementation,
},
Expand Down Expand Up @@ -240,7 +240,7 @@ pub trait NodeType:
/// The transaction type that this hotshot setup is using.
///
/// This should be equal to `BlockPayload::Transaction`
type Transaction: Transaction;
type Transaction: Transaction + BuilderTransaction;

/// The instance-level state type that this hotshot setup is using.
type InstanceState: InstanceState;
Expand Down