Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ag/refactor-legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinI committed Nov 27, 2024
2 parents 9ed8fab + da10d18 commit 6c5aeb8
Show file tree
Hide file tree
Showing 11 changed files with 2,051 additions and 183 deletions.
417 changes: 297 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ resolver = "2"
members = ["crates/*"]

[workspace.dependencies]
hotshot = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.54" }
hotshot-macros = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot-task-impls = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot-testing = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.81" }
hotshot = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", branch = "sishan/tx_status_api" }
hotshot-macros = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }
hotshot-task-impls = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }
hotshot-testing = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }
hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }
hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", rev = "f62b557" }

anyhow = "1"
async-broadcast = "0.7"
Expand All @@ -31,6 +31,7 @@ nonempty-collections = "0.2"
once_cell = "1.20"
num_cpus = "1.16"
portpicker = "0.1.1"
quick_cache = "0.6"
rand = "0.8"
serde = "1.0"
serde_json = "1.0"
Expand All @@ -45,7 +46,7 @@ toml = "0.8"
tracing = "0.1"
tracing-test = "0.1"
typenum = "1.17"
url = "2.3"
url = "2.5"
vbs = "0.1"
vec1 = "1.12"
tracing-subscriber = "0.3"
Expand Down
36 changes: 31 additions & 5 deletions crates/legacy/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use hotshot::types::Event;
use hotshot_builder_api::v0_1::builder::{define_api, submit_api, Error as BuilderApiError};
use hotshot_builder_api::v0_1::{
block_info::{AvailableBlockData, AvailableBlockHeaderInput, AvailableBlockInfo},
builder::BuildError,
builder::{define_api, submit_api, BuildError, Error as BuilderApiError, TransactionStatus},
data_source::{AcceptsTxnSubmits, BuilderDataSource},
};
use hotshot_types::traits::block_contents::{precompute_vid_commitment, Transaction};
Expand Down Expand Up @@ -95,6 +94,8 @@ pub struct BuilderConfig<Types: NodeType> {
pub txn_garbage_collect_duration: Duration,
/// Channel capacity for incoming transactions for a single builder state.
pub txn_channel_capacity: usize,
/// Capacity of cache storing information for transaction status API
pub tx_status_cache_capacity: usize,
/// Base fee; the sequencing fee for a block is calculated as block size × base fee
pub base_fee: u64,
}
Expand All @@ -113,20 +114,30 @@ impl<Types: NodeType> BuilderConfig<Types> {
maximize_txn_capture_timeout: TEST_MAXIMIZE_TX_CAPTURE_TIMEOUT,
txn_garbage_collect_duration: TEST_INCLUDED_TX_GC_PERIOD,
txn_channel_capacity: TEST_CHANNEL_BUFFER_SIZE,
tx_status_cache_capacity: TEST_TX_STATUS_CACHE_CAPACITY,
base_fee: TEST_BASE_FEE,
}
}
}

pub struct GlobalState<Types: NodeType> {
/// Underlying coordinator, responsible for builder state lifecycle
pub(crate) coordinator: Arc<BuilderStateCoordinator<Types>>,
/// Keys that this builder will use to sign responses
pub(crate) builder_keys: BuilderKeys<Types>,
pub(crate) max_api_waiting_time: Duration,
/// Stores blocks built by this builder
pub(crate) block_store: RwLock<BlockStore<Types>>,
/// Limits on block size. See [`BlockSizeLimits`] documentation for more details.
pub(crate) block_size_limits: BlockSizeLimits,
pub(crate) maximize_txn_capture_timeout: Duration,
/// Number of DA nodes used in VID computation
pub(crate) num_nodes: AtomicUsize,
/// Instance state, used to construct new blocks
pub(crate) instance_state: Types::InstanceState,
/// See [`BuilderConfig::max_api_waiting_time`]
pub(crate) max_api_waiting_time: Duration,
/// See [`BuilderConfig::maximize_txn_capture_timeout`]
pub(crate) maximize_txn_capture_timeout: Duration,
/// See [`BuilderConfig::base_fee`]
pub(crate) base_fee: u64,
}

Expand All @@ -147,6 +158,7 @@ where
coordinator: Arc::new(BuilderStateCoordinator::new(
config.txn_channel_capacity,
config.txn_garbage_collect_duration,
config.tx_status_cache_capacity,
)),
block_store: RwLock::new(BlockStore::new()),
block_size_limits: BlockSizeLimits::new(
Expand Down Expand Up @@ -249,7 +261,14 @@ where
let max_tx_len = self.block_size_limits.max_block_size();
if len > max_tx_len {
tracing::warn!(%tx.commit, %len, %max_tx_len, "Transaction too big");
return Err(Error::TxTooBig { len, max_tx_len });
let error = Error::TxTooBig { len, max_tx_len };
self.coordinator.update_txn_status(
&tx.commit,
TransactionStatus::Rejected {
reason: error.to_string(),
},
);
return Err(error);
}
self.coordinator.handle_transaction(tx).await
}
Expand Down Expand Up @@ -775,6 +794,13 @@ where
.try_collect()
.await
}

async fn txn_status(
&self,
txn_hash: Commitment<<Types as NodeType>::Transaction>,
) -> Result<TransactionStatus, BuildError> {
Ok(self.coordinator.tx_status(&txn_hash))
}
}

#[async_trait]
Expand Down
12 changes: 12 additions & 0 deletions crates/legacy/src/testing/block_size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use async_broadcast::broadcast;
use committable::Committable;
use hotshot_builder_api::v0_1::builder::TransactionStatus;
use hotshot_example_types::block_types::TestTransaction;
use hotshot_example_types::state_types::TestInstanceState;
use hotshot_types::data::ViewNumber;
Expand Down Expand Up @@ -137,6 +139,7 @@ async fn huge_transactions() {

let almost_too_big = TestTransaction::new(vec![0u8; PROTOCOL_MAX_BLOCK_SIZE as usize]);
let too_big = TestTransaction::new(vec![0u8; PROTOCOL_MAX_BLOCK_SIZE as usize + 1]);
let too_big_commitment = too_big.commit();

test_service
.submit_transactions_private(vec![almost_too_big.clone(); N_BIG_TRANSACTIONS])
Expand All @@ -148,6 +151,15 @@ async fn huge_transactions() {
.await
.unwrap_err();

// Should also update the tx status
assert!(matches!(
test_service
.proxy_global_state
.coordinator
.tx_status(&too_big_commitment),
TransactionStatus::Rejected { .. }
));

// Builder shouldn't exceed the maximum block size, so transactions
// should be included one-by-one
assert_eq!(
Expand Down
Loading

0 comments on commit 6c5aeb8

Please sign in to comment.