Skip to content

Commit a805452

Browse files
committed
fix review
1 parent 950b299 commit a805452

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2023 Datachain, Inc
189+
Copyright 2025 Datachain, Inc
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

server/src/host/single/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ impl DerivationRequest {
4343
}
4444

4545
async fn run_client_native(
46-
hint_reader: HintWriter<NativeChannel>,
46+
hint_writer: HintWriter<NativeChannel>,
4747
oracle_reader: OracleReader<NativeChannel>,
4848
evm_factory: FpvmOpEvmFactory<NativeChannel>,
4949
) -> Result<()> {
50-
kona_client::single::run(oracle_reader, hint_reader, evm_factory)
50+
kona_client::single::run(oracle_reader, hint_writer, evm_factory)
5151
.await
5252
.map_err(Into::into)
5353
}

server/src/host/single/trace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl KeyValueStore for TracingKeyValueStore {
3636

3737
pub fn encode_to_bytes(used: hashbrown::HashMap<PreimageKey, Vec<u8>>) -> Preimages {
3838
let mut temp: Vec<Preimage> = Vec::with_capacity(used.len());
39-
for (k, v) in used.iter() {
40-
temp.push(Preimage::new(*k, v.clone()));
39+
for (k, v) in used.into_iter() {
40+
temp.push(Preimage::new(k, v));
4141
}
4242

4343
Preimages { preimages: temp }

server/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![feature(const_trait_impl)]
2-
extern crate core;
3-
41
use crate::host::single::config::Config;
52
use crate::server::{start_http_server_task, DerivationState};
63
use clap::Parser;

server/src/server.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use axum::http::StatusCode;
77
use axum::routing::post;
88
use axum::Json;
99
use kona_genesis::RollupConfig;
10-
use log::{error, info};
1110
use serde::{Deserialize, Serialize};
1211
use std::fmt::Debug;
1312
use std::sync::Arc;
1413
use tokio::net::TcpListener;
1514
use tokio::task::JoinHandle;
15+
use tracing::{error, info};
1616

1717
pub struct DerivationState {
1818
pub rollup_config: RollupConfig,
@@ -56,25 +56,8 @@ async fn derivation(
5656
Json(payload): Json<Request>,
5757
) -> (StatusCode, Vec<u8>) {
5858
info!("derivation request: {:?}", payload);
59-
if payload.agreed_l2_output_root == payload.l2_output_root {
60-
error!("agreed_l2_output_root and l2_output_root are same value");
61-
return (StatusCode::BAD_REQUEST, vec![]);
62-
}
63-
if payload.agreed_l2_output_root.is_empty() || payload.agreed_l2_output_root.is_zero() {
64-
error!("invalid agreed_l2_output_root",);
65-
return (StatusCode::BAD_REQUEST, vec![]);
66-
}
67-
if payload.l2_output_root.is_empty() || payload.l2_output_root.is_zero() {
68-
error!("invalid l2_output_root",);
69-
return (StatusCode::BAD_REQUEST, vec![]);
70-
}
71-
if payload.l1_head_hash.is_empty() || payload.l1_head_hash.is_zero() {
72-
error!("invalid l1_head_hash",);
73-
return (StatusCode::BAD_REQUEST, vec![]);
74-
}
75-
if payload.l2_block_number == 0 {
76-
error!("invalid l2_block_number",);
77-
return (StatusCode::BAD_REQUEST, vec![]);
59+
if let Err(v) = validate_request(&payload) {
60+
return (StatusCode::BAD_REQUEST, v.as_bytes().to_vec());
7861
}
7962

8063
let derivation = DerivationRequest {
@@ -99,3 +82,27 @@ async fn derivation(
9982
}
10083
}
10184
}
85+
86+
fn validate_request(payload: &Request) -> Result<(), &'static str> {
87+
if payload.agreed_l2_output_root == payload.l2_output_root {
88+
error!("agreed_l2_output_root and l2_output_root are same value");
89+
return Err("agreed_l2_output_root and l2_output_root are the same value");
90+
}
91+
if payload.agreed_l2_output_root.is_empty() || payload.agreed_l2_output_root.is_zero() {
92+
error!("invalid agreed_l2_output_root",);
93+
return Err("invalid agreed_l2_output_root");
94+
}
95+
if payload.l2_output_root.is_empty() || payload.l2_output_root.is_zero() {
96+
error!("invalid l2_output_root",);
97+
return Err("invalid l2_output_root");
98+
}
99+
if payload.l1_head_hash.is_empty() || payload.l1_head_hash.is_zero() {
100+
error!("invalid l1_head_hash",);
101+
return Err("invalid l1_head_hash");
102+
}
103+
if payload.l2_block_number == 0 {
104+
error!("invalid l2_block_number",);
105+
return Err("invalid l2_block_number");
106+
}
107+
Ok(())
108+
}

0 commit comments

Comments
 (0)