Skip to content

Commit

Permalink
hildr-batcher module first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod committed Jul 31, 2023
1 parent e9e560c commit c0fa81a
Show file tree
Hide file tree
Showing 15 changed files with 684 additions and 243 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Ignore Gradle build output directory
build
.DS_Store
.vscode
*/logs
*.gz
*.log

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ docker compose up -d
The docker setup contains a Grafana dashboard. To view sync progress, you can check the dashboard at `http://localhost:3000` with the username `hildr` and password `passw0rd`. Alternatively, you can view Hildr's logs by running `docker logs hildr-node --follow`.

## Contribution
To help hildr grow, follow [Contributing to hildr](CONTRIBUTING.md).
To help hildr grow, follow [Contributing to hildr](CONTRIBUTING.md).
307 changes: 307 additions & 0 deletions build.gradle

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions config/spotless/java-thinkAfCod.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright $YEAR 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.
*/

11 changes: 11 additions & 0 deletions hildr-batcher/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
group = 'io.optimism'
version = '0.1.0'

application {
// Define the main class for the application.
mainClass = 'io.optimism.HildrBatcher'
}

test {
useJUnitPlatform()
}
32 changes: 32 additions & 0 deletions hildr-batcher/src/main/java/io/optimism/HildrBatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 main method.
*
* @author thinkAfCod
* @since 2023.07
*/
public class HildrBatcher {
public static void main(String[] args) {
// todo start batcherSubmitter
// todo start server
// todo start metrics server
// todo listen close signal
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.compressor;

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

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

/**
* write uncompressed data which will be compressed. Should return CompressorFullException if the
* compressor is full and no more data should be written.
*/
int write(byte[] p);

// read compressed data; should only be called after Close.
int read(byte[] p);

// reset all written data.
void reset();

// returns an estimate of the current length of the compressed data; calling Flush will
// increase the accuracy at the expense of a poorer compression ratio.
int length();

// 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.
void fullErr();

//// Closer Close function should be called before reading any data.
// io.Closer
//// Flush flushes any uncompressed data to the compression buffer. This will result in a
//// non-optimal compression ratio.
// Flush() error

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.compressor;

/**
* Compressor Factory.
*
* @author thinkAfCod
* @since 2023.07
*/
public class CompressorFactory {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.compressor;

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

String RatioKind = "ratio";
String ShadowKind = "shadow";

default void create(String kind) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.compressor;

/**
* Compressor Config.
*
* @author thinkAfCod
* @since 2023.07
* @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
* 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.
*/
public record Config(
long targetFrameSize, int targetNumFrame, double approxComprRatio, String kind) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.compressor;

import java.io.IOException;
import java.nio.CharBuffer;
import org.jetbrains.annotations.NotNull;

/**
* RatioCompressor class.
*
* @author thinkAfCod
* @since 2023.07
*/
public class RatioCompressor implements Compressor {

RatioCompressor() {
// todo 看看有没有更高性能的工具,如果没有就使用java.util.zip.Deflater
}

@Override
public int write(byte[] p) {
return 0;
}

@Override
public int read(byte[] p) {
return 0;
}

@Override
public int read(@NotNull CharBuffer cb) throws IOException {
return 0;
}

@Override
public void reset() {}

@Override
public int length() {
return 0;
}

@Override
public void fullErr() {}

@Override
public void close() throws IOException {}

@Override
public void flush() throws IOException {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.compressor;

import java.io.IOException;
import java.nio.CharBuffer;
import org.jetbrains.annotations.NotNull;

/**
* ShadowCompressor class.
*
* @author thinkAfCod
* @since 2023.07
*/
public class ShadowCompressor implements Compressor {

@Override
public int write(byte[] p) {
return 0;
}

@Override
public int read(byte[] p) {
return 0;
}

@Override
public int read(@NotNull CharBuffer cb) throws IOException {
return 0;
}

@Override
public void reset() {}

@Override
public int length() {
return 0;
}

@Override
public void fullErr() {}

@Override
public void close() throws IOException {}

@Override
public void flush() throws IOException {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.compressor.ex;

/**
* if the compressor is full and no more data should be written or the compressor is known to be
* full.
*
* @author thinkAfCod
* @since 2023.07
*/
public class CompressorFullException extends RuntimeException {

public CompressorFullException(String message) {
super(message);
}
}
Loading

0 comments on commit c0fa81a

Please sign in to comment.