-
Notifications
You must be signed in to change notification settings - Fork 63
feat: enable configuration hot-reloading #231
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 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5477a9d
Update signer config via API endpoint
ManuelBilbao fb60b24
Update config for PBS module
ManuelBilbao cf20b43
Add reload endpoint to API
ManuelBilbao 1162b49
Take read lock instead of write
ManuelBilbao 97a2266
Add custom reload to status_api example
ManuelBilbao 4e08196
Add function doc
ManuelBilbao 797bc87
Add warning when updating PBS host and port
ManuelBilbao a2ae3e5
Improve signer reload logging
ManuelBilbao e4d0660
Update OpenAPI docs
ManuelBilbao 4d7b609
Refactor error
ManuelBilbao 92a04de
Refactor PbsState
ManuelBilbao 9f37297
Fix deadlock
ManuelBilbao 0ec779e
Remove authentication from signer reload
ManuelBilbao bb08dd1
Refactor signer
ManuelBilbao cafc7a7
Add status endpoint to OpenAPI
ManuelBilbao acd4b32
Add documentation
ManuelBilbao 2481a95
Change reload endpoint in PBS
ManuelBilbao 7f3a904
Merge branch 'main' into mb/hot_reloading
ManuelBilbao afd6edb
Merge branch 'main' into mb/hot_reloading
ManuelBilbao 9dbdd60
Merge branch 'main' into mb/hot_reloading
ManuelBilbao d3339f0
Release locks earlier
ManuelBilbao be8e8a5
Move write new status to wrapper
ManuelBilbao f340baf
Replace tokio RwLock with parking_lot
ManuelBilbao 6173270
Update docs
ManuelBilbao 6e95635
Fix error logging
ManuelBilbao 53d5044
Remove /reload endpoint from OpenAPI
ManuelBilbao 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
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
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
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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| mod get_header; | ||
| mod register_validator; | ||
| mod reload; | ||
| mod status; | ||
| mod submit_block; | ||
|
|
||
| pub use get_header::get_header; | ||
| pub use register_validator::register_validator; | ||
| pub use reload::reload; | ||
| pub use status::get_status; | ||
| pub use submit_block::submit_block; |
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,31 @@ | ||
| use cb_common::config::load_pbs_config; | ||
| use tracing::warn; | ||
|
|
||
| use crate::{BuilderApiState, PbsState, PbsStateGuard}; | ||
|
|
||
| /// Reload the PBS state with the latest configuration in the config file | ||
| /// Returns 200 if successful or 500 if failed | ||
| pub async fn reload<S: BuilderApiState>(state: PbsStateGuard<S>) -> eyre::Result<()> { | ||
| let prev_state = state.read().await.clone(); | ||
|
|
||
| let pbs_config = load_pbs_config().await?; | ||
| let new_state = PbsState::new(pbs_config).with_data(prev_state.data); | ||
|
|
||
| if prev_state.config.pbs_config.host != new_state.config.pbs_config.host { | ||
| warn!( | ||
| "Host change for PBS module require a full restart. Old: {}, New: {}", | ||
| prev_state.config.pbs_config.host, new_state.config.pbs_config.host | ||
| ); | ||
| } | ||
|
|
||
| if prev_state.config.pbs_config.port != new_state.config.pbs_config.port { | ||
| warn!( | ||
| "Port change for PBS module require a full restart. Old: {}, New: {}", | ||
| prev_state.config.pbs_config.port, new_state.config.pbs_config.port | ||
| ); | ||
| } | ||
|
|
||
| *state.write().await = new_state; | ||
|
|
||
| Ok(()) | ||
| } |
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| mod get_header; | ||
| mod register_validator; | ||
| mod reload; | ||
| mod router; | ||
| mod status; | ||
| mod submit_block; | ||
|
|
||
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,45 @@ | ||
| use axum::{extract::State, http::HeaderMap, response::IntoResponse}; | ||
| use cb_common::{pbs::BuilderEvent, utils::get_user_agent}; | ||
| use reqwest::StatusCode; | ||
| use tracing::{error, info}; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::{ | ||
| error::PbsClientError, | ||
| metrics::BEACON_NODE_STATUS, | ||
| state::{BuilderApiState, PbsStateGuard}, | ||
| BuilderApi, RELOAD_ENDPOINT_TAG, | ||
| }; | ||
|
|
||
| #[tracing::instrument(skip_all, name = "reload", fields(req_id = %Uuid::new_v4()))] | ||
| pub async fn handle_reload<S: BuilderApiState, A: BuilderApi<S>>( | ||
| req_headers: HeaderMap, | ||
| State(state): State<PbsStateGuard<S>>, | ||
| ) -> Result<impl IntoResponse, PbsClientError> { | ||
| let prev_state = state.read().await.clone(); | ||
|
|
||
| prev_state.publish_event(BuilderEvent::ReloadEvent); | ||
|
|
||
| let ua = get_user_agent(&req_headers); | ||
|
|
||
| info!(ua, relay_check = prev_state.config.pbs_config.relay_check); | ||
|
|
||
| match A::reload(state.clone()).await { | ||
| Ok(_) => { | ||
ltitanb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| state.read().await.publish_event(BuilderEvent::ReloadResponse); | ||
| info!("config reload successful"); | ||
|
|
||
| BEACON_NODE_STATUS.with_label_values(&["200", RELOAD_ENDPOINT_TAG]).inc(); | ||
| Ok((StatusCode::OK, "OK")) | ||
| } | ||
| Err(err) => { | ||
| error!(%err, "config reload failed"); | ||
|
|
||
| let err = PbsClientError::Internal; | ||
| BEACON_NODE_STATUS | ||
| .with_label_values(&[err.status_code().as_str(), RELOAD_ENDPOINT_TAG]) | ||
| .inc(); | ||
| Err(err) | ||
| } | ||
| } | ||
| } | ||
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
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
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.