Skip to content

Commit

Permalink
rename ver to apiver
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Aug 21, 2024
1 parent 0a830c4 commit fbc19ba
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 80 deletions.
33 changes: 17 additions & 16 deletions hotshot-state-prover/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ pub fn load_proving_key(stake_table_capacity: usize) -> ProvingKey {
pk
}

pub async fn fetch_latest_state<Ver: StaticVersionType>(
client: &Client<ServerError, Ver>,
pub async fn fetch_latest_state<ApiVer: StaticVersionType>(
client: &Client<ServerError, ApiVer>,
) -> Result<StateSignaturesBundle, ServerError> {
tracing::info!("Fetching the latest state signatures bundle from relay server.");
client
Expand Down Expand Up @@ -307,10 +307,10 @@ pub async fn submit_state_and_proof(
Ok(())
}

pub async fn sync_state<Ver: StaticVersionType>(
pub async fn sync_state<ApiVer: StaticVersionType>(
st: &StakeTable<BLSPubKey, StateVerKey, CircuitField>,
proving_key: Arc<ProvingKey>,
relay_server_client: &Client<ServerError, Ver>,
relay_server_client: &Client<ServerError, ApiVer>,
config: &StateProverConfig,
) -> Result<(), ProverError> {
let light_client_address = config.light_client_address;
Expand Down Expand Up @@ -393,16 +393,16 @@ pub async fn sync_state<Ver: StaticVersionType>(
Ok(())
}

fn start_http_server<Ver: StaticVersionType + 'static>(
fn start_http_server<ApiVer: StaticVersionType + 'static>(
port: u16,
light_client_address: Address,
bind_version: Ver,
bind_version: ApiVer,
) -> io::Result<()> {
let mut app = tide_disco::App::<_, ServerError>::with_state(());
let toml = toml::from_str::<toml::value::Value>(include_str!("../api/prover-service.toml"))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

let mut api = Api::<_, ServerError, Ver>::new(toml)
let mut api = Api::<_, ServerError, ApiVer>::new(toml)
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

api.get("getlightclientcontract", move |_, _| {
Expand All @@ -416,9 +416,9 @@ fn start_http_server<Ver: StaticVersionType + 'static>(
Ok(())
}

pub async fn run_prover_service<Ver: StaticVersionType + 'static>(
pub async fn run_prover_service<ApiVer: StaticVersionType + 'static>(
config: StateProverConfig,
bind_version: Ver,
bind_version: ApiVer,
) -> Result<()> {
let stake_table_capacity = config.stake_table_capacity;
tracing::info!("Stake table capacity: {}", stake_table_capacity);
Expand All @@ -431,15 +431,16 @@ pub async fn run_prover_service<Ver: StaticVersionType + 'static>(
run_prover_service_with_stake_table(config, bind_version, st).await
}

pub async fn run_prover_service_with_stake_table<Ver: StaticVersionType + 'static>(
pub async fn run_prover_service_with_stake_table<ApiVer: StaticVersionType + 'static>(
config: StateProverConfig,
bind_version: Ver,
bind_version: ApiVer,
st: Arc<StakeTable<BLSPubKey, StateVerKey, CircuitField>>,
) -> Result<()> {
tracing::info!("Light client address: {:?}", config.light_client_address);

let relay_server_client =
Arc::new(Client::<ServerError, Ver>::new(config.relay_server.clone()));
let relay_server_client = Arc::new(Client::<ServerError, ApiVer>::new(
config.relay_server.clone(),
));

// Start the HTTP server to get a functioning healthcheck before any heavy computations.
if let Some(port) = config.port {
Expand All @@ -466,17 +467,17 @@ pub async fn run_prover_service_with_stake_table<Ver: StaticVersionType + 'stati
}

/// Run light client state prover once
pub async fn run_prover_once<Ver: StaticVersionType>(
pub async fn run_prover_once<ApiVer: StaticVersionType>(
config: StateProverConfig,
_: Ver,
_: ApiVer,
) -> Result<()> {
let st = init_stake_table_from_sequencer(&config.sequencer_url, config.stake_table_capacity)
.await
.with_context(|| "Failed to initialize stake table")?;
let stake_table_capacity = config.stake_table_capacity;
let proving_key =
spawn_blocking(move || Arc::new(load_proving_key(stake_table_capacity))).await;
let relay_server_client = Client::<ServerError, Ver>::new(config.relay_server.clone());
let relay_server_client = Client::<ServerError, ApiVer>::new(config.relay_server.clone());

sync_state(&st, proving_key, &relay_server_client, &config)
.await
Expand Down
4 changes: 2 additions & 2 deletions marketplace-solver/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ where
Ok(api)
}

pub(crate) fn load_api<State: 'static, Error: 'static, Ver: StaticVersionType + 'static>(
pub(crate) fn load_api<State: 'static, Error: 'static, ApiVer: StaticVersionType + 'static>(
path: Option<impl AsRef<Path>>,
default: &str,
extensions: impl IntoIterator<Item = Value>,
) -> Result<Api<State, Error, Ver>, ApiError> {
) -> Result<Api<State, Error, ApiVer>, ApiError> {
let mut toml = match path {
Some(path) => load_toml(path.as_ref())?,
None => toml::from_str(default).map_err(|err| ApiError::CannotReadToml {
Expand Down
4 changes: 2 additions & 2 deletions node-metrics/src/api/node_validator/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ impl From<ApiError> for LoadApiError {
}
}

pub(crate) fn load_api<State: 'static, Ver: StaticVersionType + 'static>(
pub(crate) fn load_api<State: 'static, ApiVer: StaticVersionType + 'static>(
default: &str,
) -> Result<Api<State, Error, Ver>, LoadApiError> {
) -> Result<Api<State, Error, ApiVer>, LoadApiError> {
let toml: toml::Value = toml::from_str(default)?;
Ok(Api::new(toml)?)
}
Expand Down
37 changes: 21 additions & 16 deletions sequencer/src/api/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ pub struct NamespaceProofQueryData {
pub transactions: Vec<Transaction>,
}

pub(super) type AvailState<N, P, D, Ver> = Arc<RwLock<StorageState<N, P, D, Ver>>>;
pub(super) type AvailState<N, P, D, ApiVer> = Arc<RwLock<StorageState<N, P, D, ApiVer>>>;

type AvailabilityApi<N, P, D, V, Ver> = Api<AvailState<N, P, D, V>, availability::Error, Ver>;
type AvailabilityApi<N, P, D, V, ApiVer> = Api<AvailState<N, P, D, V>, availability::Error, ApiVer>;

// TODO (abdul): replace snafu with `this_error` in hotshot query service
// Snafu has been replaced by `this_error` everywhere.
Expand Down Expand Up @@ -127,7 +127,7 @@ where
Ok(api)
}

type ExplorerApi<N, P, D, V, Ver> = Api<AvailState<N, P, D, V>, explorer::Error, Ver>;
type ExplorerApi<N, P, D, V, ApiVer> = Api<AvailState<N, P, D, V>, explorer::Error, ApiVer>;

pub(super) fn explorer<N, P, D, V: Versions>(
) -> Result<ExplorerApi<N, P, D, V, SequencerApiVersion>>
Expand All @@ -142,7 +142,7 @@ where
Ok(api)
}

type NodeApi<N, P, D, V, Ver> = Api<AvailState<N, P, D, V>, node::Error, Ver>;
type NodeApi<N, P, D, V, ApiVer> = Api<AvailState<N, P, D, V>, node::Error, ApiVer>;

pub(super) fn node<N, P, D, V: Versions>() -> Result<NodeApi<N, P, D, V, SequencerApiVersion>>
where
Expand All @@ -156,20 +156,20 @@ where
)?;
Ok(api)
}
pub(super) fn submit<N, P, S, Ver: StaticVersionType + 'static>() -> Result<Api<S, Error, Ver>>
pub(super) fn submit<N, P, S, ApiVer: StaticVersionType + 'static>() -> Result<Api<S, Error, ApiVer>>
where
N: ConnectedNetwork<PubKey>,
S: 'static + Send + Sync + WriteState,
P: SequencerPersistence,
S::State: Send + Sync + SubmitDataSource<N, P>,
{
let toml = toml::from_str::<toml::Value>(include_str!("../../api/submit.toml"))?;
let mut api = Api::<S, Error, Ver>::new(toml)?;
let mut api = Api::<S, Error, ApiVer>::new(toml)?;

api.at("submit", |req, state| {
async move {
let tx = req
.body_auto::<Transaction, Ver>(Ver::instance())
.body_auto::<Transaction, ApiVer>(ApiVer::instance())
.map_err(Error::from_request_error)?;

let hash = tx.commit();
Expand All @@ -185,16 +185,16 @@ where
Ok(api)
}

pub(super) fn state_signature<N, S, Ver: StaticVersionType + 'static>(
_: Ver,
) -> Result<Api<S, Error, Ver>>
pub(super) fn state_signature<N, S, ApiVer: StaticVersionType + 'static>(
_: ApiVer,
) -> Result<Api<S, Error, ApiVer>>
where
N: ConnectedNetwork<PubKey>,
S: 'static + Send + Sync + ReadState,
S::State: Send + Sync + StateSignatureDataSource<N>,
{
let toml = toml::from_str::<toml::Value>(include_str!("../../api/state_signature.toml"))?;
let mut api = Api::<S, Error, Ver>::new(toml)?;
let mut api = Api::<S, Error, ApiVer>::new(toml)?;

api.get("get_state_signature", |req, state| {
async move {
Expand All @@ -215,13 +215,15 @@ where
Ok(api)
}

pub(super) fn catchup<S, Ver: StaticVersionType + 'static>(_: Ver) -> Result<Api<S, Error, Ver>>
pub(super) fn catchup<S, ApiVer: StaticVersionType + 'static>(
_: ApiVer,
) -> Result<Api<S, Error, ApiVer>>
where
S: 'static + Send + Sync + ReadState,
S::State: Send + Sync + CatchupDataSource,
{
let toml = toml::from_str::<toml::Value>(include_str!("../../api/catchup.toml"))?;
let mut api = Api::<S, Error, Ver>::new(toml)?;
let mut api = Api::<S, Error, ApiVer>::new(toml)?;

api.get("account", |req, state| {
async move {
Expand Down Expand Up @@ -281,7 +283,8 @@ where
Ok(api)
}

type MerklizedStateApi<N, P, D, V, Ver> = Api<AvailState<N, P, D, V>, merklized_state::Error, Ver>;
type MerklizedStateApi<N, P, D, V, ApiVer> =
Api<AvailState<N, P, D, V>, merklized_state::Error, ApiVer>;
pub(super) fn merklized_state<N, P, D, S, V: Versions, const ARITY: usize>(
) -> Result<MerklizedStateApi<N, P, D, V, SequencerApiVersion>>
where
Expand All @@ -305,13 +308,15 @@ where
Ok(api)
}

pub(super) fn config<S, Ver: StaticVersionType + 'static>(_: Ver) -> Result<Api<S, Error, Ver>>
pub(super) fn config<S, ApiVer: StaticVersionType + 'static>(
_: ApiVer,
) -> Result<Api<S, Error, ApiVer>>
where
S: 'static + Send + Sync + ReadState,
S::State: Send + Sync + HotShotConfigDataSource,
{
let toml = toml::from_str::<toml::Value>(include_str!("../../api/config.toml"))?;
let mut api = Api::<S, Error, Ver>::new(toml)?;
let mut api = Api::<S, Error, ApiVer>::new(toml)?;

let env_variables = get_public_env_vars()
.map_err(|err| Error::catch_all(StatusCode::INTERNAL_SERVER_ERROR, format!("{err:#}")))?;
Expand Down
6 changes: 3 additions & 3 deletions sequencer/src/api/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,16 @@ impl Options {
Ok(())
}

fn listen<S, E, Ver>(
fn listen<S, E, ApiVer>(
&self,
port: u16,
app: App<S, E>,
bind_version: Ver,
bind_version: ApiVer,
) -> impl Future<Output = anyhow::Result<()>>
where
S: Send + Sync + 'static,
E: Send + Sync + tide_disco::Error,
Ver: StaticVersionType + 'static,
ApiVer: StaticVersionType + 'static,
{
let max_connections = self.http.max_connections;

Expand Down
6 changes: 3 additions & 3 deletions sequencer/src/bin/commitment-task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ async fn main() {
run_hotshot_commitment_task::<SequencerApiVersion>(&hotshot_contract_options).await;
}

fn start_http_server<Ver: StaticVersionType + 'static>(
fn start_http_server<ApiVer: StaticVersionType + 'static>(
port: u16,
hotshot_address: Address,
bind_version: Ver,
bind_version: ApiVer,
) -> io::Result<()> {
let mut app = tide_disco::App::<(), ServerError>::with_state(());
let toml = toml::from_str::<toml::value::Value>(include_str!("../../api/commitment_task.toml"))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

let mut api = Api::<(), ServerError, Ver>::new(toml)
let mut api = Api::<(), ServerError, ApiVer>::new(toml)
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

api.get("gethotshotcontract", move |_, _| {
Expand Down
10 changes: 5 additions & 5 deletions sequencer/src/bin/espresso-dev-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,18 @@ impl<S: Signer + Clone + 'static> ReadState for ApiState<S> {
}
}

async fn run_dev_node_server<Ver: StaticVersionType + 'static, S: Signer + Clone + 'static>(
async fn run_dev_node_server<ApiVer: StaticVersionType + 'static, S: Signer + Clone + 'static>(
port: u16,
contracts: BTreeMap<u64, LightClientMock<SignerMiddleware<Provider<Http>, S>>>,
dev_info: DevInfo,
bind_version: Ver,
bind_version: ApiVer,
) -> anyhow::Result<()> {
let mut app = tide_disco::App::<_, ServerError>::with_state(ApiState(contracts));
let toml =
toml::from_str::<toml::value::Value>(include_str!("../../api/espresso_dev_node.toml"))
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

let mut api = Api::<_, ServerError, Ver>::new(toml)
let mut api = Api::<_, ServerError, ApiVer>::new(toml)
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
api.get("devinfo", move |_, _| {
let info = dev_info.clone();
Expand All @@ -388,7 +388,7 @@ async fn run_dev_node_server<Ver: StaticVersionType + 'static, S: Signer + Clone
.at("sethotshotdown", move |req, state: &ApiState<S>| {
async move {
let body = req
.body_auto::<SetHotshotDownReqBody, Ver>(Ver::instance())
.body_auto::<SetHotshotDownReqBody, ApiVer>(ApiVer::instance())
.map_err(ServerError::from_request_error)?;

// if chain id is not provided, primary L1 light client is used
Expand Down Expand Up @@ -423,7 +423,7 @@ async fn run_dev_node_server<Ver: StaticVersionType + 'static, S: Signer + Clone
.at("sethotshotup", move |req, state| {
async move {
let chain_id = req
.body_auto::<Option<SetHotshotUpReqBody>, Ver>(Ver::instance())
.body_auto::<Option<SetHotshotUpReqBody>, ApiVer>(ApiVer::instance())
.map_err(ServerError::from_request_error)?
.map(|b| b.chain_id);

Expand Down
8 changes: 4 additions & 4 deletions sequencer/src/bin/submit-transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ struct SubmittedTransaction {
submitted_at: Instant,
}

async fn submit_transactions<Ver: StaticVersionType>(
async fn submit_transactions<ApiVer: StaticVersionType>(
opt: Options,
mut sender: Sender<SubmittedTransaction>,
mut rng: ChaChaRng,
_: Ver,
_: ApiVer,
) {
let url = opt.submit_url();
tracing::info!(%url, "starting load generator task");
let client = Client::<Error, Ver>::new(url);
let client = Client::<Error, ApiVer>::new(url);

// Create an exponential distribution for sampling delay times. The distribution should have
// mean `opt.delay`, or parameter `\lambda = 1 / opt.delay`.
Expand Down Expand Up @@ -455,7 +455,7 @@ async fn submit_transactions<Ver: StaticVersionType>(
}
}

async fn server<Ver: StaticVersionType + 'static>(port: u16, bind_version: Ver) {
async fn server<ApiVer: StaticVersionType + 'static>(port: u16, bind_version: ApiVer) {
if let Err(err) = App::<(), ServerError>::with_state(())
.serve(format!("0.0.0.0:{port}"), bind_version)
.await
Expand Down
11 changes: 7 additions & 4 deletions sequencer/src/bin/verify-headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ struct Options {
logging: logging::Config,
}

type SequencerClient<Ver> = surf_disco::Client<hotshot_query_service::Error, Ver>;
type SequencerClient<ApiVer> = surf_disco::Client<hotshot_query_service::Error, ApiVer>;

async fn verify_header<Ver: StaticVersionType>(
async fn verify_header<ApiVer: StaticVersionType>(
opt: &Options,
seq: &SequencerClient<Ver>,
seq: &SequencerClient<ApiVer>,
l1: Option<&Provider<Http>>,
parent: Option<Header>,
height: usize,
Expand Down Expand Up @@ -117,7 +117,10 @@ async fn verify_header<Ver: StaticVersionType>(
(header, ok)
}

async fn get_header<Ver: StaticVersionType>(seq: &SequencerClient<Ver>, height: usize) -> Header {
async fn get_header<ApiVer: StaticVersionType>(
seq: &SequencerClient<ApiVer>,
height: usize,
) -> Header {
loop {
match seq
.get(&format!("availability/header/{height}"))
Expand Down
Loading

0 comments on commit fbc19ba

Please sign in to comment.