-
Notifications
You must be signed in to change notification settings - Fork 176
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
feat: reduce block interval poc #265
base: develop
Are you sure you want to change the base?
Changes from all commits
34b9560
3b0be5f
8520a2f
a717b8c
618dbe0
7115b2a
6ef4b4a
7a188bc
a67eb4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
RenRick marked this conversation as resolved.
Show resolved
Hide resolved
|
RenRick marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,13 @@ import ( | |
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
|
||
"github.com/ethereum-optimism/optimism/op-node/rollup" | ||
"github.com/ethereum-optimism/optimism/op-service/bsc" | ||
"github.com/ethereum-optimism/optimism/op-service/eth" | ||
"github.com/ethereum-optimism/optimism/op-service/predeploys" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
var ( | ||
|
@@ -85,6 +84,7 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex | |
return nil, NewCriticalError(fmt.Errorf("failed to derive some deposits: %w", err)) | ||
} | ||
// apply sysCfg changes | ||
// TODO: may need to pass l1origin milli-timestamp later if IsEcotone() use the milli-timestamp | ||
if err := UpdateSystemConfigWithL1Receipts(&sysConfig, receipts, ba.rollupCfg, info.Time()); err != nil { | ||
return nil, NewCriticalError(fmt.Errorf("failed to apply derived L1 sysCfg updates: %w", err)) | ||
} | ||
|
@@ -107,7 +107,7 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex | |
|
||
// Calculate bsc block base fee | ||
var l1BaseFee *big.Int | ||
if ba.rollupCfg.IsSnow(l2Parent.Time + ba.rollupCfg.BlockTime) { | ||
if ba.rollupCfg.IsSnow((l2Parent.MillisecondTimestamp() + ba.rollupCfg.MillisecondBlockInterval()) / 1000) { | ||
l1BaseFee, err = SnowL1GasPrice(ctx, ba, epoch) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -124,29 +124,29 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex | |
l1Info = bsc.NewBlockInfoBSCWrapper(l1Info, l1BaseFee) | ||
|
||
// Sanity check the L1 origin was correctly selected to maintain the time invariant between L1 and L2 | ||
nextL2Time := l2Parent.Time + ba.rollupCfg.BlockTime | ||
if nextL2Time < l1Info.Time() { | ||
nextL2MilliTime := l2Parent.MillisecondTimestamp() + ba.rollupCfg.MillisecondBlockInterval() | ||
if nextL2MilliTime < l1Info.MillisecondTimestamp() { | ||
return nil, NewResetError(fmt.Errorf("cannot build L2 block on top %s for time %d before L1 origin %s at time %d", | ||
l2Parent, nextL2Time, eth.ToBlockID(l1Info), l1Info.Time())) | ||
l2Parent, nextL2MilliTime, eth.ToBlockID(l1Info), l1Info.MillisecondTimestamp())) | ||
} | ||
|
||
var upgradeTxs []hexutil.Bytes | ||
if ba.rollupCfg.IsEcotoneActivationBlock(nextL2Time) { | ||
if ba.rollupCfg.IsEcotoneActivationBlock(nextL2MilliTime / 1000) { | ||
upgradeTxs, err = EcotoneNetworkUpgradeTransactions() | ||
if err != nil { | ||
return nil, NewCriticalError(fmt.Errorf("failed to build ecotone network upgrade txs: %w", err)) | ||
} | ||
} | ||
|
||
if ba.rollupCfg.IsFjordActivationBlock(nextL2Time) { | ||
if ba.rollupCfg.IsFjordActivationBlock(nextL2MilliTime / 1000) { | ||
fjord, err := FjordNetworkUpgradeTransactions() | ||
if err != nil { | ||
return nil, NewCriticalError(fmt.Errorf("failed to build fjord network upgrade txs: %w", err)) | ||
} | ||
upgradeTxs = append(upgradeTxs, fjord...) | ||
} | ||
|
||
l1InfoTx, err := L1InfoDepositBytes(ba.rollupCfg, sysConfig, seqNumber, l1Info, nextL2Time) | ||
l1InfoTx, err := L1InfoDepositBytes(ba.rollupCfg, sysConfig, seqNumber, l1Info, nextL2MilliTime) | ||
if err != nil { | ||
return nil, NewCriticalError(fmt.Errorf("failed to create l1InfoTx: %w", err)) | ||
} | ||
|
@@ -157,28 +157,29 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex | |
txs = append(txs, upgradeTxs...) | ||
|
||
var withdrawals *types.Withdrawals | ||
if ba.rollupCfg.IsCanyon(nextL2Time) { | ||
if ba.rollupCfg.IsCanyon(nextL2MilliTime / 1000) { | ||
withdrawals = &types.Withdrawals{} | ||
} | ||
|
||
var parentBeaconRoot *common.Hash | ||
if ba.rollupCfg.IsEcotone(nextL2Time) { | ||
if ba.rollupCfg.IsEcotone(nextL2MilliTime / 1000) { | ||
parentBeaconRoot = l1Info.ParentBeaconRoot() | ||
if parentBeaconRoot == nil { // default to zero hash if there is no beacon-block-root available | ||
parentBeaconRoot = new(common.Hash) | ||
} | ||
} | ||
|
||
return ð.PayloadAttributes{ | ||
Timestamp: hexutil.Uint64(nextL2Time), | ||
pa := ð.PayloadAttributes{ | ||
PrevRandao: eth.Bytes32(l1Info.MixDigest()), | ||
SuggestedFeeRecipient: predeploys.SequencerFeeVaultAddr, | ||
Transactions: txs, | ||
NoTxPool: true, | ||
GasLimit: (*eth.Uint64Quantity)(&sysConfig.GasLimit), | ||
Withdrawals: withdrawals, | ||
ParentBeaconBlockRoot: parentBeaconRoot, | ||
}, nil | ||
} | ||
pa.SetMillisecondTimestamp(nextL2MilliTime) | ||
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. SetMillisecondTimestamp(common.hash, millseconds) -> set millseconds to first common.hash. then the return value to init eth.PayloadAttributes in 173 line, may be better. |
||
return pa, nil | ||
} | ||
|
||
func (ba *FetchingAttributesBuilder) CachePayloadByHash(payload *eth.ExecutionPayloadEnvelope) bool { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ func (bq *BatchQueue) NextBatch(ctx context.Context, parent eth.L2BlockRef) (*Si | |
if len(bq.nextSpan) > 0 { | ||
// There are cached singular batches derived from the span batch. | ||
// Check if the next cached batch matches the given parent block. | ||
if bq.nextSpan[0].Timestamp == parent.Time+bq.config.BlockTime { | ||
if bq.nextSpan[0].Timestamp == parent.MillisecondTimestamp()+bq.config.MillisecondBlockInterval() { | ||
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. if the Timestamp is changed to milliseconds for seconds, add one note that it is active after hard fork, otherwise it is seconds. |
||
// Pop first one and return. | ||
nextBatch := bq.popNextBatch(parent) | ||
// len(bq.nextSpan) == 0 means it's the last batch of the span. | ||
|
@@ -257,7 +257,7 @@ func (bq *BatchQueue) deriveNextBatch(ctx context.Context, outOfData bool, paren | |
// Find the first-seen batch that matches all validity conditions. | ||
// We may not have sufficient information to proceed filtering, and then we stop. | ||
// There may be none: in that case we force-create an empty batch | ||
nextTimestamp := parent.Time + bq.config.BlockTime | ||
nextMilliTimestamp := parent.MillisecondTimestamp() + bq.config.MillisecondBlockInterval() | ||
var nextBatch *BatchWithL1InclusionBlock | ||
|
||
// Go over all batches, in order of inclusion, and find the first batch we can accept. | ||
|
@@ -304,7 +304,7 @@ batchLoop: | |
firstOfEpoch := epoch.Number == parent.L1Origin.Number+1 | ||
|
||
bq.log.Trace("Potentially generating an empty batch", | ||
"expiryEpoch", expiryEpoch, "forceEmptyBatches", forceEmptyBatches, "nextTimestamp", nextTimestamp, | ||
"expiryEpoch", expiryEpoch, "forceEmptyBatches", forceEmptyBatches, "next_ms_timestamp", nextMilliTimestamp, | ||
"epoch_time", epoch.Time, "len_l1_blocks", len(bq.l1Blocks), "firstOfEpoch", firstOfEpoch) | ||
|
||
if !forceEmptyBatches { | ||
|
@@ -321,20 +321,20 @@ batchLoop: | |
// Fill with empty L2 blocks of the same epoch until we meet the time of the next L1 origin, | ||
// to preserve that L2 time >= L1 time. If this is the first block of the epoch, always generate a | ||
// batch to ensure that we at least have one batch per epoch. | ||
if nextTimestamp < nextEpoch.Time || firstOfEpoch { | ||
bq.log.Info("Generating next batch", "epoch", epoch, "timestamp", nextTimestamp) | ||
if nextMilliTimestamp < nextEpoch.MillisecondTimestamp() || firstOfEpoch { | ||
bq.log.Info("Generating next batch", "epoch", epoch, "timestamp", nextMilliTimestamp) | ||
return &SingularBatch{ | ||
ParentHash: parent.Hash, | ||
EpochNum: rollup.Epoch(epoch.Number), | ||
EpochHash: epoch.Hash, | ||
Timestamp: nextTimestamp, | ||
Timestamp: nextMilliTimestamp, | ||
RenRick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Transactions: nil, | ||
}, nil | ||
} | ||
|
||
// At this point we have auto generated every batch for the current epoch | ||
// that we can, so we can advance to the next epoch. | ||
bq.log.Trace("Advancing internal L1 blocks", "next_timestamp", nextTimestamp, "next_epoch_time", nextEpoch.Time) | ||
bq.log.Trace("Advancing internal L1 blocks", "next_ms_timestamp", nextMilliTimestamp, "next_epoch_ms_time", nextEpoch.MillisecondTimestamp()) | ||
bq.l1Blocks = bq.l1Blocks[1:] | ||
return nil, io.EOF | ||
} |
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.
L2BlockRef
as the l2BlockRefFromBlockAndL1Info return value, it is only used to mertics, so it is useless for adding the milliPart.