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

Fix: MetricSystem is only available at start phase #106

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
releaseVersion=0.8.0-rc4.1-local
releaseVersion=0.8.0-rc4.1
besuVersion=24.10-develop-829db23
arithmetizationVersion=0.8.0-rc4
besuArtifactGroup=io.consensys.linea-besu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public abstract class AbstractLineaSharedPrivateOptionsPlugin
protected static BlockchainService blockchainService;
protected static MetricsSystem metricsSystem;

private static AtomicBoolean sharedRegisterTasksDone = new AtomicBoolean(false);
private static AtomicBoolean sharedStartTasksDone = new AtomicBoolean(false);
private static final AtomicBoolean sharedRegisterTasksDone = new AtomicBoolean(false);
private static final AtomicBoolean sharedStartTasksDone = new AtomicBoolean(false);

private BesuContext besuContext;

static {
// force the initialization of the gnark compress native library to fail fast in case of issues
Expand Down Expand Up @@ -125,12 +127,14 @@ public LineaRejectedTxReportingConfiguration rejectedTxReportingConfiguration()
public synchronized void register(final BesuContext context) {
super.register(context);

besuContext = context;

if (sharedRegisterTasksDone.compareAndSet(false, true)) {
performSharedRegisterTasksOnce(context);
}
}

protected void performSharedRegisterTasksOnce(final BesuContext context) {
protected static void performSharedRegisterTasksOnce(final BesuContext context) {
blockchainService =
context
.getService(BlockchainService.class)
Expand All @@ -139,12 +143,6 @@ protected void performSharedRegisterTasksOnce(final BesuContext context) {
new RuntimeException(
"Failed to obtain BlockchainService from the BesuContext."));

metricsSystem =
context
.getService(MetricsSystem.class)
.orElseThrow(
() -> new RuntimeException("Failed to obtain MetricSystem from the BesuContext."));

context
.getService(MetricCategoryRegistry.class)
.orElseThrow(
Expand All @@ -159,11 +157,11 @@ public void start() {
super.start();

if (sharedStartTasksDone.compareAndSet(false, true)) {
performSharedStartTasksOnce();
performSharedStartTasksOnce(besuContext);
}
}

private static void performSharedStartTasksOnce() {
private static void performSharedStartTasksOnce(final BesuContext context) {
blockchainService
.getChainId()
.ifPresentOrElse(
Expand All @@ -175,6 +173,12 @@ private static void performSharedStartTasksOnce() {
() -> {
throw new IllegalArgumentException("Chain id required");
});

metricsSystem =
context
.getService(MetricsSystem.class)
.orElseThrow(
() -> new RuntimeException("Failed to obtain MetricSystem from the BesuContext."));
}

@Override
Expand Down
Loading