diff --git a/Cargo.lock b/Cargo.lock index 290a1455..9573292f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3072,7 +3072,7 @@ dependencies = [ [[package]] name = "hotshot" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "anyhow", "async-broadcast", @@ -3117,7 +3117,7 @@ dependencies = [ [[package]] name = "hotshot-builder-api" version = "0.1.7" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "async-trait", "clap", @@ -3163,7 +3163,7 @@ dependencies = [ [[package]] name = "hotshot-events-service" version = "0.1.15" -source = "git+https://github.com/EspressoSystems/hotshot-events-service.git?tag=0.1.16#dc8d019f7f487ad2bbb87cc934498d0abfc4af13" +source = "git+https://github.com/EspressoSystems/hotshot-events-service.git?branch=nfy/builder-batched-txn-submit#4b3882665253c49a5567f1c29cb6b4159ca174b0" dependencies = [ "async-broadcast", "async-compatibility-layer", @@ -3188,7 +3188,7 @@ dependencies = [ [[package]] name = "hotshot-example-types" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "anyhow", "async-broadcast", @@ -3218,7 +3218,7 @@ dependencies = [ [[package]] name = "hotshot-orchestrator" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "anyhow", "async-compatibility-layer", @@ -3247,7 +3247,7 @@ dependencies = [ [[package]] name = "hotshot-task" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "async-broadcast", "async-compatibility-layer", @@ -3260,7 +3260,7 @@ dependencies = [ [[package]] name = "hotshot-task-impls" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "anyhow", "async-broadcast", @@ -3293,7 +3293,7 @@ dependencies = [ [[package]] name = "hotshot-types" version = "0.1.11" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "anyhow", "ark-bls12-381", @@ -3345,7 +3345,7 @@ dependencies = [ [[package]] name = "hotshot-web-server" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "async-compatibility-layer", "async-lock 2.8.0", @@ -4416,7 +4416,7 @@ dependencies = [ [[package]] name = "libp2p-networking" version = "0.5.43" -source = "git+https://github.com/EspressoSystems/HotShot.git?tag=0.5.46#f02711daca9ce18ecc86443fa054cafff76464f0" +source = "git+https://github.com/EspressoSystems/HotShot.git?branch=nfy/builder-batched-txn-submit#132c2b64fc6fc555cd54e1647840e7e89d66ed82" dependencies = [ "anyhow", "async-compatibility-layer", diff --git a/Cargo.toml b/Cargo.toml index 9dbad64d..1198c12e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,10 @@ async-trait = "0.1" clap = { version = "4.4", features = ["derive", "env"] } committable = "0.2" futures = "0.3" -hotshot = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.46" } -hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.46" } -hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.16" } -hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.46" } +hotshot = { git = "https://github.com/EspressoSystems/HotShot.git", branch = "nfy/builder-batched-txn-submit" } +hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", branch = "nfy/builder-batched-txn-submit" } +hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", branch = "nfy/builder-batched-txn-submit" } +hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", branch = "nfy/builder-batched-txn-submit" } serde = { version = "1.0", features = ["derive"] } sha2 = "0.10" snafu = "0.8" @@ -29,4 +29,4 @@ tracing = "0.1" vbs = "0.1" [dev-dependencies] -hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.46" } +hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", branch = "nfy/builder-batched-txn-submit" } diff --git a/src/service.rs b/src/service.rs index 81e61fbf..575e530a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -43,13 +43,10 @@ use hotshot_events_service::{ events_source::{BuilderEvent, BuilderEventType}, }; use sha2::{Digest, Sha256}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::num::NonZeroUsize; use std::sync::Arc; use std::time::Duration; -use std::{ - collections::{BTreeMap, HashMap, HashSet}, - ops::Deref, -}; use std::{fmt::Display, time::Instant}; use tagged_base64::TaggedBase64; use tide_disco::method::ReadState; @@ -206,21 +203,22 @@ impl GlobalState { // private mempool submit txn // Currently, we don't differentiate between the transactions from the hotshot and the private mempool - pub async fn submit_client_txn( + pub async fn submit_client_txns( &self, - txn: ::Transaction, - ) -> Result::Transaction>, BuildError> { + txns: Vec<::Transaction>, + ) -> Result::Transaction>>, BuildError> { + let results = txns.iter().map(|tx| tx.commit()).collect(); let tx_msg = TransactionMessage:: { - txns: vec![txn.clone()], + txns, tx_type: TransactionSource::External, }; self.tx_sender .broadcast(MessageType::TransactionMessage(tx_msg)) .await - .map(|_a| txn.commit()) + .map(|_a| results) .map_err(|_e| BuildError::Error { - message: "failed to send txn".to_string(), + message: "failed to send txns".to_string(), }) } } @@ -529,18 +527,19 @@ where Ok(self.builder_keys.0.clone()) } } + #[async_trait] impl AcceptsTxnSubmits for ProxyGlobalState { - async fn submit_txn( - &mut self, - txn: ::Transaction, + async fn submit_txns( + &self, + txns: Vec<::Transaction>, ) -> Result<(), BuildError> { - tracing::debug!("Submitting transaction to the builder states{:?}", txn); + tracing::debug!("Submitting transaction to the builder states{:?}", txns); let response = self .global_state .read_arc() .await - .submit_client_txn(txn) + .submit_client_txns(txns) .await; tracing::info!( @@ -557,15 +556,16 @@ impl AcceptsTxnSubmits for ProxyGlobalState { Ok(()) } } + #[async_trait] impl ReadState for ProxyGlobalState { - type State = GlobalState; + type State = ProxyGlobalState; async fn read( &self, op: impl Send + for<'a> FnOnce(&'a Self::State) -> BoxFuture<'a, T> + 'async_trait, ) -> T { - op(self.global_state.read_arc().await.deref()).await + op(self).await } }