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

sync status api and rollup config api #53

Merged
merged 6 commits into from
Nov 4, 2023
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
25 changes: 14 additions & 11 deletions hildr-batcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id "com.diffplug.spotless" version "6.19.0"
id "net.ltgt.errorprone" version "3.1.0"
id 'org.graalvm.buildtools.native' version '0.9.22'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group = 'io.optimism'
Expand Down Expand Up @@ -46,6 +47,11 @@ tasks.withType(JavaExec).configureEach {
jvmArgs += ["--add-modules", "jdk.incubator.concurrent"]
}

tasks.withType(Test).configureEach {
jvmArgs += "--enable-preview"
jvmArgs += ["--add-modules", "jdk.incubator.concurrent"]
}

dependencies {
implementation project(':hildr-utilities')
implementation 'com.github.gestalt-config:gestalt-core:0.20.4'
Expand Down Expand Up @@ -93,12 +99,11 @@ dependencies {
exclude group: 'org.apache.tuweni', module: 'tuweni-rlp'
exclude group: 'org.apache.tuweni', module: 'tuweni-crypto'
}
implementation 'org.bouncycastle:bcprov-jdk18on:1.76'

implementation 'info.picocli:picocli:4.7.3'
annotationProcessor 'info.picocli:picocli-codegen:4.7.3'

implementation 'io.tmio:tuweni-crypto:2.4.2'

// implementation fileTree(dir: '../lib', include: '*.jar')
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
Expand Down Expand Up @@ -238,7 +243,6 @@ tasks.withType(Test).configureEach {
"-Djunit.platform.reporting.open.xml.enabled=true",
"-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}",
"--enable-preview",
"--add-modules jdk.incubator.concurrent"
]
} as CommandLineArgumentProvider)
}
Expand All @@ -259,17 +263,16 @@ javadoc {
}

jar {
dependsOn(configurations.runtimeClasspath)
enabled = false
manifest {
attributes "Main-Class": "io.optimism.HildrBatcher"
attributes "Main-Class": "io.optimism.batcher.HildrBatcher"
attributes "Multi-Release": "true"
}
dependsOn(shadowJar)
}

duplicatesStrategy = DuplicatesStrategy.WARN
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.SF'
}
shadowJar {
archiveFileName = "${project.name}-${project.version}.jar"
}

