Skip to content

Commit

Permalink
update hotshot query service to tag 0.1.63 (SQLX) (#2169)
Browse files Browse the repository at this point in the history
This PR:
updates hotshot query service to tag 0.1.63 which introduces replaces
tokio-postgres with SQLX
  • Loading branch information
imabdulbasit authored Oct 12, 2024
2 parents b70b7bd + da740dc commit 2918e14
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 127 deletions.
38 changes: 11 additions & 27 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ hotshot-builder-core = { git = "https://github.com/EspressoSystems/marketplace-b
marketplace-builder-core = { git = "https://github.com/EspressoSystems/marketplace-builder-core", tag = "0.1.51" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.49" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.77" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", tag = "0.1.62" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", tag = "0.1.63" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.77" }
hotshot-state-prover = { version = "0.1.0", path = "hotshot-state-prover" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.77" }
Expand Down Expand Up @@ -115,7 +115,7 @@ libp2p = { version = "0.53", default-features = false }
log-panics = { version = "2.0", features = ["with-backtrace"] }
strum = { version = "0.26", features = ["derive"] }
surf-disco = "0.9"
sqlx = { version = "^0.8", features = ["postgres", "macros"] }
sqlx = "0.8"
tagged-base64 = "0.4"
tide-disco = "0.9.3"
thiserror = "1.0.61"
Expand Down
7 changes: 7 additions & 0 deletions sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ serde = { workspace = true }
serde_json = { workspace = true }
sha2 = "0.10" # TODO temporary, used only for VID, should be set in hotshot
snafu = "0.8"
sqlx = { workspace = true, features = [
"bit-vec",
"postgres",
"runtime-async-std",
"sqlite",
"tls-native-tls",
] }
static_assertions = "1"
strum = { workspace = true }
surf-disco = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions sequencer/src/api/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use espresso_types::{NamespaceId, NsProof, PubKey, Transaction};
use futures::{try_join, FutureExt};
use hotshot_query_service::{
availability::{self, AvailabilityDataSource, CustomSnafu, FetchBlockSnafu},
data_source::storage::ExplorerStorage,
explorer::{self},
explorer::{self, ExplorerDataSource},
merklized_state::{
self, MerklizedState, MerklizedStateDataSource, MerklizedStateHeightPersistence,
},
Expand Down Expand Up @@ -129,7 +128,7 @@ pub(super) fn explorer<N, P, D, V: Versions>(
) -> Result<ExplorerApi<N, P, D, V, SequencerApiVersion>>
where
N: ConnectedNetwork<PubKey>,
D: ExplorerStorage<SeqTypes> + Send + Sync + 'static,
D: ExplorerDataSource<SeqTypes> + Send + Sync + 'static,
P: SequencerPersistence,
{
let api = explorer::define_api::<AvailState<N, P, D, V>, SeqTypes, _>(
Expand Down
35 changes: 15 additions & 20 deletions sequencer/src/api/sql.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use anyhow::{bail, Context};
use async_trait::async_trait;
use committable::Commitment;

use espresso_types::{v0_3::ChainConfig, BlockMerkleTree, FeeAccountProof, FeeMerkleTree};
use ethers::prelude::Address;
use hotshot_query_service::data_source::storage::sql::Write;
use hotshot_query_service::{
data_source::{
sql::{Config, SqlDataSource, Transaction},
storage::SqlStorage,
storage::{sql::query_as, MerklizedStateStorage, SqlStorage},
VersionedDataSource,
},
merklized_state::{MerklizedStateDataSource, Snapshot},
merklized_state::Snapshot,
Resolvable,
};
use hotshot_types::data::ViewNumber;
Expand All @@ -20,10 +22,7 @@ use super::{
AccountQueryData, BlocksFrontier,
};
use crate::{
persistence::{
sql::{sql_param, Options},
ChainConfigPersistence,
},
persistence::{sql::Options, ChainConfigPersistence},
SeqTypes,
};

Expand Down Expand Up @@ -115,19 +114,15 @@ impl CatchupDataSource for SqlStorage {
&self,
commitment: Commitment<ChainConfig>,
) -> anyhow::Result<ChainConfig> {
let query = self
.read()
.await
.context(format!(
"opening transaction to fetch chain config {commitment}"
))?
.query_one(
"SELECT * from chain_config where commitment = $1",
[&commitment.to_string()],
)
.await?;
let mut tx = self.read().await.context(format!(
"opening transaction to fetch chain config {commitment}"
))?;

let data: Vec<u8> = query.try_get("data")?;
let (data,) = query_as::<(Vec<u8>,)>("SELECT * from chain_config where commitment = $1")
.bind(commitment.to_string())
.fetch_one(tx.as_mut())
.await
.unwrap();

bincode::deserialize(&data[..]).context("failed to deserialize")
}
Expand All @@ -149,15 +144,15 @@ impl CatchupDataSource for DataSource {
}

#[async_trait]
impl<'a> ChainConfigPersistence for Transaction<'a> {
impl ChainConfigPersistence for Transaction<Write> {
async fn insert_chain_config(&mut self, chain_config: ChainConfig) -> anyhow::Result<()> {
let commitment = chain_config.commitment();
let data = bincode::serialize(&chain_config)?;
self.upsert(
"chain_config",
["commitment", "data"],
["commitment"],
[[sql_param(&(commitment.to_string())), sql_param(&data)]],
[(commitment.to_string(), data)],
)
.await
.map_err(Into::into)
Expand Down
Loading

0 comments on commit 2918e14

Please sign in to comment.