Skip to content

Commit

Permalink
style: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Dec 13, 2024
1 parent 68b8304 commit b6d1cbd
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 122 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# hokulea
# Hokulea

![](./hokulea.jpeg)
37 changes: 22 additions & 15 deletions bin/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
extern crate alloc;
use alloy_consensus::{Header, Sealed};
use eigenda_proof::pipeline::OraclePipeline;
use kona_client::FaultProofProgramError;
use kona_driver::Driver;
use kona_preimage::{
CommsClient, HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient,
};
use eigenda_proof::pipeline::OraclePipeline;
use kona_driver::{Driver};
use alloy_consensus::{Header, Sealed};

use alloc::sync::Arc;
use core::fmt::Debug;
use kona_executor::TrieDBProvider;
use kona_proof::{
errors::OracleProviderError,
executor::KonaExecutor,
Expand All @@ -15,12 +18,7 @@ use kona_proof::{
sync::new_pipeline_cursor,
BootInfo, CachingOracle, HintType,
};
use core::fmt::Debug;
use alloc::sync::Arc;
use kona_executor::{ExecutorError, TrieDBProvider};
use tracing::{error, info, warn};

use eigenda_proof::pipeline::{OracleDataProvider, OracleDerivationPipeline};
use tracing::{error, info};

use eigenda_proof::eigenda_provider::OracleEigenDAProvider;

Expand All @@ -36,7 +34,11 @@ where
// PROLOGUE //
////////////////////////////////////////////////////////////////

let oracle = Arc::new(CachingOracle::new(ORACLE_LRU_SIZE, oracle_client, hint_client));
let oracle = Arc::new(CachingOracle::new(
ORACLE_LRU_SIZE,
oracle_client,
hint_client,
));
let boot = match BootInfo::load(oracle.as_ref()).await {
Ok(boot) => Arc::new(boot),
Err(e) => {
Expand Down Expand Up @@ -96,8 +98,9 @@ where

// Run the derivation pipeline until we are able to produce the output root of the claimed
// L2 block.
let (number, output_root) =
driver.advance_to_target(&boot.rollup_config, Some(boot.claimed_l2_block_number)).await?;
let (number, output_root) = driver
.advance_to_target(&boot.rollup_config, Some(boot.claimed_l2_block_number))
.await?;

////////////////////////////////////////////////////////////////
// EPILOGUE //
Expand All @@ -110,7 +113,10 @@ where
number = number,
output_root = output_root
);
return Err(FaultProofProgramError::InvalidClaim(output_root, boot.claimed_l2_output_root));
return Err(FaultProofProgramError::InvalidClaim(
output_root,
boot.claimed_l2_output_root,
));
}

info!(
Expand Down Expand Up @@ -146,8 +152,9 @@ where
.await
.map_err(OracleProviderError::Preimage)?;

let safe_hash =
output_preimage[96..128].try_into().map_err(OracleProviderError::SliceConversion)?;
let safe_hash = output_preimage[96..128]
.try_into()
.map_err(OracleProviderError::SliceConversion)?;
l2_chain_provider
.header_by_hash(safe_hash)
.map(|header| Sealed::new_unchecked(header, safe_hash))
Expand Down
19 changes: 6 additions & 13 deletions bin/host/src/eigenda_blobs.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use alloy_primitives::Bytes;
use anyhow::Ok;
use kona_derive::{errors::BlobProviderError, traits::BlobProvider};
use reqwest::{header::GetAll, Client};
use tracing::trace;
use reqwest;

/// An online implementation of the [EigenDABlobProvider] trait.
#[derive(Debug, Clone)]
pub struct OnlineEigenDABlobProvider {
/// The base url.
base: String,
/// The inner reqwest client. Used to talk to proxy
inner: Client,
inner: reqwest::Client,
}

const GET_METHOD: &str = "get";
Expand All @@ -22,7 +20,7 @@ impl OnlineEigenDABlobProvider {
/// [OnlineEigenDABlobProvider] will attempt to load them dynamically at runtime if they are not
/// provided.
pub async fn new_http(base: String) -> Result<Self, anyhow::Error> {
let inner = Client::new();
let inner = reqwest::Client::new();
Ok(Self { base, inner })
}

Expand All @@ -31,14 +29,9 @@ impl OnlineEigenDABlobProvider {
cert: &Bytes,
) -> Result<alloy_rlp::Bytes, reqwest::Error> {
let url = format!("{}/{}/{}", self.base, GET_METHOD, cert.slice(1..));

let raw_response = self.inner
.get(url)
.send()
.await?;

let raw_response = self.inner.get(url).send().await?;

raw_response.bytes().await
}


}
}
74 changes: 48 additions & 26 deletions bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! remote source.
use crate::eigenda_blobs::OnlineEigenDABlobProvider;
use kona_host::{blobs::OnlineBlobProvider, kv::KeyValueStore};
use alloy_consensus::{Header, TxEnvelope, EMPTY_ROOT_HASH};
use alloy_eips::{
eip2718::Encodable2718,
Expand All @@ -17,13 +16,14 @@ use alloy_rpc_types::{
Transaction,
};
use anyhow::{anyhow, Result};
use eigenda_proof::hint::{Hint, HintType};
use kona_host::{blobs::OnlineBlobProvider, kv::KeyValueStore};
use kona_preimage::{PreimageKey, PreimageKeyType};
use eigenda_proof::hint::{HintType, Hint};
use op_alloy_protocol::BlockInfo;
use op_alloy_rpc_types_engine::OpPayloadAttributes;
use std::sync::Arc;
use tokio::sync::RwLock;
use tracing::{error, trace, warn, info};
use tracing::{error, info, trace, warn};

mod precompiles;

Expand Down Expand Up @@ -62,7 +62,15 @@ where
l2_provider: ReqwestProvider,
l2_head: B256,
) -> Self {
Self { kv_store, l1_provider, blob_provider, eigenda_blob_provider, l2_provider, l2_head, last_hint: None }
Self {
kv_store,
l1_provider,
blob_provider,
eigenda_blob_provider,
l2_provider,
l2_head,
last_hint: None,
}
}

/// Set the last hint to be received.
Expand Down Expand Up @@ -191,7 +199,10 @@ where
let index = u64::from_be_bytes(index_data_bytes);
let timestamp = u64::from_be_bytes(timestamp_data_bytes);

let partial_block_ref = BlockInfo { timestamp, ..Default::default() };
let partial_block_ref = BlockInfo {
timestamp,
..Default::default()
};
let indexed_hash = IndexedBlobHash { index, hash };

// Fetch the blob sidecar from the blob provider.
Expand Down Expand Up @@ -336,7 +347,8 @@ where
encoded_transactions.push(tx);
}