nativeCompile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public BatcherSubmitter(Config config) {
this.channelManager =
new ChannelManager(ChannelConfig.from(config), CompressorConfig.from(config));
this.blockLoader = new BlockLoader(LoaderConfig.from(config), this.channelManager::addL2Block);

this.blockLoader.init();
this.channelPublisher =
new ChannelDataPublisher(
PublisherConfig.from(config, this.blockLoader.getRollConfig()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.optimism.batcher.channel;

import io.optimism.batcher.compressor.Compressor;
import io.optimism.batcher.compressor.exception.CompressorException;
import io.optimism.batcher.exception.UnsupportedException;
import io.optimism.batcher.telemetry.BatcherMetrics;
import io.optimism.type.BlockId;
Expand Down Expand Up @@ -128,9 +129,10 @@ public L1BlockInfo addBlock(final EthBlock.Block block) {
try {
this.addBatch(batch);
this.blocks.add(block);
} catch (ChannelFullException e) {
} catch (ChannelFullException | CompressorException e) {
this.isFull = true;
}
this.splitToFrame();
this.updateSeqWindowTimeout(batch);
return l1Info;
}
Expand Down Expand Up @@ -312,6 +314,7 @@ private Tuple2<L1BlockInfo, Batch> blockToBatch(EthBlock.Block block) {
if (!DEPOSIT_TX_TYPE.equalsIgnoreCase(depositTxObj.getType())) {
throw new ChannelException("block txs not contains deposit tx");
}

final L1BlockInfo l1Info =
L1BlockInfo.from(Numeric.hexStringToByteArray(depositTxObj.getInput()));

Expand Down Expand Up @@ -345,8 +348,9 @@ private int addBatch(Batch batch) {
"could not add %d bytes to channel of %d bytes, max is %d",
encode.length, this.rlpLength.get(), MAX_RLP_BYTES_PER_CHANNEL));
}
int n = this.compressor.write(encode);
this.rlpLength.addAndGet(encode.length);
return this.compressor.write(encode);
return n;
}

private void closeAndOutputAllFrames() {
Expand Down Expand Up @@ -383,8 +387,9 @@ private Frame frame(final int maxSize) {
}
var lastFrameFlag = false;
var dataSize = maxSize - Frame.FRAME_V0_OVER_HEAD_SIZE;
if (dataSize > this.compressor.length()) {
dataSize = this.compressor.length();
var cprLength = this.compressor.length();
if (dataSize > cprLength) {
dataSize = cprLength;
lastFrameFlag = this.isClose;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ public Frame txData(final BlockId l1Head) {
}
// no channel
if (!this.hasSpace(this.latestChannel)) {
this.latestChannel = this.openChannel(l1Head);
this.latestChannel = this.openChannel();
LOGGER.info(
"Created a channel: id:{}, l1Head: {}, blocksPending:{}",
this.latestChannel,
l1Head,
this.blocks.size());
this.metrics.recordChannelOpened(null, this.blocks.size());
}
this.pushBlocks(this.latestChannel);
this.updateChannelTimeout(l1Head);
Expand Down Expand Up @@ -222,12 +228,8 @@ private boolean hasSpace(final Channel channel) {
return channel != null && !channel.isFull();
}

private Channel openChannel(final BlockId l1Head) {
Channel ch = new ChannelImpl(this.chConfig, Compressors.create(this.compressorConfig));
LOGGER.info(
"Created a channel: id:{}, l1Head: {}, blocksPending:{}", ch, l1Head, this.blocks.size());
this.metrics.recordChannelOpened(null, this.blocks.size());
return ch;
private Channel openChannel() {
return new ChannelImpl(this.chConfig, Compressors.create(this.compressorConfig));
}

private void pushBlocks(final Channel lastChannel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.optimism.batcher.compressor;

import io.optimism.batcher.compressor.exception.CompressorFullException;
import io.optimism.batcher.compressor.exception.CompressorException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
Expand All @@ -37,8 +37,12 @@ public class RatioCompressor implements Compressor {

private final int inputThreshold;

private final byte[] compressed;

private volatile ByteArrayOutputStream bos;

private boolean closed;

private int pos;

private int inputLength;
Expand All @@ -48,24 +52,38 @@ public class RatioCompressor implements Compressor {
this.deflater = new Deflater(Deflater.BEST_COMPRESSION);
this.inputThreshold = inputThreshold();
this.bos = new ByteArrayOutputStream(this.inputThreshold);
this.compressed = new byte[2048];
this.pos = 0;
this.inputLength = 0;
}

@Override
public int write(byte[] p) {
if (this.isFull()) {
throw new CompressorFullException("the target amount of input data has been reached limit");
throw new CompressorException("the target amount of input data has been reached limit");
}
if (this.isClose()) {
throw new CompressorException("the compressor has been closed");
}
this.inputLength += p.length;
this.deflater.setInput(p);
byte[] compressed = new byte[p.length];
int len = this.deflater.deflate(compressed);
this.bos.write(compressed, 0, len);
int len;
// int compressedLength = 0;
do {
len = this.deflater.deflate(compressed, 0, compressed.length, Deflater.SYNC_FLUSH);
if (len > 0) {
// compressedLength += len;
this.bos.write(compressed, 0, len);
}
} while (len > 0);
this.deflater.reset();
return p.length;
}

private boolean isClose() {
return this.closed;
}

@Override
public int read(byte[] p) {
byte[] data = this.bos.toByteArray();
Expand Down Expand Up @@ -105,6 +123,7 @@ public boolean isFull() {

@Override
public void close() throws IOException {
closed = true;
this.deflater.finish();
this.deflater.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
* @author thinkAfCod
* @since 0.1.1
*/
public class CompressorFullException extends RuntimeException {
public class CompressorException extends RuntimeException {

/**
* Constructor of CompressorFullException.
*
* @param message error message
*/
public CompressorFullException(String message) {
public CompressorException(String message) {
super(message);
}
}
Loading
Loading