Skip to content

Commit

Permalink
Use consensus storage as fetching provider when running query service
Browse files Browse the repository at this point in the history
  • Loading branch information
jbearer committed Nov 4, 2024
1 parent c80c873 commit 01e44f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions sequencer/src/api/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Context};
use async_std::sync::Arc;
use clap::Parser;
use espresso_types::{
v0::traits::{EventConsumer, NullEventConsumer, SequencerPersistence},
v0::traits::{EventConsumer, NullEventConsumer, PersistenceOptions, SequencerPersistence},
BlockMerkleTree, FeeMerkleTree, PubKey,
};
use futures::{
Expand All @@ -14,6 +14,7 @@ use futures::{
use hotshot_events_service::events::Error as EventStreamingError;
use hotshot_query_service::{
data_source::{ExtensibleDataSource, MetricsDataSource},
fetching::provider::QueryServiceProvider,
status::{self, UpdateStatusData},
ApiState as AppState, Error,
};
Expand All @@ -27,7 +28,7 @@ use vbs::version::StaticVersionType;

use super::{
data_source::{
provider, CatchupDataSource, HotShotConfigDataSource, NodeStateDataSource,
provider, CatchupDataSource, HotShotConfigDataSource, NodeStateDataSource, Provider,
SequencerDataSource, StateSignatureDataSource, SubmitDataSource,
},
endpoints, fs, sql,
Expand Down Expand Up @@ -333,12 +334,18 @@ impl Options {
N: ConnectedNetwork<PubKey>,
P: SequencerPersistence,
{
let ds = sql::DataSource::create(
mod_opt.clone(),
provider::<V>(query_opt.peers.clone(), bind_version),
false,
)
.await?;
let mut provider = Provider::default();

// Use the database itself as a fetching provider: sometimes we can fetch data that is
// missing from the query service from ephemeral consensus storage.
provider = provider.with_provider(mod_opt.clone().create().await?);
// If that fails, fetch missing data from peers.
for peer in query_opt.peers {
tracing::info!("will fetch missing data from {peer}");
provider = provider.with_provider(QueryServiceProvider::new(peer, bind_version));
}

let ds = sql::DataSource::create(mod_opt.clone(), provider, false).await?;
let (metrics, ds, mut app) = self
.init_app_modules(ds, state.clone(), bind_version)
.await?;
Expand Down
1 change: 1 addition & 0 deletions sequencer/src/persistence/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ impl PersistenceOptions for Options {
}

/// Postgres-backed persistence.
#[derive(Debug)]
pub struct Persistence {
db: SqlStorage,
store_undecided_state: bool,
Expand Down

0 comments on commit 01e44f7

Please sign in to comment.