Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Fixing builder core for read only access to ProxyGlobalState
Browse files Browse the repository at this point in the history
  • Loading branch information
nyospe committed Apr 30, 2024
1 parent 1656287 commit c873ec8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }
34 changes: 17 additions & 17 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,21 +203,22 @@ impl<Types: NodeType> GlobalState<Types> {

// 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: <Types as NodeType>::Transaction,
) -> Result<Commitment<<Types as NodeType>::Transaction>, BuildError> {
txns: Vec<<Types as NodeType>::Transaction>,
) -> Result<Vec<Commitment<<Types as NodeType>::Transaction>>, BuildError> {
let results = txns.iter().map(|tx| tx.commit()).collect();
let tx_msg = TransactionMessage::<Types> {
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(),
})
}
}
Expand Down Expand Up @@ -529,18 +527,19 @@ where
Ok(self.builder_keys.0.clone())
}
}

#[async_trait]
impl<Types: NodeType> AcceptsTxnSubmits<Types> for ProxyGlobalState<Types> {
async fn submit_txn(
&mut self,
txn: <Types as NodeType>::Transaction,
async fn submit_txns(
&self,
txns: Vec<<Types as NodeType>::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!(
Expand All @@ -557,15 +556,16 @@ impl<Types: NodeType> AcceptsTxnSubmits<Types> for ProxyGlobalState<Types> {
Ok(())
}
}

#[async_trait]
impl<Types: NodeType> ReadState for ProxyGlobalState<Types> {
type State = GlobalState<Types>;
type State = ProxyGlobalState<Types>;

async fn read<T>(
&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
}
}

Expand Down

0 comments on commit c873ec8

Please sign in to comment.