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

Remove explicit beacon endpoint and enhance eth/head endpoint instead. #27

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

luka-ethernal
Copy link
Contributor

@luka-ethernal luka-ethernal commented Aug 26, 2024

  • Create a task that periodically checks for changes in head and updates one global state value.
  • Make eth/head endpoint just read the current state instead of calling Node every time.
  • Integrate a beacon mapping into eth/head endpoint, so mapping becomes easier and atomic.
  • Implement a retry mechanism in case of errors.
  • If all retries fail, crash the entire process.
  • Introduce versioning to endpoints.

…nt from now on. Removed Beaconcha endpoint. Fix documentation. Add explicit retry settings.
src/main.rs Outdated
Comment on lines 545 to 550
.route("/versions", get(versions))
.route("/v1/info", get(info))
.route("/v1/eth/proof/:block_hash", get(get_eth_proof))
.route("/v1/eth/head", get(get_eth_head))
.route("/v1/avl/head", get(get_avl_head))
.route("/v1/avl/proof/:block_hash/:message_id", get(get_avl_proof))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing URLs will have an impact on our monitors as well.
We should run the old and new bridge API in parallel until the migration is completed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is on purpose, to let us know what else will need changing. Also, in the future, we need versioning for introducing new functionality and changing old one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luka-ethernal yes but I think @0xSasaPrsic is saying something else, it's that we also need non-v1 endpoints for a deprecation period before we fully switch over. I agree as well, we need both for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see. I was thinking we add versioning now and skip the deprecation phase since we have no external users yet (do we?). But if needed, I can do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagging @vthunder to help with a suggestion.

Copy link
Member

@QEDK QEDK Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in almost all our validium integrations, all of which are internal (some externally but private) but until we change all of them (in a month maybe?), good to retain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then I'll maintain the old endpoints till we can phase them out. I will need to change the docs as well and bring back the beacon endpoint.

src/main.rs Outdated
Comment on lines 545 to 550
.route("/versions", get(versions))
.route("/v1/info", get(info))
.route("/v1/eth/proof/:block_hash", get(get_eth_proof))
.route("/v1/eth/head", get(get_eth_head))
.route("/v1/avl/head", get(get_avl_head))
.route("/v1/avl/proof/:block_hash/:message_id", get(get_avl_proof))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luka-ethernal yes but I think @0xSasaPrsic is saying something else, it's that we also need non-v1 endpoints for a deprecation period before we fully switch over. I agree as well, we need both for now.

src/main.rs Outdated
tracing::info!("🚀 Listening on {} port {}", host, port);
axum::serve(listener, app).await.unwrap();
}

lazy_static! {
static ref SLOT_BLOCK_HEAD: Mutex<Option<(u64, u64, B256, u64)>> = Mutex::new(None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Arc<RwLock> here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that, right now, it doesn't make a huge difference, but it might in the future. Will change that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already use the parking_lot feature in tokio might be better to use parking_lot::RwLock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the tokio::sync::RwLock use parking_lot on the low level? I can also introduce parking_lot separately, but I see no need.

src/main.rs Outdated
@@ -675,30 +538,139 @@ async fn main() {
.unwrap_or(172800),
beaconchain_api_key: env::var("BEACONCHAIN_API_KEY").unwrap_or("".to_owned()),
});
tracing::info!("Config: {shared_state:?}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not log credentials to logs!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I should probably also remove the Beaconcha api key from code, since it won't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it's also the only secret in this shared state)

src/main.rs Show resolved Hide resolved
@luka-ethernal
Copy link
Contributor Author

@QEDK I've addressed all of the comments, please review them if you can.

…th/head endpoint now uses new mechanism, but has old behavior.
@luka-ethernal luka-ethernal force-pushed the luka/refactor-beacon-and-head branch from 56f5cdb to d91a81f Compare August 29, 2024 13:03
Copy link
Member

@QEDK QEDK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@luka-ethernal luka-ethernal merged commit 59022fa into main Aug 29, 2024
2 checks passed
@luka-ethernal luka-ethernal deleted the luka/refactor-beacon-and-head branch August 29, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants