paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.99k stars 1.21k forks source link

Improve metrics hook setup #12672

Closed mattsse closed 18 hours ago

mattsse commented 2 days ago

Describe the feature

currently we do:

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/node/metrics/src/hooks.rs#L24-L26

which makes the metrics crate depend on

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/node/metrics/src/hooks.rs#L4-L4

we can improve this api with a builder API

HooksBuilder {
  Vec<Box<dyn Hook<Output = ()>>>
}

and replace the new function

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/node/metrics/src/hooks.rs#L30-L30

with something like

fn with(mut self, hook: impl Hook)

then we need to change how this type is instantiated and effectively push these:

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/node/metrics/src/hooks.rs#L36-L41

to the callsite

Additional context

No response

nils-mathieu commented 2 days ago

May I take this?