self.store_trie_nodes(encoded_transactions.as_slice()).await?;
self.store_trie_nodes(encoded_transactions.as_slice())
.await?;
}
_ => anyhow::bail!("Only BlockTransactions::Hashes are supported."),
};
Expand Down Expand Up @@ -375,8 +387,10 @@ where
};

let mut kv_write_lock = self.kv_store.write().await;
kv_write_lock
.set(PreimageKey::new(*hash, PreimageKeyType::Keccak256).into(), code.into())?;
kv_write_lock.set(
PreimageKey::new(*hash, PreimageKeyType::Keccak256).into(),
code.into(),
)?;
}
HintType::StartingL2Output => {
const OUTPUT_ROOT_VERSION: u8 = 0;
Expand Down Expand Up @@ -468,12 +482,15 @@ where
let mut kv_write_lock = self.kv_store.write().await;

// Write the account proof nodes to the key-value store.
proof_response.account_proof.into_iter().try_for_each(|node| {
let node_hash = keccak256(node.as_ref());
let key = PreimageKey::new(*node_hash, PreimageKeyType::Keccak256);
kv_write_lock.set(key.into(), node.into())?;
Ok::<(), anyhow::Error>(())
})?;
proof_response
.account_proof
.into_iter()
.try_for_each(|node| {
let node_hash = keccak256(node.as_ref());
let key = PreimageKey::new(*node_hash, PreimageKeyType::Keccak256);
kv_write_lock.set(key.into(), node.into())?;
Ok::<(), anyhow::Error>(())
})?;
}
HintType::L2AccountStorageProof => {
if hint_data.len() != 8 + 20 + 32 {
Expand All @@ -498,12 +515,15 @@ where
let mut kv_write_lock = self.kv_store.write().await;

// Write the account proof nodes to the key-value store.
proof_response.account_proof.into_iter().try_for_each(|node| {
let node_hash = keccak256(node.as_ref());
let key = PreimageKey::new(*node_hash, PreimageKeyType::Keccak256);
kv_write_lock.set(key.into(), node.into())?;
Ok::<(), anyhow::Error>(())
})?;
proof_response
.account_proof
.into_iter()
.try_for_each(|node| {
let node_hash = keccak256(node.as_ref());
let key = PreimageKey::new(*node_hash, PreimageKeyType::Keccak256);
kv_write_lock.set(key.into(), node.into())?;
Ok::<(), anyhow::Error>(())
})?;

// Write the storage proof nodes to the key-value store.
let storage_proof = proof_response.storage_proof.remove(0);
Expand Down Expand Up @@ -540,7 +560,10 @@ where
let mut kv_write_lock = self.kv_store.write().await;
for (hash, preimage) in merged.into_iter() {
let computed_hash = keccak256(preimage.as_ref());
assert_eq!(computed_hash, hash, "Preimage hash does not match expected hash");
assert_eq!(
computed_hash, hash,
"Preimage hash does not match expected hash"
);

let key = PreimageKey::new(*hash, PreimageKeyType::Keccak256);
kv_write_lock.set(key.into(), preimage.into())?;
Expand All @@ -551,10 +574,10 @@ where
info!(target: "fetcher", "Fetching AltDACommitment cert: {:?}", cert);
// Fetch the blob sidecar from the blob provider.
let eigenda_blob = self
.eigenda_blob_provider.
fetch_eigenda_blob(&cert).
await.
map_err(|e| anyhow!("Failed to fetch eigenda blob: {e}"))?;
.eigenda_blob_provider
.fetch_eigenda_blob(&cert)
.await
.map_err(|e| anyhow!("Failed to fetch eigenda blob: {e}"))?;

info!(target: "fetcher", "eigenda_blob len {}", eigenda_blob.len());
// Acquire a lock on the key-value store and set the preimages.
Expand All @@ -565,7 +588,6 @@ where
PreimageKey::new(*keccak256(cert), PreimageKeyType::GlobalGeneric).into(),
eigenda_blob.to_vec(),
)?;

}
}

