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

Refactor #183

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 0 deletions hildr-batcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions hildr-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
64 changes: 64 additions & 0 deletions hildr-node/src/main/java/io/optimism/driver/NewDriver.kt
Original file line number Diff line number Diff line change
@@ -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<ExecutionPayloadEnvelop> = Channel(10),
private val l1HeadSignal: Channel<L1BlockRef> = Channel(10),
private val l1SafeSignal: Channel<L1BlockRef> = Channel(10),
private val l1FinalizedSignal: Channel<L1BlockRef> = Channel(10),
private val config: Config,
) : AbstractVerticle(), Handler<Message<Event?>?> {

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<Event?>?) {
}
}
Original file line number Diff line number Diff line change
@@ -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<Message<Event>> {
override fun handle(event: Message<Event>) {
TODO("Not yet implemented")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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";
}
}
21 changes: 21 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/DebugDeriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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<E extends Event> implements Deriver {

private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(DebugDeriver.class);

@Override
@Subscribe
public void onEvent(Event event) {
LOGGER.debug("Event: {}", event);
}
}
17 changes: 17 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/Deriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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);
}
30 changes: 30 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/DeriverFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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<Event, Void> function;

/**
* Instantiates a new Deriver function.
*
* @param function the function
*/
public DeriverFunction(Function<Event, Void> function) {
this.function = function;
}

@Override
@Subscribe
public void onEvent(Event event) {
function.apply(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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";
}
}
17 changes: 17 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/Event.java
Original file line number Diff line number Diff line change
@@ -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();
}
17 changes: 17 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/EventEmitter.java
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/EventType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.optimism.events;

/**
* The type EventType.
*
* @author grapebaba
* @since v0.4.1
*/
public enum EventType {
EngineTemporaryErrorEvent,
ResetEvent,
CriticalErrorEvent
}
17 changes: 17 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/NoopDeriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
}
}
14 changes: 14 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/NoopEmitter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
}
}
31 changes: 31 additions & 0 deletions hildr-node/src/main/java/io/optimism/events/ResetEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.optimism.events;

import com.google.common.eventbus.Subscribe;
import java.util.List;

public class SynchronousDerivers implements Deriver {

private final List<Deriver> derivers;

public SynchronousDerivers(List<Deriver> derivers) {
this.derivers = derivers;
}

@Override
@Subscribe
public void onEvent(Event event) {
for (Deriver deriver : derivers) {
deriver.onEvent(event);
}
}
}
Loading
Loading