Skip to content

Commit

Permalink
Optimization after reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Jul 16, 2024
1 parent 2038cbe commit e7550d6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 23 deletions.
31 changes: 24 additions & 7 deletions sequencer/api/espresso_dev_node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@ FORMAT_VERSION = "0.1.0"
PATH = ["/dev-info"]
DOC = """
Get the debug info
Returns
```
{
"builder_url": string,
"prover_port": integer,
"l1_url": string,
"light_client_address:" address,
}
```
"""

[route.freeze]
PATH = ["mock-contract/freeze/:height"]
":height" = "Integer"
[route.sethotshotdown]
PATH = ["set-hotshot-down"]
METHOD = "POST"
DOC = """
Freeze the L1 height in the light client contract.
Set the hotshot down since the given L1 height.
Body:
```
{
"height": integer,
}
```
By doing this, the L1 height in the light contract will be frozen and rollups will detect
the HotShot failure. This is intended to be used when testing the rollups' functionalities.
"""

[route.unfreeze]
PATH = ["mock-contract/unfreeze"]
[route.sethotshotup]
PATH = ["set-hotshot-up"]
METHOD = "POST"
DOC = """
Unfreeze the L1 height in the light client contract.
Set the hotshot up in the light client contract.
This is intended to be used when `freeze` has been called previously. By unfreezing the L1 height,
rollups will detect the reactivity of HotShot.
Expand Down
60 changes: 44 additions & 16 deletions sequencer/src/bin/espresso-dev-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async fn main() -> anyhow::Result<()> {
let retry_interval = Duration::from_secs(2);
let prover_port = cli_params
.prover_port
.unwrap_or(pick_unused_port().unwrap());
.unwrap_or_else(|| pick_unused_port().unwrap());
let light_client_address = contracts
.get_contract_address(Contract::LightClientProxy)
.unwrap();
Expand Down Expand Up @@ -241,31 +241,32 @@ async fn run_dev_node_server<Ver: StaticVersionType + 'static, S: Signer + Clone
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

let contract = mock_contract.clone();
api.get("freeze", move |req, _| {
api.post("sethotshotdown", move |req, _| {
let contract = contract.clone();
async move {
let height: u64 = req
.integer_param("height")
.map_err(ServerError::from_request_error)?;
let height = req
.body_auto::<SetHotshotUpBody, Ver>(Ver::instance())
.map_err(ServerError::from_request_error)?
.height;
contract
.set_hot_shot_down_since(U256::from(height))
.send()
.await
.map_err(|err| ServerError::catch_all(StatusCode::FORBIDDEN, err.to_string()))?;
.map_err(|err| {
ServerError::catch_all(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
})?;
Ok(())
}
.boxed()
})
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;

api.get("unfreeze", move |_, _| {
api.post("sethotshotup", move |_, _| {
let contract = mock_contract.clone();
async move {
contract
.set_hot_shot_up()
.send()
.await
.map_err(|err| ServerError::catch_all(StatusCode::FORBIDDEN, err.to_string()))?;
contract.set_hot_shot_up().send().await.map_err(|err| {
ServerError::catch_all(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
})?;
Ok(())
}
.boxed()
Expand All @@ -280,14 +281,19 @@ async fn run_dev_node_server<Ver: StaticVersionType + 'static, S: Signer + Clone
Ok(())
}

#[derive(Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
struct DevInfo {
pub builder_url: Url,
pub prover_port: u16,
pub l1_url: Url,
pub light_client_address: Address,
}

#[derive(Debug, Serialize, Deserialize)]
struct SetHotshotUpBody {
pub height: u64,
}

#[cfg(test)]
mod tests {
use std::{process::Child, sync::Arc, time::Duration};
Expand All @@ -312,7 +318,7 @@ mod tests {
use surf_disco::Client;
use tide_disco::error::ServerError;

use crate::DevInfo;
use crate::{DevInfo, SetHotshotUpBody};

const TEST_MNEMONIC: &str = "test test test test test test test test test test test junk";

Expand Down Expand Up @@ -505,16 +511,38 @@ mod tests {
.unwrap();

dev_node_client
.get::<()>("api/mock-contract/freeze/3")
.post::<()>("api/mock-contract/set-hotshot-down")
.body_json(&SetHotshotUpBody { height: 3 })
.unwrap()
.send()
.await
.unwrap();

while !light_client
.lag_over_escape_hatch_threshold(U256::from(4), U256::from(0))
.call()
.await
.unwrap_or(false)
{
tracing::info!("waiting for setting hotshot down");
sleep(Duration::from_secs(3)).await;
}

dev_node_client
.get::<()>("api/mock-contract/unfreeze")
.post::<()>("api/mock-contract/set-hotshot-up")
.send()
.await
.unwrap();

while light_client
.lag_over_escape_hatch_threshold(U256::from(4), U256::from(0))
.call()
.await
.unwrap_or(true)
{
tracing::info!("waiting for setting hotshot up");
sleep(Duration::from_secs(3)).await;
}
}

drop(db);
Expand Down

0 comments on commit e7550d6

Please sign in to comment.