-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor to continuous background preimage generation and L1 finality caching #30
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
Merged
Merged
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
5790a5c
bump up kona
1b77763
bump optimism
6bcd7ca
bump optimism-package
e6705df
change directory
b9eec29
change directory
32e1baa
start server
315ef13
create preimage sequentially
6260bbd
configure
53356d5
fix write and load
fa7566d
collect parallel
3797455
add test
edc914d
add test
1422c66
fix clippy
826c641
add test
15aebb6
fix conflict
7b9ea58
add l1 finality cache
5561b45
fix
83c8750
fix logic
816b680
fix logic
c1db3dc
fix log
aa82b66
add test
44664ae
add inspector
aaf86cb
add inspection
806fb88
tweak
080c36d
fix lint
7330c2e
check order
39303a1
change cache type from vec to hash
171f9f5
sort save order
3e8ce62
add test
62c4f5c
Change log
f7f3c3e
check dir existence
b2bc1f3
refactor
14e15b5
add comment and test
84c44c2
tweak comment
2a3070b
add test for collector
9809898
fix format
c9d920f
add unit test for web
f027f5a
simplify logic
5b9d098
add test
84fa27e
use hashset instead of hashmap
fe63460
change progress on error
9948bdd
fix conflict
61b9913
fix conflict
d415e4d
tweak
bd07d09
use modified instead of created
27a49f5
use write rename pattern for file
2541074
reuse http client / add timeout
7816a37
fix clippy
2396523
fix ci
4e2afcd
rename retry_count -> attempts_count / add the comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,4 +25,6 @@ target/ | |
| /.data | ||
| *.bin | ||
| *.json | ||
| chain | ||
| chain | ||
| .preimage | ||
| .finalized_l1 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| use alloy_primitives::B256; | ||
| use axum::async_trait; | ||
| use reqwest::Response; | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct LightClientFinalityUpdateResponse { | ||
| pub data: LightClientFinalityUpdate, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct LightClientFinalityUpdate { | ||
| pub finalized_header: LightClientHeader, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct LightClientHeader { | ||
| pub execution: ExecutionPayloadHeader, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct ExecutionPayloadHeader { | ||
| pub block_hash: B256, | ||
| #[serde(deserialize_with = "deserialize_u64_from_str")] | ||
| pub block_number: u64, | ||
| } | ||
|
|
||
| // serde helper to allow numbers encoded as strings | ||
| fn deserialize_u64_from_str<'de, D>(deserializer: D) -> Result<u64, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| struct U64StringOrNumber; | ||
|
|
||
| impl<'de> serde::de::Visitor<'de> for U64StringOrNumber { | ||
| type Value = u64; | ||
|
|
||
| fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| write!(f, "a u64 as number or string") | ||
| } | ||
|
|
||
| fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E> { | ||
| Ok(v) | ||
| } | ||
|
|
||
| fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E> | ||
| where | ||
| E: serde::de::Error, | ||
| { | ||
| if v < 0 { | ||
| return Err(E::custom("negative value for u64")); | ||
| } | ||
| Ok(v as u64) | ||
| } | ||
|
|
||
| fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> | ||
| where | ||
| E: serde::de::Error, | ||
| { | ||
| v.parse::<u64>() | ||
| .map_err(|e| E::custom(format!("invalid u64 string: {e}"))) | ||
| } | ||
|
|
||
| fn visit_string<E>(self, v: String) -> Result<Self::Value, E> | ||
| where | ||
| E: serde::de::Error, | ||
| { | ||
| self.visit_str(&v) | ||
| } | ||
| } | ||
|
|
||
| deserializer.deserialize_any(U64StringOrNumber) | ||
| } | ||
|
|
||
| #[async_trait] | ||
| pub trait BeaconClient: Send + Sync + 'static { | ||
| async fn get_raw_light_client_finality_update(&self) -> anyhow::Result<String>; | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct HttpBeaconClient { | ||
| beacon_addr: String, | ||
| client: reqwest::Client, | ||
| } | ||
|
|
||
| impl HttpBeaconClient { | ||
| pub fn new(beacon_addr: String, timeout: std::time::Duration) -> Self { | ||
| Self { | ||
| beacon_addr, | ||
| client: reqwest::Client::builder() | ||
| .timeout(timeout) | ||
| .build() | ||
| .expect("failed to build reqwest client"), | ||
| } | ||
| } | ||
|
|
||
| async fn check_response(&self, response: Response) -> anyhow::Result<Response> { | ||
| if response.status().is_success() { | ||
| Ok(response) | ||
| } else { | ||
| Err(anyhow::anyhow!( | ||
| "Request failed with status: {} body={:?}", | ||
| response.status(), | ||
| response.text().await | ||
| )) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl BeaconClient for HttpBeaconClient { | ||
| async fn get_raw_light_client_finality_update(&self) -> anyhow::Result<String> { | ||
| let response = self | ||
| .client | ||
| .get(format!( | ||
| "{}/eth/v1/beacon/light_client/finality_update", | ||
| self.beacon_addr | ||
| )) | ||
| .send() | ||
| .await?; | ||
| let response = self.check_response(response).await?; | ||
| response | ||
| .text() | ||
| .await | ||
| .map_err(|e| anyhow::anyhow!("Failed to get finality update: {e:?}")) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.