Expand Down
5 changes: 3 additions & 2 deletions bin/host/src/fetcher/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ pub(crate) const ACCELERATED_PRECOMPILES: &[PrecompileWithAddress] = &[

/// Executes an accelerated precompile on [revm].
pub(crate) fn execute<T: Into<Bytes>>(address: Address, input: T) -> Result<Vec<u8>> {
if let Some(precompile) =
ACCELERATED_PRECOMPILES.iter().find(|precompile| precompile.0 == address)
if let Some(precompile) = ACCELERATED_PRECOMPILES
.iter()
.find(|precompile| precompile.0 == address)
{
match precompile.1 {
Precompile::Standard(std_precompile) => {
Expand Down
18 changes: 9 additions & 9 deletions bin/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ use server::PreimageServer;

use kona_host::cli::{init_tracing_subscriber, HostCli};

use kona_host::{kv};
use kona_host::kv;

use kona_client;

use crate::eigenda_blobs::OnlineEigenDABlobProvider;
use anyhow::{anyhow, Result};
use fetcher::Fetcher;
use kona_preimage::{
BidirectionalChannel, HintReader, HintWriter, NativeChannel, OracleReader, OracleServer,
Expand All @@ -23,11 +25,6 @@ use kv::KeyValueStore;
use std::sync::Arc;
use tokio::{sync::RwLock, task};
use tracing::info;
use crate::{
eigenda_blobs::OnlineEigenDABlobProvider,
};
use anyhow::{anyhow, Result};


/// Starts the [PreimageServer] and the client program in separate threads. The client program is
/// ran natively in this mode.
Expand All @@ -48,9 +45,10 @@ pub async fn start_server_and_native_client(cfg: HostCli) -> Result<i32> {
let eigenda_blob_provider = OnlineEigenDABlobProvider::new_http(
//EIGENDA_ADDRESS.to_string(),
"http://127.0.0.1:3100".to_string(),
).await
)
.await
.map_err(|e| anyhow!("Failed to load eigenda blob provider configuration: {e}"))?;

Some(Arc::new(RwLock::new(Fetcher::new(
kv_store.clone(),
l1_provider,
Expand Down Expand Up @@ -100,5 +98,7 @@ where
let hint_reader = HintReader::new(hint_chan);
let oracle_server = OracleServer::new(preimage_chan);

PreimageServer::new(oracle_server, hint_reader, kv_store, fetcher).start().await
PreimageServer::new(oracle_server, hint_reader, kv_store, fetcher)
.start()
.await
}
2 changes: 1 addition & 1 deletion bin/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use anyhow::Result;
use clap::Parser;
use kona_host::{init_tracing_subscriber, start_server, HostCli};
use hokulea_host::start_server_and_native_client;
use kona_host::{init_tracing_subscriber, start_server, HostCli};

use tracing::{error, info};

Expand Down
4 changes: 3 additions & 1 deletion bin/host/src/preimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ where
{
async fn get_preimage(&self, key: PreimageKey) -> PreimageOracleResult<Vec<u8>> {
let kv_store = self.inner.read().await;
kv_store.get(key.into()).ok_or(PreimageOracleError::KeyNotFound)
kv_store
.get(key.into())
.ok_or(PreimageOracleError::KeyNotFound)
}
}

Expand Down
Loading

0 comments on commit b6d1cbd

Please sign in to comment.