From 40bf6ab577c329fc250f2e42a3302986d8829a9d Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Thu, 20 Jun 2024 22:31:20 +0800 Subject: [PATCH 1/2] feat:add events framework Signed-off-by: Chen Kai <281165273grape@gmail.com> --- .../optimism/events/CriticalErrorEvent.java | 32 +++++ .../java/io/optimism/events/DebugDeriver.java | 22 +++ .../main/java/io/optimism/events/Deriver.java | 19 +++ .../io/optimism/events/DeriverFunction.java | 33 +++++ .../events/EngineTemporaryErrorEvent.java | 32 +++++ .../main/java/io/optimism/events/Event.java | 17 +++ .../java/io/optimism/events/EventEmitter.java | 17 +++ .../java/io/optimism/events/EventType.java | 13 ++ .../java/io/optimism/events/NoopDeriver.java | 18 +++ .../java/io/optimism/events/NoopEmitter.java | 15 ++ .../java/io/optimism/events/ResetEvent.java | 32 +++++ .../optimism/events/SynchronousDerivers.java | 23 ++++ .../io/optimism/events/SynchronousEvents.java | 89 ++++++++++++ .../events/SynchronousDeriversTest.java | 66 +++++++++ .../events/SynchronousEventsTest.java | 130 ++++++++++++++++++ 15 files changed, 558 insertions(+) create mode 100644 hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java create mode 100644 hildr-node/src/main/java/io/optimism/events/DebugDeriver.java create mode 100644 hildr-node/src/main/java/io/optimism/events/Deriver.java create mode 100644 hildr-node/src/main/java/io/optimism/events/DeriverFunction.java create mode 100644 hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java create mode 100644 hildr-node/src/main/java/io/optimism/events/Event.java create mode 100644 hildr-node/src/main/java/io/optimism/events/EventEmitter.java create mode 100644 hildr-node/src/main/java/io/optimism/events/EventType.java create mode 100644 hildr-node/src/main/java/io/optimism/events/NoopDeriver.java create mode 100644 hildr-node/src/main/java/io/optimism/events/NoopEmitter.java create mode 100644 hildr-node/src/main/java/io/optimism/events/ResetEvent.java create mode 100644 hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java create mode 100644 hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java create mode 100644 hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java create mode 100644 hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java diff --git a/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java b/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java new file mode 100644 index 00000000..66fc3d84 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java @@ -0,0 +1,32 @@ +package io.optimism.events; + + +/** + * The type CriticalErrorEvent. + * + * @author grapebaba + * @since v0.4.1 + */ +public class CriticalErrorEvent implements Event { + + private final Throwable cause; + + /** + * Instantiates a new Reset event. + * + * @param cause the cause + */ + public CriticalErrorEvent(Throwable cause) { + this.cause = cause; + } + + @Override + public EventType getType() { + return EventType.CriticalErrorEvent; + } + + @Override + public String toString() { + return "critical-error"; + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java b/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java new file mode 100644 index 00000000..0a297691 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java @@ -0,0 +1,22 @@ +package io.optimism.events; + + +import com.google.common.eventbus.Subscribe; +import org.slf4j.Logger; + +/** + * The type DebugDeriver. + * + * @author grapebaba + * @since v0.4.1 + */ +public class DebugDeriver implements Deriver { + + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(DebugDeriver.class); + + @Override + @Subscribe + public void onEvent(Event event) { + LOGGER.debug("Event: {}", event); + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/Deriver.java b/hildr-node/src/main/java/io/optimism/events/Deriver.java new file mode 100644 index 00000000..7531b580 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/Deriver.java @@ -0,0 +1,19 @@ +package io.optimism.events; + + +/** + * The interface Deriver. + * + * @author grapebaba + * @since v0.4.1 + */ +public interface Deriver{ + + + /** + * On event. + * + * @param event the event + */ + void onEvent(Event event); +} diff --git a/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java b/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java new file mode 100644 index 00000000..92b115e4 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java @@ -0,0 +1,33 @@ +package io.optimism.events; + +import com.google.common.eventbus.Subscribe; + +import java.util.function.Function; + + +/** + * The type DeriverFunction. + * + * @author grapebaba + * @since v0.4.1 + */ +public class DeriverFunction implements Deriver { + + private final Function function; + + /** + * Instantiates a new Deriver function. + * + * @param function the function + */ + public DeriverFunction(Function function) { + this.function = function; + } + + @Override + @Subscribe + public void onEvent(Event event) { + function.apply(event); + } + +} diff --git a/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java b/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java new file mode 100644 index 00000000..84ee84bb --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java @@ -0,0 +1,32 @@ +package io.optimism.events; + + +/** + * The type EngineTemporaryErrorEvent. + * + * @author grapebaba + * @since v0.4.1 + */ +public class EngineTemporaryErrorEvent implements Event { + + private final Throwable cause; + + /** + * Instantiates a new Reset event. + * + * @param cause the cause + */ + public EngineTemporaryErrorEvent(Throwable cause) { + this.cause = cause; + } + + @Override + public EventType getType() { + return EventType.EngineTemporaryErrorEvent; + } + + @Override + public String toString() { + return "engine-temporary-error"; + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/Event.java b/hildr-node/src/main/java/io/optimism/events/Event.java new file mode 100644 index 00000000..96942ebf --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/Event.java @@ -0,0 +1,17 @@ +package io.optimism.events; + +/** + * Event interface. + * + * @author grapebaba + * @since v0.4.1 + */ +public interface Event { + + /** + * Gets type. + * + * @return the type + */ + EventType getType(); +} diff --git a/hildr-node/src/main/java/io/optimism/events/EventEmitter.java b/hildr-node/src/main/java/io/optimism/events/EventEmitter.java new file mode 100644 index 00000000..253288ed --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/EventEmitter.java @@ -0,0 +1,17 @@ +package io.optimism.events; + +/** + * The EventEmitter interface. + * + * @author grapebaba + * @since v0.4.1 + */ +public interface EventEmitter { + + /** + * Emit. + * + * @param event the event + */ + void emit(Event event); +} diff --git a/hildr-node/src/main/java/io/optimism/events/EventType.java b/hildr-node/src/main/java/io/optimism/events/EventType.java new file mode 100644 index 00000000..8f85ab95 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/EventType.java @@ -0,0 +1,13 @@ +package io.optimism.events; + +/** + * The type EventType. + * + * @author grapebaba + * @since v0.4.1 + */ +public enum EventType { + EngineTemporaryErrorEvent, + ResetEvent, + CriticalErrorEvent +} diff --git a/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java b/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java new file mode 100644 index 00000000..c288df15 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java @@ -0,0 +1,18 @@ +package io.optimism.events; + + +import com.google.common.eventbus.Subscribe; + +/** + * The type NoopDeriver. + * + * @author grapebaba + * @since v0.4.1 + */ +public class NoopDeriver implements Deriver { + @Override + @Subscribe + public void onEvent(Event event) { + // do nothing + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java b/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java new file mode 100644 index 00000000..2146e9ba --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java @@ -0,0 +1,15 @@ +package io.optimism.events; + + +/** + * The type NoopEmitter. + * + * @author grapebaba + * @since v0.4.1 + */ +public class NoopEmitter implements EventEmitter { + @Override + public void emit(Event event) { + // do nothing + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/ResetEvent.java b/hildr-node/src/main/java/io/optimism/events/ResetEvent.java new file mode 100644 index 00000000..27d6c137 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/ResetEvent.java @@ -0,0 +1,32 @@ +package io.optimism.events; + + +/** + * The type ResetEvent. + * + * @author grapebaba + * @since v0.4.1 + */ +public class ResetEvent implements Event { + + private final Throwable cause; + + /** + * Instantiates a new Reset event. + * + * @param cause the cause + */ + public ResetEvent(Throwable cause) { + this.cause = cause; + } + + @Override + public EventType getType() { + return EventType.ResetEvent; + } + + @Override + public String toString() { + return "reset-event"; + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java b/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java new file mode 100644 index 00000000..ef8fc76d --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java @@ -0,0 +1,23 @@ +package io.optimism.events; + +import com.google.common.eventbus.Subscribe; + +import java.util.List; + + +public class SynchronousDerivers implements Deriver { + + private final List derivers; + + public SynchronousDerivers(List derivers) { + this.derivers = derivers; + } + + @Override + @Subscribe + public void onEvent(Event event) { + for (Deriver deriver : derivers) { + deriver.onEvent(event); + } + } +} diff --git a/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java b/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java new file mode 100644 index 00000000..8bf18273 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java @@ -0,0 +1,89 @@ +package io.optimism.events; + +import org.slf4j.Logger; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.locks.ReentrantLock; + + +/** + * The type SynchronousEvents. + * + * @author grapebaba + * @since v0.4.1 + */ +public class SynchronousEvents implements EventEmitter { + + protected final static int SANITY_EVENT_LIMIT = 1000; + + private final static Logger LOGGER = org.slf4j.LoggerFactory.getLogger(SynchronousEvents.class); + + private final ReentrantLock lock = new ReentrantLock(); + + private final List events; + + private final Deriver root; + + private final CompletableFuture ctx; + + /** + * Instantiates a new Synchronous events. + * + * @param root the root + * @param ctx the ctx + */ + public SynchronousEvents(Deriver root, CompletableFuture ctx) { + this.root = root; + this.ctx = ctx; + this.events = new ArrayList<>(); + } + + @Override + public void emit(Event event) { + lock.lock(); + try { + if (this.ctx.isCompletedExceptionally()) { + LOGGER.warn("Context is completed exceptionally, ignore emitting event: {}", event); + return; + } + + if (events.size() >= SANITY_EVENT_LIMIT) { + LOGGER.error("Event queue is full, drop event: {}", event); + return; + } + + events.add(event); + } finally { + lock.unlock(); + } + } + + /** + * Drain. + * + * @throws Throwable the throwable + */ + public void drain() throws Throwable { + while (true) { + if (ctx.isCompletedExceptionally()) { + ctx.get(); + } + + lock.lock(); + Event firstEvent; + try { + if (events.isEmpty()) { + return; + } + + firstEvent = events.removeFirst(); + } finally { + lock.unlock(); + } + + root.onEvent(firstEvent); + } + } +} diff --git a/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java b/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java new file mode 100644 index 00000000..934a8ef2 --- /dev/null +++ b/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java @@ -0,0 +1,66 @@ +package io.optimism.events; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class SynchronousDeriversTest { + + public static class TestEvent implements Event { + + @Override + public EventType getType() { + return null; + } + + public String toString() { + return "X"; + } + } + + @Test + void testSynchronousDeriversOnEvents() { + final String[] res = {""}; + + DeriverFunction a = new DeriverFunction(event -> { + res[0] += String.format("A:%s\n", event); + return null; + }); + + DeriverFunction b = new DeriverFunction(event -> { + res[0] += String.format("B:%s\n", event); + return null; + }); + + DeriverFunction c = new DeriverFunction(event -> { + res[0] += String.format("c:%s\n", event); + return null; + }); + + + SynchronousDerivers x = new SynchronousDerivers(List.of()); + x.onEvent(new TestEvent()); + assertEquals("", res[0]); + + x = new SynchronousDerivers(List.of(a)); + x.onEvent(new TestEvent()); + assertEquals("A:X\n", res[0]); + + res[0] = ""; + x = new SynchronousDerivers(List.of(a, a)); + x.onEvent(new TestEvent()); + assertEquals("A:X\nA:X\n", res[0]); + + res[0] = ""; + x = new SynchronousDerivers(List.of(a, b)); + x.onEvent(new TestEvent()); + assertEquals("A:X\nB:X\n", res[0]); + + res[0] = ""; + x = new SynchronousDerivers(List.of(a, b, c)); + x.onEvent(new TestEvent()); + assertEquals("A:X\nB:X\nc:X\n", res[0]); + } +} \ No newline at end of file diff --git a/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java b/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java new file mode 100644 index 00000000..8fd4fb16 --- /dev/null +++ b/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java @@ -0,0 +1,130 @@ +package io.optimism.events; + +import org.junit.jupiter.api.Test; + +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +class SynchronousEventsTest { + + @Test + void testSynchronousEvents() { + final int[] count = {0}; + DeriverFunction deriver = new DeriverFunction(_ -> { + count[0]++; + return null; + }); + + CompletableFuture ctx = new CompletableFuture<>(); + SynchronousEvents synchronousEvents = new SynchronousEvents(deriver, ctx); + assertDoesNotThrow(synchronousEvents::drain); + + synchronousEvents.emit(new SynchronousDeriversTest.TestEvent()); + assertEquals(0, count[0]); + try { + synchronousEvents.drain(); + } catch (Throwable e) { + throw new RuntimeException(e); + } + assertEquals(1, count[0]); + + synchronousEvents.emit(new SynchronousDeriversTest.TestEvent()); + synchronousEvents.emit(new SynchronousDeriversTest.TestEvent()); + assertEquals(1, count[0]); + try { + synchronousEvents.drain(); + } catch (Throwable e) { + throw new RuntimeException(e); + } + assertEquals(3, count[0]); + + ctx.cancel(true); + synchronousEvents.emit(new SynchronousDeriversTest.TestEvent()); + assertThrows(CancellationException.class, synchronousEvents::drain); + assertEquals(3, count[0]); + } + + @Test + void testSynchronousEventsSanityLimit() { + final int[] count = {0}; + DeriverFunction deriver = new DeriverFunction(_ -> { + count[0]++; + return null; + }); + + CompletableFuture ctx = new CompletableFuture<>(); + SynchronousEvents synchronousEvents = new SynchronousEvents(deriver, ctx); + for (int i = 0; i < SynchronousEvents.SANITY_EVENT_LIMIT + 1; i++) { + synchronousEvents.emit(new SynchronousDeriversTest.TestEvent()); + } + assertDoesNotThrow(synchronousEvents::drain); + assertEquals(SynchronousEvents.SANITY_EVENT_LIMIT, count[0]); + + synchronousEvents.emit(new SynchronousDeriversTest.TestEvent()); + assertDoesNotThrow(synchronousEvents::drain); + assertEquals(SynchronousEvents.SANITY_EVENT_LIMIT + 1, count[0]); + } + + public static class CyclicEvent implements Event { + + private final int count; + + public CyclicEvent(int count) { + this.count = count; + } + + @Override + public EventType getType() { + return null; + } + + public String toString() { + return "cyclic-event"; + } + } + + public static class AF implements Function { + private EventEmitter emitter; + + private boolean result; + + public AF(EventEmitter emitter, boolean result) { + this.emitter = emitter; + this.result = result; + } + + @Override + public Void apply(Event e) { + System.out.printf("received event: %s%n", e); + if (e instanceof CyclicEvent) { + if (((CyclicEvent) e).count < 10) { + emitter.emit(new CyclicEvent(((CyclicEvent) e).count + 1)); + } else { + result = true; + } + } + return null; + } + } + + @Test + void testSynchronousEventsCyclic() { + final boolean result = false; + AF af = new AF(null, result); + DeriverFunction deriver = new DeriverFunction(af); + + CompletableFuture ctx = new CompletableFuture<>(); + SynchronousEvents synchronousEvents = new SynchronousEvents(deriver, ctx); + af.emitter = synchronousEvents; + synchronousEvents.emit(new CyclicEvent(0)); + assertDoesNotThrow(synchronousEvents::drain); + assertTrue(af.result); + } +} \ No newline at end of file From f08fa5fe95bdca87e2f5b689363fed884a964b19 Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Fri, 26 Jul 2024 16:10:59 +0800 Subject: [PATCH 2/2] feat:refactor hildr based latest event based driver and deriver design Signed-off-by: Chen Kai <281165273grape@gmail.com> --- hildr-batcher/build.gradle | 2 + hildr-node/build.gradle | 5 ++ .../main/java/io/optimism/driver/NewDriver.kt | 64 +++++++++++++++++++ .../optimism/driver/StepSchedulingDeriver.kt | 18 ++++++ .../optimism/events/CriticalErrorEvent.java | 1 - .../java/io/optimism/events/DebugDeriver.java | 1 - .../main/java/io/optimism/events/Deriver.java | 4 +- .../io/optimism/events/DeriverFunction.java | 3 - .../events/EngineTemporaryErrorEvent.java | 1 - .../java/io/optimism/events/NoopDeriver.java | 1 - .../java/io/optimism/events/NoopEmitter.java | 1 - .../java/io/optimism/events/ResetEvent.java | 1 - .../optimism/events/SynchronousDerivers.java | 2 - .../io/optimism/events/SynchronousEvents.java | 8 +-- .../events/SynchronousDeriversTest.java | 8 +-- .../events/SynchronousEventsTest.java | 16 ++--- hildr-proposer/build.gradle | 2 + hildr-utilities/build.gradle | 2 + settings.gradle | 3 + 19 files changed, 110 insertions(+), 33 deletions(-) create mode 100644 hildr-node/src/main/java/io/optimism/driver/NewDriver.kt create mode 100644 hildr-node/src/main/java/io/optimism/driver/StepSchedulingDeriver.kt diff --git a/hildr-batcher/build.gradle b/hildr-batcher/build.gradle index 589b8743..40f2ad0c 100644 --- a/hildr-batcher/build.gradle +++ b/hildr-batcher/build.gradle @@ -6,6 +6,7 @@ plugins { id "net.ltgt.errorprone" version "3.1.0" id 'org.graalvm.buildtools.native' version '0.9.28' id 'com.github.johnrengelman.shadow' version '8.1.1' + id 'org.jetbrains.kotlin.jvm' } group = 'io.optimism' @@ -121,6 +122,7 @@ dependencies { testImplementation("com.squareup.okhttp3:mockwebserver:5.0.0-alpha.14") errorprone("com.google.errorprone:error_prone_core:2.18.0") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } // Apply a specific Java toolchain to ease working on different environments. diff --git a/hildr-node/build.gradle b/hildr-node/build.gradle index 0b6a6a5f..19659109 100644 --- a/hildr-node/build.gradle +++ b/hildr-node/build.gradle @@ -16,6 +16,7 @@ plugins { id "net.ltgt.errorprone" version "3.1.0" id 'org.graalvm.buildtools.native' version '0.9.28' id 'com.github.johnrengelman.shadow' version '8.1.1' + id 'org.jetbrains.kotlin.jvm' // id 'org.unbroken-dome.test-sets' version '4.0.0' // id 'maven-publish' // id "io.github.gradle-nexus.publish-plugin" version "1.1.0" @@ -161,6 +162,10 @@ dependencies { testImplementation 'org.mockito:mockito-junit-jupiter:2.19.0' testImplementation("com.squareup.okhttp3:mockwebserver:5.0.0-alpha.14") + implementation 'io.vertx:vertx-core:4.5.9' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation 'io.vertx:vertx-lang-kotlin-coroutines:4.5.9' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1' } // Apply a specific Java toolchain to ease working on different environments. diff --git a/hildr-node/src/main/java/io/optimism/driver/NewDriver.kt b/hildr-node/src/main/java/io/optimism/driver/NewDriver.kt new file mode 100644 index 00000000..a32c757e --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/driver/NewDriver.kt @@ -0,0 +1,64 @@ +package io.optimism.driver + +import io.optimism.config.Config +import io.optimism.events.Event +import io.optimism.network.ExecutionPayloadEnvelop +import io.optimism.type.L1BlockRef +import io.vertx.core.AbstractVerticle +import io.vertx.core.Handler +import io.vertx.core.eventbus.Message +import kotlinx.coroutines.ObsoleteCoroutinesApi +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.ticker +import kotlinx.coroutines.selects.selectUnbiased + +/** + * Created by IntelliJ IDEA. + * Author: kaichen + * Date: 2024/7/24 + * Time: 20:59 + */ +class NewDriver( + private val unsafeL2Payloads: Channel = Channel(10), + private val l1HeadSignal: Channel = Channel(10), + private val l1SafeSignal: Channel = Channel(10), + private val l1FinalizedSignal: Channel = Channel(10), + private val config: Config, +) : AbstractVerticle(), Handler?> { + + override fun start() { + + } + + @ObsoleteCoroutinesApi + suspend fun eventLoop() { + val altSyncTicker = ticker(delayMillis = config.chainConfig.blockTime.toLong() * 1000L * 2L) + while (true) { + selectUnbiased { + unsafeL2Payloads.onReceiveCatching { + println("New driver received unsafe L2 payloads") + } + altSyncTicker.onReceiveCatching { + println("New driver received alt sync ticker") + } + l1HeadSignal.onReceiveCatching { + println("New driver received L1 head signal") + } + l1SafeSignal.onReceiveCatching { + println("New driver received L1 safe signal") + } + l1FinalizedSignal.onReceiveCatching { + println("New driver received L1 finalized signal") + } + } + } + altSyncTicker.cancel() + } + + override fun stop() { + println("New driver stopped") + } + + override fun handle(event: Message?) { + } +} diff --git a/hildr-node/src/main/java/io/optimism/driver/StepSchedulingDeriver.kt b/hildr-node/src/main/java/io/optimism/driver/StepSchedulingDeriver.kt new file mode 100644 index 00000000..8c527254 --- /dev/null +++ b/hildr-node/src/main/java/io/optimism/driver/StepSchedulingDeriver.kt @@ -0,0 +1,18 @@ +package io.optimism.driver + +import io.optimism.events.Event +import io.vertx.core.Handler +import io.vertx.core.eventbus.Message + +/** + * Created by IntelliJ IDEA. + * Author: kaichen + * Date: 2024/7/25 + * Time: 19:46 + */ +class StepSchedulingDeriver: Handler> { + override fun handle(event: Message) { + TODO("Not yet implemented") + } + +} \ No newline at end of file diff --git a/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java b/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java index 66fc3d84..a9c788f5 100644 --- a/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java +++ b/hildr-node/src/main/java/io/optimism/events/CriticalErrorEvent.java @@ -1,6 +1,5 @@ package io.optimism.events; - /** * The type CriticalErrorEvent. * diff --git a/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java b/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java index 0a297691..14eb94b7 100644 --- a/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java +++ b/hildr-node/src/main/java/io/optimism/events/DebugDeriver.java @@ -1,6 +1,5 @@ package io.optimism.events; - import com.google.common.eventbus.Subscribe; import org.slf4j.Logger; diff --git a/hildr-node/src/main/java/io/optimism/events/Deriver.java b/hildr-node/src/main/java/io/optimism/events/Deriver.java index 7531b580..90a4d41f 100644 --- a/hildr-node/src/main/java/io/optimism/events/Deriver.java +++ b/hildr-node/src/main/java/io/optimism/events/Deriver.java @@ -1,14 +1,12 @@ package io.optimism.events; - /** * The interface Deriver. * * @author grapebaba * @since v0.4.1 */ -public interface Deriver{ - +public interface Deriver { /** * On event. diff --git a/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java b/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java index 92b115e4..13437434 100644 --- a/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java +++ b/hildr-node/src/main/java/io/optimism/events/DeriverFunction.java @@ -1,10 +1,8 @@ package io.optimism.events; import com.google.common.eventbus.Subscribe; - import java.util.function.Function; - /** * The type DeriverFunction. * @@ -29,5 +27,4 @@ public DeriverFunction(Function function) { public void onEvent(Event event) { function.apply(event); } - } diff --git a/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java b/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java index 84ee84bb..d3c70b0a 100644 --- a/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java +++ b/hildr-node/src/main/java/io/optimism/events/EngineTemporaryErrorEvent.java @@ -1,6 +1,5 @@ package io.optimism.events; - /** * The type EngineTemporaryErrorEvent. * diff --git a/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java b/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java index c288df15..0a795d3b 100644 --- a/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java +++ b/hildr-node/src/main/java/io/optimism/events/NoopDeriver.java @@ -1,6 +1,5 @@ package io.optimism.events; - import com.google.common.eventbus.Subscribe; /** diff --git a/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java b/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java index 2146e9ba..3f5876dc 100644 --- a/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java +++ b/hildr-node/src/main/java/io/optimism/events/NoopEmitter.java @@ -1,6 +1,5 @@ package io.optimism.events; - /** * The type NoopEmitter. * diff --git a/hildr-node/src/main/java/io/optimism/events/ResetEvent.java b/hildr-node/src/main/java/io/optimism/events/ResetEvent.java index 27d6c137..bd53ce5a 100644 --- a/hildr-node/src/main/java/io/optimism/events/ResetEvent.java +++ b/hildr-node/src/main/java/io/optimism/events/ResetEvent.java @@ -1,6 +1,5 @@ package io.optimism.events; - /** * The type ResetEvent. * diff --git a/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java b/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java index ef8fc76d..d5a88899 100644 --- a/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java +++ b/hildr-node/src/main/java/io/optimism/events/SynchronousDerivers.java @@ -1,10 +1,8 @@ package io.optimism.events; import com.google.common.eventbus.Subscribe; - import java.util.List; - public class SynchronousDerivers implements Deriver { private final List derivers; diff --git a/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java b/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java index 8bf18273..e502ddb3 100644 --- a/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java +++ b/hildr-node/src/main/java/io/optimism/events/SynchronousEvents.java @@ -1,12 +1,10 @@ package io.optimism.events; -import org.slf4j.Logger; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; - +import org.slf4j.Logger; /** * The type SynchronousEvents. @@ -16,9 +14,9 @@ */ public class SynchronousEvents implements EventEmitter { - protected final static int SANITY_EVENT_LIMIT = 1000; + protected static final int SANITY_EVENT_LIMIT = 1000; - private final static Logger LOGGER = org.slf4j.LoggerFactory.getLogger(SynchronousEvents.class); + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(SynchronousEvents.class); private final ReentrantLock lock = new ReentrantLock(); diff --git a/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java b/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java index 934a8ef2..72e9f53e 100644 --- a/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java +++ b/hildr-node/src/test/java/io/optimism/events/SynchronousDeriversTest.java @@ -1,10 +1,9 @@ package io.optimism.events; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; class SynchronousDeriversTest { @@ -39,7 +38,6 @@ void testSynchronousDeriversOnEvents() { return null; }); - SynchronousDerivers x = new SynchronousDerivers(List.of()); x.onEvent(new TestEvent()); assertEquals("", res[0]); @@ -63,4 +61,4 @@ void testSynchronousDeriversOnEvents() { x.onEvent(new TestEvent()); assertEquals("A:X\nB:X\nc:X\n", res[0]); } -} \ No newline at end of file +} diff --git a/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java b/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java index 8fd4fb16..f3de913f 100644 --- a/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java +++ b/hildr-node/src/test/java/io/optimism/events/SynchronousEventsTest.java @@ -1,23 +1,21 @@ package io.optimism.events; -import org.junit.jupiter.api.Test; - -import java.util.concurrent.CancellationException; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; - import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; +import org.junit.jupiter.api.Test; class SynchronousEventsTest { @Test void testSynchronousEvents() { final int[] count = {0}; - DeriverFunction deriver = new DeriverFunction(_ -> { + DeriverFunction deriver = new DeriverFunction(a -> { count[0]++; return null; }); @@ -54,7 +52,7 @@ void testSynchronousEvents() { @Test void testSynchronousEventsSanityLimit() { final int[] count = {0}; - DeriverFunction deriver = new DeriverFunction(_ -> { + DeriverFunction deriver = new DeriverFunction(a -> { count[0]++; return null; }); @@ -127,4 +125,4 @@ void testSynchronousEventsCyclic() { assertDoesNotThrow(synchronousEvents::drain); assertTrue(af.result); } -} \ No newline at end of file +} diff --git a/hildr-proposer/build.gradle b/hildr-proposer/build.gradle index 741fbdc3..7a45e8f2 100644 --- a/hildr-proposer/build.gradle +++ b/hildr-proposer/build.gradle @@ -6,6 +6,7 @@ plugins { id "net.ltgt.errorprone" version "3.1.0" id 'org.graalvm.buildtools.native' version '0.9.28' id 'com.github.johnrengelman.shadow' version '8.1.1' + id 'org.jetbrains.kotlin.jvm' } group = 'io.optimism' @@ -124,6 +125,7 @@ dependencies { testImplementation("com.squareup.okhttp3:mockwebserver:5.0.0-alpha.14") errorprone("com.google.errorprone:error_prone_core:2.18.0") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } // Apply a specific Java toolchain to ease working on different environments. diff --git a/hildr-utilities/build.gradle b/hildr-utilities/build.gradle index 24cd5cd5..43998669 100644 --- a/hildr-utilities/build.gradle +++ b/hildr-utilities/build.gradle @@ -4,6 +4,7 @@ plugins { id "jacoco" id "com.diffplug.spotless" version "6.22.0" id "net.ltgt.errorprone" version "3.1.0" + id 'org.jetbrains.kotlin.jvm' } group = 'io.optimism' @@ -129,6 +130,7 @@ dependencies { else throw new IllegalStateException("Unsupported operating system: $operatingSystem"); }:$brotliVersion""") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } test { diff --git a/settings.gradle b/settings.gradle index 8acae4f0..62efdef1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,6 +12,9 @@ pluginManagement { mavenCentral() gradlePluginPortal() } + plugins { + id 'org.jetbrains.kotlin.jvm' version '2.0.0' + } } rootProject.name = 'hildr'