Skip to content

Commit

Permalink
exception type and other util
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Aug 16, 2023
1 parent 3d066f2 commit ed1abac
Show file tree
Hide file tree
Showing 37 changed files with 825 additions and 280 deletions.
1 change: 0 additions & 1 deletion hildr-batcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ tasks.withType(JavaExec).configureEach {

dependencies {
implementation project(':hildr-utilities')
implementation('net.osslabz.evm:evm-abi-decoder:0.0.6')
implementation 'com.github.gestalt-config:gestalt-core:0.20.4'
implementation 'com.github.gestalt-config:gestalt-toml:0.20.4'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.common.util.concurrent.AbstractExecutionThreadService;
import io.optimism.batcher.channel.ChannelManager;
import io.optimism.batcher.config.Config;
import io.optimism.batcher.ex.BatcherExecutionException;
import io.optimism.batcher.exception.BatcherExecutionException;
import io.optimism.batcher.loader.BlockLoader;
import io.optimism.batcher.loader.LoaderConfig;
import io.optimism.batcher.publisher.ChannelDataPublisher;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 q315xia@163.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.optimism.batcher.channel;

/**
* Batcher Channel Exception class.
*
* @author thinkAfCod
* @since 0.1.1
*/
public class ChannelException extends RuntimeException {

/**
* Instantiates a new ChannelException.
*
* @param message the message
*/
public ChannelException(String message) {
super(message);
}

/**
* Instantiates a new ChannelException.
*
* @param message the message
* @param cause the cause
*/
public ChannelException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new ChannelException.
*
* @param cause the cause
*/
public ChannelException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 q315xia@163.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.optimism.batcher.channel;

/**
* ChannelFullException class.
*
* @author thinkAfCod
* @since 0.1.1
*/
public class ChannelFullException extends ChannelException {

/**
* Instantiates a new ChannelFullException.
*
* @param message the message
*/
public ChannelFullException(String message) {
super(message);
}

/**
* Instantiates a new ChannelFullException.
*
* @param message the message
* @param cause the cause
*/
public ChannelFullException(String message, Throwable cause) {
super(message, cause);
}

/**
* Instantiates a new ChannelFullException.
*
* @param cause the cause
*/
public ChannelFullException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.optimism.batcher.channel;

import io.optimism.batcher.ex.ReorgException;
import io.optimism.type.BlockId;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* specific language governing permissions and limitations under the License.
*/

package io.optimism.batcher.ex;
package io.optimism.batcher.channel;

/**
* ReorgException class. Throws this when chain occurs reorg.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package io.optimism.batcher.compressor;

import java.io.Closeable;
import java.io.Flushable;

/**
* Tx data bytes compressor interface.
*
* @author thinkAfCod
* @since 0.1.1
*/
public interface Compressor extends Closeable, Readable, Flushable {
public interface Compressor extends Closeable {

/**
* write uncompressed data which will be compressed. Should return CompressorFullException if the
Expand Down Expand Up @@ -59,6 +58,8 @@ public interface Compressor extends Closeable, Readable, Flushable {
* returns CompressorFullException if the compressor is known to be full. Note that calls to Write
* will fail if an error is returned from this method, but calls to Write can still return
* CompressorFullErr even if this does not.
*
* @return return true if compressed data length reached the limit, otherwise return false
*/
void fullErr();
boolean isFull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,37 @@

package io.optimism.batcher.compressor;

import io.optimism.batcher.config.Config;

/**
* Compressor Config.
*
* @author thinkAfCod
* @since 0.1.1
* @param targetFrameSize To target when creating channel frames. Note that if the realized
* compression ratio is worse than the approximate, more frames may actually be created. This
* also depends on how close the target is to the max frame size.
* @param targetNumFrame To create in this channel. If the realized compression ratio is worse than
* @param targetNumFrames To create in this channel. If the realized compression ratio is worse than
* approxComprRatio, additional leftover frame(s) might get created.
* @param approxComprRatio ApproxComprRatio to assume. Should be slightly smaller than average from
* experiments to avoid the chances of creating a small additional leftover frame.
* @param kind Kind of compressor to use. Must be one of KindKeys. If unset, NewCompressor will
* default to RatioKind.
* @author thinkAfCod
* @since 0.1.1
*/
public record Config(
long targetFrameSize, int targetNumFrame, double approxComprRatio, String kind) {}
public record CompressorConfig(
int targetFrameSize, int targetNumFrames, String approxComprRatio, String kind) {

/**
* Create CompressorConfig instance from Config instance.
*
* @param config Config instance
* @return CompressorConfig instance
*/
public static CompressorConfig from(Config config) {
return new CompressorConfig(
config.targetFrameSize(),
config.targetNumFrames(),
config.approxComprRatio(),
Compressors.RatioKind);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,33 @@

package io.optimism.batcher.compressor;

import io.optimism.batcher.exception.UnsupportedException;

/**
* Compressor create tool.
*
* @author thinkAfCod
* @since 0.1.1
*/
public interface Compressors {
public class Compressors {

/** Kind type of ratio. */
String RatioKind = "ratio";
public static final String RatioKind = "ratio";

/** Kind type of shadow. */
String ShadowKind = "shadow";
private Compressors() {}

/**
* Create Compressor by kind.
*
* @param kind Type of Compressor
* @param config Config of compressor
* @return a compressor
*/
default void create(String kind) {}
public static Compressor create(final CompressorConfig config) {
String kind = config.kind();
if (kind.equalsIgnoreCase(RatioKind)) {
return new RatioCompressor(config);
} else {
throw new UnsupportedException(String.format("unsupported kind: %s", kind));
}
}
}
Loading

0 comments on commit ed1abac

Please sign in to comment.