-
Notifications
You must be signed in to change notification settings - Fork 14
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 stages #211
Refactor stages #211
Changes from 9 commits
961dc72
627e357
13874b9
df84faf
aee3593
22e0265
ab7d361
f6710b2
6c46598
f2caba2
e1343e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,22 +369,14 @@ public static AttributesDeposited decode(String txInput) { | |
if (input.length != 260) { | ||
throw new IllegalArgumentException("bedrock deposit tx input length is not 164 bytes"); | ||
} | ||
int offset = 4; | ||
BigInteger l1BlockNum = Numeric.toBigInt(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
BigInteger l1BlockTime = Numeric.toBigInt(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
BigInteger baseFee = Numeric.toBigInt(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
String l1BlockHash = Numeric.toHexString(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
BigInteger seqNum = Numeric.toBigInt(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
String batcherHash = Numeric.toHexString(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
BigInteger l1FeeOverhead = Numeric.toBigInt(Arrays.copyOfRange(input, offset, offset + 32)); | ||
offset += 32; | ||
BigInteger l1FeeScalar = Numeric.toBigInt(Arrays.copyOfRange(input, offset, offset + 32)); | ||
BigInteger l1BlockNum = Numeric.toBigInt(Arrays.copyOfRange(input, 28, 36)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个改动之前的代码好啊,全是magic number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bedrock的有效数据位很少,现在只读有效的数据位。 |
||
BigInteger l1BlockTime = Numeric.toBigInt(Arrays.copyOfRange(input, 60, 68)); | ||
BigInteger baseFee = Numeric.toBigInt(Arrays.copyOfRange(input, 92, 100)); | ||
String l1BlockHash = Numeric.toHexString(Arrays.copyOfRange(input, 100, 132)); | ||
BigInteger seqNum = Numeric.toBigInt(Arrays.copyOfRange(input, 156, 164)); | ||
String batcherHash = Numeric.toHexString(Arrays.copyOfRange(input, 176, 196)); | ||
BigInteger l1FeeOverhead = Numeric.toBigInt(Arrays.copyOfRange(input, 196, 228)); | ||
BigInteger l1FeeScalar = Numeric.toBigInt(Arrays.copyOfRange(input, 228, 260)); | ||
return new AttributesDeposited( | ||
l1BlockNum, | ||
l1BlockTime, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.optimism.utilities; | ||
|
||
import com.google.common.cache.Cache; | ||
import com.google.common.cache.CacheBuilder; | ||
|
||
public class LruCacheProvider { | ||
|
||
static <K, V> Cache<K, V> create() { | ||
return CacheBuilder.newBuilder().maximumSize(1000L).build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic number |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.optimism.v2.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,18 @@ | ||
package io.optimism.v2.derive.datasource; | ||
|
||
import io.optimism.v2.derive.types.BlockInfo; | ||
import java.math.BigInteger; | ||
import java.util.List; | ||
import org.web3j.protocol.core.methods.response.EthBlock; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
|
||
public interface ChainProvider { | ||
|
||
EthBlock.Block headerByHash(String hash); | ||
|
||
BlockInfo blockInfoByNumber(BigInteger num); | ||
|
||
List<TransactionReceipt> receiptsByHash(String hash); | ||
|
||
EthBlock.Block blockInfoNTxsByHash(String hash); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.optimism.v2.derive.datasource; | ||
|
||
import io.optimism.types.BlockInfo; | ||
import io.optimism.v2.derive.stages.DataIter; | ||
|
||
public interface DataAvailabilityProvider { | ||
|
||
DataIter openData(BlockInfo l1Ref, String batcherAddr); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.optimism.v2.derive.datasource; | ||
|
||
import io.optimism.config.Config; | ||
import io.optimism.rpc.response.OpEthBlock; | ||
import io.optimism.types.L2BlockRef; | ||
import io.optimism.types.SystemConfig; | ||
import java.math.BigInteger; | ||
|
||
public interface L2ChainProvider { | ||
|
||
L2BlockRef l2BlockInfoByNumber(BigInteger num); | ||
|
||
OpEthBlock blockByNum(BigInteger num); | ||
|
||
SystemConfig systemConfigByNumber(BigInteger num, Config.ChainConfig chainConfig); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.optimism.v2.derive.datasource.impl; | ||
|
||
import io.optimism.v2.derive.stages.FrameQueueProvider; | ||
import io.optimism.v2.derive.stages.OriginAdvancer; | ||
import io.optimism.v2.derive.stages.OriginProvider; | ||
import io.optimism.v2.derive.stages.ResettableStage; | ||
import io.optimism.v2.derive.types.BlockInfo; | ||
import io.optimism.v2.derive.types.SystemConfig; | ||
|
||
public class L1Retrieval implements FrameQueueProvider, OriginProvider, OriginAdvancer, ResettableStage { | ||
|
||
@Override | ||
public void advanceOrigin() {} | ||
|
||
@Override | ||
public BlockInfo origin() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void reset(BlockInfo base, SystemConfig config) {} | ||
|
||
@Override | ||
public byte[] next() { | ||
return new byte[0]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package io.optimism.v2.derive.datasource.impl; | ||
|
||
import io.optimism.config.Config; | ||
import io.optimism.exceptions.ResetException; | ||
import io.optimism.v2.derive.datasource.ChainProvider; | ||
import io.optimism.v2.derive.exception.PipelineEofException; | ||
import io.optimism.v2.derive.exception.PipelineProviderException; | ||
import io.optimism.v2.derive.stages.L1RetrievalProvider; | ||
import io.optimism.v2.derive.stages.OriginAdvancer; | ||
import io.optimism.v2.derive.stages.OriginProvider; | ||
import io.optimism.v2.derive.stages.ResettableStage; | ||
import io.optimism.v2.derive.types.BlockInfo; | ||
import io.optimism.v2.derive.types.SystemConfig; | ||
import java.math.BigInteger; | ||
import java.util.List; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
|
||
public class L1Traversal implements L1RetrievalProvider, OriginProvider, OriginAdvancer, ResettableStage { | ||
|
||
private final Config.ChainConfig rollupConfig; | ||
|
||
private ChainProvider dataSource; | ||
|
||
private BlockInfo block; | ||
|
||
private boolean done; | ||
|
||
private SystemConfig curSysConfig; | ||
|
||
public L1Traversal(Config.ChainConfig rollupConfig, ChainProvider provider) { | ||
this.rollupConfig = rollupConfig; | ||
this.dataSource = provider; | ||
} | ||
|
||
@Override | ||
public BlockInfo nextL1Block() { | ||
return this.block; | ||
} | ||
|
||
@Override | ||
public String batcherAddr() { | ||
return this.curSysConfig.batcherAddr(); | ||
} | ||
|
||
@Override | ||
public void advanceOrigin() { | ||
if (this.block == null) { | ||
throw new PipelineEofException(); | ||
} | ||
|
||
var block = this.block; | ||
var nextL1Origin = this.dataSource.blockInfoByNumber(block.number().add(BigInteger.ONE)); | ||
if (nextL1Origin == null) { | ||
throw new PipelineProviderException(); | ||
} | ||
if (block.hash().equals(nextL1Origin.hash())) { | ||
throw new ResetException("reorg detected"); | ||
} | ||
|
||
List<TransactionReceipt> txReceipts = this.dataSource.receiptsByHash(nextL1Origin.hash()); | ||
updateWithReceipts( | ||
txReceipts, | ||
this.rollupConfig.systemConfigContract(), | ||
this.rollupConfig.isEcotone(nextL1Origin.timestamp())); | ||
|
||
this.block = nextL1Origin; | ||
this.done = false; | ||
|
||
this.rollupConfig.isHoloceneActivationBlock(nextL1Origin.timestamp()); | ||
} | ||
|
||
private void updateWithReceipts(List<TransactionReceipt> txReceipts, String sysConfigAddr, boolean ecotone) {} | ||
|
||
@Override | ||
public BlockInfo origin() { | ||
return this.block; | ||
} | ||
|
||
@Override | ||
public void reset(BlockInfo base, SystemConfig config) { | ||
this.block = base; | ||
this.curSysConfig = config; | ||
// metrics record stage reset for l1 traversal | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.optimism.v2.derive.datasource.impl; | ||
|
||
import io.optimism.config.Config; | ||
import io.optimism.rpc.response.OpEthBlock; | ||
import io.optimism.types.L2BlockRef; | ||
import io.optimism.types.SystemConfig; | ||
import io.optimism.v2.derive.datasource.L2ChainProvider; | ||
import java.math.BigInteger; | ||
|
||
public class L2ChainFetcher implements L2ChainProvider { | ||
@Override | ||
public L2BlockRef l2BlockInfoByNumber(BigInteger num) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public OpEthBlock blockByNum(BigInteger num) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SystemConfig systemConfigByNumber(BigInteger num, Config.ChainConfig chainConfig) { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.optimism.v2.derive.exception; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注释看起来没有原来规范,建议都用ide或者ai生成 |
||
* Exception thrown when there is an error in the pipeline. | ||
*/ | ||
public class PipelineEofException extends RuntimeException { | ||
/** Constructs a PipelineEofException. */ | ||
public PipelineEofException() { | ||
super("pipeline EOF error"); | ||
} | ||
|
||
/** | ||
* Constructs a PipelineEofException with a custom message. | ||
* | ||
* @param message the custom error message | ||
*/ | ||
public PipelineEofException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs a new PipelineEofException with the specified detail message and cause. | ||
* | ||
* @param message the detail message | ||
* @param cause the cause | ||
*/ | ||
public PipelineEofException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.optimism.v2.derive.exception; | ||
|
||
/** | ||
* Exception thrown when there is an error in the pipeline provider. | ||
*/ | ||
public class PipelineProviderException extends RuntimeException { | ||
|
||
public PipelineProviderException() { | ||
super("pipeline provider error"); | ||
} | ||
|
||
/** | ||
* Constructs a new PipelineProviderException with the specified detail message. | ||
* | ||
* @param message the detail message | ||
*/ | ||
public PipelineProviderException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs a new PipelineProviderException with the specified detail message and cause. | ||
* | ||
* @param message the detail message | ||
* @param cause the cause | ||
*/ | ||
public PipelineProviderException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.optimism.v2.derive.pipeline; | ||
|
||
public class DerivationPipeline { | ||
|
||
DerivationPipeline() {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是bug吧,应该放到单独的pr里面提交,需要立即发布版本的