Skip to content

Commit

Permalink
refactor: stages interface and base type
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod committed Sep 30, 2024
1 parent 280b82c commit 8602acb
Show file tree
Hide file tree
Showing 39 changed files with 1,098 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/io/optimism/spec/derive/datasource/BlobProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.optimism.spec.derive.datasource;

import io.optimism.types.BlobSidecar;
import io.optimism.types.BlockInfo;

import java.util.List;

public interface BlobProvider {

BlobSidecar getBlobs(BlockInfo l1Info, List<String> blobHashes);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.optimism.spec.derive.datasource;

import io.optimism.types.BlockInfo;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.TransactionReceipt;

import java.math.BigInteger;

public interface ChainProvider {

EthBlock.Block headerByHash(String hash);

BlockInfo blockInfoByNumber(BigInteger num);

TransactionReceipt receiptsByHash(String hash);

EthBlock.Block blockInfoNTxsByHash(String hash);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.optimism.spec.derive.datasource;

import io.optimism.spec.derive.stages.DataIter;
import io.optimism.types.BlockInfo;

public interface DataAvailabilityProvider {

DataIter openData(BlockInfo l1Ref, String batcherAddr);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.optimism.spec.derive.datasource;

import io.optimism.config.Config;
import io.optimism.types.ExecutionPayloadEnvelop;
import io.optimism.types.L2BlockRef;
import io.optimism.types.SystemConfig;

import java.math.BigInteger;

public interface L2ChainProvider {

L2BlockRef l2BlockInfoByNumber(BigInteger num);

ExecutionPayloadEnvelop payloadByNumber(BigInteger num);

SystemConfig systemConfigByNumber(BigInteger num, Config.ChainConfig chainConfig);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.optimism.spec.derive.datasource.impl;

import io.optimism.config.Config;
import io.optimism.spec.derive.stages.FrameQueueProvider;
import io.optimism.spec.derive.stages.OriginAdvancer;
import io.optimism.spec.derive.stages.OriginProvider;
import io.optimism.spec.derive.stages.ResettableStage;
import io.optimism.types.BlockInfo;

public class L1Retrieval implements FrameQueueProvider, OriginProvider, OriginAdvancer, ResettableStage {

@Override
public void advanceOrigin() {

}

@Override
public BlockInfo origin() {
return null;
}

@Override
public void reset(BlockInfo base, Config.SystemConfig config) {

}

@Override
public byte[] next() {
return new byte[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.optimism.spec.derive.datasource.impl;

import io.optimism.config.Config;
import io.optimism.spec.derive.stages.L1RetrievalProvider;
import io.optimism.spec.derive.stages.OriginAdvancer;
import io.optimism.spec.derive.stages.OriginProvider;
import io.optimism.spec.derive.stages.ResettableStage;
import io.optimism.types.BlockInfo;

public class L1Traversal implements L1RetrievalProvider, OriginProvider, OriginAdvancer, ResettableStage {

public L1Traversal() {

}


@Override
public BlockInfo nextL1Block() {
return null;
}

@Override
public String batcherAddr() {
return "";
}

@Override
public void advanceOrigin() {

}

@Override
public BlockInfo origin() {
return null;
}

@Override
public void reset(BlockInfo base, Config.SystemConfig config) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.optimism.spec.derive.pipeline;

public class DerivationPipeline {

DerivationPipeline() {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.optimism.spec.derive.pipeline;

public class PipelineBuilder {

public PipelineBuilder() {}

public DerivationPipeline build() {
return new DerivationPipeline();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.optimism.spec.derive.stages;

import io.optimism.spec.derive.types.L2BlockRef;
import io.optimism.spec.derive.types.OpPayloadAttributes;
import io.optimism.spec.derive.types.Epoch;

public interface AttributesBuilder {

OpPayloadAttributes preparePayloadAttr(L2BlockRef ref, Epoch epoch);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.optimism.spec.derive.stages;

import io.optimism.types.L2BlockRef;
import io.optimism.types.SingularBatch;

public interface AttributesProvider {
/**
* returns the next valid batch upon the given safe head.
* @param parent
* @return
*/
SingularBatch nextBatch(L2BlockRef parent);

/**
*
* @return
*/
boolean isLastInSpan();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.optimism.spec.derive.stages;

import io.optimism.spec.derive.types.Batch;

public interface BatchQueueProvider {

Batch nextBatch();

void flush();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.optimism.spec.derive.stages;

import io.optimism.spec.derive.types.Frame;

public interface ChannelBankProvider {

Frame nextFrame();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.optimism.spec.derive.stages;

public interface ChannelReaderProvider {

byte[] nextData();

}
7 changes: 7 additions & 0 deletions src/main/java/io/optimism/spec/derive/stages/DataIter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.optimism.spec.derive.stages;

public interface DataIter {

byte[] Next();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.optimism.spec.derive.stages;

public interface FrameQueueProvider {
byte[] next();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.optimism.spec.derive.stages;

import io.optimism.types.BlockInfo;

public interface L1RetrievalProvider {

BlockInfo nextL1Block();

String batcherAddr();

}
10 changes: 10 additions & 0 deletions src/main/java/io/optimism/spec/derive/stages/NextAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.optimism.spec.derive.stages;

import io.optimism.spec.derive.types.L2BlockRef;
import io.optimism.spec.derive.types.OpAttributesWithParent;

public interface NextAttributes {

OpAttributesWithParent nextAttr(L2BlockRef parent);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.optimism.spec.derive.stages;

public interface OriginAdvancer {
void advanceOrigin();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.optimism.spec.derive.stages;

import io.optimism.types.BlockInfo;

public interface OriginProvider {

BlockInfo origin();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.optimism.spec.derive.stages;

import io.optimism.config.Config;
import io.optimism.types.BlockInfo;

public interface ResettableStage {

void reset(BlockInfo base, Config.SystemConfig config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.optimism.spec.derive.stages.impl;

import io.optimism.config.Config;
import io.optimism.spec.derive.stages.AttributesBuilder;
import io.optimism.spec.derive.stages.NextAttributes;
import io.optimism.spec.derive.stages.OriginAdvancer;
import io.optimism.spec.derive.stages.OriginProvider;
import io.optimism.spec.derive.stages.ResettableStage;
import io.optimism.spec.derive.types.Epoch;
import io.optimism.spec.derive.types.L2BlockRef;
import io.optimism.spec.derive.types.OpAttributesWithParent;
import io.optimism.spec.derive.types.OpPayloadAttributes;
import io.optimism.types.BlockInfo;

public class AttributesQueue implements NextAttributes, OriginAdvancer, OriginProvider, ResettableStage, AttributesBuilder {
@Override
public OpPayloadAttributes preparePayloadAttr(L2BlockRef ref, Epoch epoch) {
return null;
}

@Override
public void advanceOrigin() {

}

@Override
public BlockInfo origin() {
return null;
}

@Override
public void reset(BlockInfo base, Config.SystemConfig config) {

}

@Override
public OpAttributesWithParent nextAttr(L2BlockRef parent) {
return null;
}
}
37 changes: 37 additions & 0 deletions src/main/java/io/optimism/spec/derive/stages/impl/BatchQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.optimism.spec.derive.stages.impl;

import io.optimism.config.Config;
import io.optimism.spec.derive.stages.AttributesProvider;
import io.optimism.spec.derive.stages.OriginAdvancer;
import io.optimism.spec.derive.stages.OriginProvider;
import io.optimism.spec.derive.stages.ResettableStage;
import io.optimism.types.BlockInfo;
import io.optimism.types.L2BlockRef;
import io.optimism.types.SingularBatch;

public class BatchQueue implements AttributesProvider, OriginProvider, OriginAdvancer, ResettableStage {
@Override
public SingularBatch nextBatch(L2BlockRef parent) {
return null;
}

@Override
public boolean isLastInSpan() {
return false;
}

@Override
public void advanceOrigin() {

}

@Override
public BlockInfo origin() {
return null;
}

@Override
public void reset(BlockInfo base, Config.SystemConfig config) {

}
}
36 changes: 36 additions & 0 deletions src/main/java/io/optimism/spec/derive/stages/impl/BatchStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.optimism.spec.derive.stages.impl;

import io.optimism.config.Config;
import io.optimism.spec.derive.stages.BatchQueueProvider;
import io.optimism.spec.derive.stages.OriginAdvancer;
import io.optimism.spec.derive.stages.OriginProvider;
import io.optimism.spec.derive.stages.ResettableStage;
import io.optimism.spec.derive.types.Batch;
import io.optimism.types.BlockInfo;

public class BatchStream implements BatchQueueProvider, OriginProvider, OriginAdvancer, ResettableStage {
@Override
public Batch nextBatch() {
return null;
}

@Override
public void flush() {

}

@Override
public void advanceOrigin() {

}

@Override
public BlockInfo origin() {
return null;
}

@Override
public void reset(BlockInfo base, Config.SystemConfig config) {

}
}
Loading

0 comments on commit 8602acb

Please sign in to comment.