Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kairos-server: add casper sse url #138

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ KAIROS_SERVER_MAX_BATCH_SECONDS=60
RISC0_DEV_MODE=1;
# FIXME this is a dummy value that fixes a regression that prevented server startup
KAIROS_SERVER_CASPER_RPC="http://127.0.0.1:11101/rpc"
KAIROS_SERVER_CASPER_SSE="http://127.0.0.1:18101/events/main"
KAIROS_SERVER_DEMO_CONTRACT_HASH="0000000000000000000000000000000000000000000000000000000000000000"
7 changes: 6 additions & 1 deletion kairos-cli/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ async fn deposit_successful_with_ed25519() {
.expect("Expected at least one node after successful network run");
let casper_rpc_url =
Url::parse(&format!("http://localhost:{}/rpc", node.port.rpc_port)).unwrap();
let casper_sse_url = Url::parse(&format!(
"http://localhost:{}/events/main",
node.port.sse_port
))
.unwrap();

let kairos = kairos::Kairos::run(casper_rpc_url, None, None)
let kairos = kairos::Kairos::run(&casper_rpc_url, &casper_sse_url, None, None)
.await
.unwrap();

Expand Down
3 changes: 3 additions & 0 deletions kairos-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct ServerConfig {
pub secret_key_file: Option<PathBuf>,
pub socket_addr: SocketAddr,
pub casper_rpc: Url,
pub casper_sse: Url,
pub kairos_demo_contract_hash: ContractHash,
pub batch_config: BatchConfig,
}
Expand All @@ -21,6 +22,7 @@ impl ServerConfig {
pub fn from_env() -> Result<Self, String> {
let socket_addr = parse_env_as::<SocketAddr>("KAIROS_SERVER_SOCKET_ADDR")?;
let casper_rpc = parse_env_as::<Url>("KAIROS_SERVER_CASPER_RPC")?;
let casper_sse = parse_env_as::<Url>("KAIROS_SERVER_CASPER_SSE")?;
let batch_config = BatchConfig::from_env()?;
let secret_key_file =
parse_env_as_opt::<String>("KAIROS_SERVER_SECRET_KEY_FILE")?.map(PathBuf::from);
Expand Down Expand Up @@ -50,6 +52,7 @@ impl ServerConfig {
secret_key_file,
socket_addr,
casper_rpc,
casper_sse,
kairos_demo_contract_hash,
batch_config,
})
Expand Down
17 changes: 12 additions & 5 deletions kairos-server/tests/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ static TEST_ENVIRONMENT: OnceLock<()> = OnceLock::new();

#[cfg(feature = "deposit-mock")]
fn new_test_app() -> TestServer {
new_test_app_with_casper_node(&Url::parse("http://0.0.0.0:0").unwrap())
let dummy_url = Url::parse("http://0.0.0.0:0").unwrap();
new_test_app_with_casper_node(&dummy_url, &dummy_url)
}

fn new_test_app_with_casper_node(casper_node_url: &Url) -> TestServer {
fn new_test_app_with_casper_node(casper_rpc_url: &Url, casper_sse_url: &Url) -> TestServer {
TEST_ENVIRONMENT.get_or_init(|| {
tracing_subscriber::registry()
.with(
Expand All @@ -47,7 +48,8 @@ fn new_test_app_with_casper_node(casper_node_url: &Url) -> TestServer {
let server_config = ServerConfig {
secret_key_file: None,
socket_addr: "0.0.0.0:0".parse().unwrap(),
casper_rpc: casper_node_url.clone(),
casper_rpc: casper_rpc_url.clone(),
casper_sse: casper_sse_url.clone(),
kairos_demo_contract_hash: ContractHash::default(),
batch_config: BatchConfig {
max_batch_size: None,
Expand All @@ -73,10 +75,15 @@ async fn test_signed_deploy_is_forwarded_if_sender_in_approvals() {
.nodes
.first()
.expect("Expected at least one node after successful network run");
let casper_node_url =
let casper_rpc_url =
Url::parse(&format!("http://localhost:{}/rpc", node.port.rpc_port)).unwrap();
let casper_sse_url = Url::parse(&format!(
"http://localhost:{}/events/main",
node.port.sse_port
))
.unwrap();

let server = new_test_app_with_casper_node(&casper_node_url);
let server = new_test_app_with_casper_node(&casper_rpc_url, &casper_sse_url);

let sender_secret_key_file = network
.working_dir
Expand Down
11 changes: 8 additions & 3 deletions kairos-test-utils/src/kairos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ impl Kairos {
/// If no proving server is running, we will start the one at `BatchConfig.proving_server`.
/// The caller should ensure that `BatchConfig.proving_server == KAIROS_PROVER_SERVER_URL`.
pub async fn run(
casper_rpc: Url,
casper_rpc: &Url,
casper_sse: &Url,
proving_server_batch_config: Option<BatchConfig>,
kairos_demo_contract_hash: Option<ContractHash>,
) -> Result<Kairos, io::Error> {
Expand All @@ -44,7 +45,8 @@ impl Kairos {
let config = ServerConfig {
secret_key_file: None,
socket_addr,
casper_rpc,
casper_rpc: casper_rpc.clone(),
casper_sse: casper_sse.clone(),
kairos_demo_contract_hash: kairos_demo_contract_hash.unwrap_or_default(),
batch_config,
};
Expand Down Expand Up @@ -117,6 +119,9 @@ mod tests {
#[tokio::test]
async fn test_kairos_starts_and_terminates() {
let dummy_rpc = Url::parse("http://127.0.0.1:11101/rpc").unwrap();
let _kairos = Kairos::run(dummy_rpc, None, None).await.unwrap();
let dummy_sse = Url::parse("http://127.0.0.1:18101/events/main").unwrap();
let _kairos = Kairos::run(&dummy_rpc, &dummy_sse, None, None)
.await
.unwrap();
}
}
7 changes: 5 additions & 2 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ in
imports = [
(mkKairosHostConfig "kairos-host")
];
# A placeholder URL to make the test pass
services.kairos.casperRpcUrl = "http://localhost:11101/rpc";
# Placeholder values make the test pass
services.kairos = {
casperRpcUrl = "http://localhost:11101/rpc";
casperSseUrl = "http://localhost:18101/events/main";
};
};
verifyServices = [ "kairos.service" ];
};
Expand Down
9 changes: 9 additions & 0 deletions nixos/modules/kairos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ in
'';
};

casperSseUrl = mkOption {
type = types.str;
example = "http://127.0.0.1:18101/events/main";
description = ''
The casper node URL to the SSE events endpoint.
'';
};

prover = mkOption {
description = "Prover server related options";
default = { };
Expand Down Expand Up @@ -133,6 +141,7 @@ in
RUST_LOG = cfg.logLevel;
KAIROS_SERVER_SOCKET_ADDR = "${cfg.bindAddress}:${builtins.toString cfg.port}";
KAIROS_SERVER_CASPER_RPC = cfg.casperRpcUrl;
KAIROS_SERVER_CASPER_SSE = cfg.casperSseUrl;
KAIROS_SERVER_DEMO_CONTRACT_HASH = cfg.demoContractHash;
KAIROS_PROVER_SERVER_URL = "${cfg.prover.protocol}://${cfg.prover.bindAddress}:${builtins.toString cfg.prover.port}";
} // optionalAttrs (!builtins.isNull cfg.prover.maxBatchSize) {
Expand Down
1 change: 1 addition & 0 deletions nixos/tests/end-to-end.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ nixosTest {

services.kairos = {
casperRpcUrl = "http://localhost:${builtins.toString config.services.cctl.port}/rpc";
casperSseUrl = "http://localhost:18101/events/main"; # has to be hardcoded since it's not configurable atm
demoContractHash = "0000000000000000000000000000000000000000000000000000000000000000";
};

Expand Down
Loading