Skip to content

Commit

Permalink
implement PayloadAttributes.Milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
fahimahmedx committed Jul 24, 2024
1 parent bf28a2c commit 0cc2555
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions op-e2e/actions/l2_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func TestL2EngineAPIBlockBuilding(gt *testing.T) {
NoTxPool: false,
GasLimit: (*eth.Uint64Quantity)(&sd.RollupCfg.Genesis.SystemConfig.GasLimit),
Withdrawals: w,
Milliseconds: eth.Uint64Quantity(nextBlockTime.ToUint64Milli()),
})
require.NoError(t, err)
require.Equal(t, fcRes.PayloadStatus.Status, eth.ExecutionValid)
Expand Down
3 changes: 2 additions & 1 deletion op-e2e/op_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,13 @@ func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.Payloa
}

attrs := eth.PayloadAttributes{
Timestamp: eth.Uint64Quantity(timestamp.ToUint64Sec()),
Timestamp: eth.Uint64Quantity(timestamp.ToSeconds().ToUint64Sec()),
Transactions: txBytes,
NoTxPool: true,
GasLimit: (*eth.Uint64Quantity)(&d.SystemConfig.GasLimit),
Withdrawals: withdrawals,
ParentBeaconBlockRoot: parentBeaconBlockRoot,
Milliseconds: eth.Uint64Quantity(timestamp.toUint64Milli()),
}
return &attrs, nil
}
2 changes: 2 additions & 0 deletions op-node/rollup/attributes/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestAttributesHandler(t *testing.T) {
Transactions: []eth.Data{a1L1Info},
NoTxPool: false,
GasLimit: &payloadA1.ExecutionPayload.GasLimit,
Milliseconds: payloadA1.ExecutionPayload.Milliseconds,
},
Parent: refA0,
IsLastInSpan: true,
Expand Down Expand Up @@ -156,6 +157,7 @@ func TestAttributesHandler(t *testing.T) {
Transactions: []eth.Data{a1L1Info},
NoTxPool: false,
GasLimit: &payloadA1Alt.ExecutionPayload.GasLimit,
Milliseconds: payloadA1Alt.ExecutionPayload.Milliseconds,
},
Parent: refA0,
IsLastInSpan: true,
Expand Down
3 changes: 3 additions & 0 deletions op-node/rollup/attributes/engine_consolidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func AttributesMatchBlock(rollupCfg *rollup.Config, attrs *eth.PayloadAttributes
if attrs.Timestamp != block.Timestamp {
return fmt.Errorf("timestamp field does not match. expected: %v. got: %v", uint64(attrs.Timestamp), block.Timestamp)
}
if attrs.Milliseconds != block.Milliseconds {
return fmt.Errorf("milliseconds field does not match. expected: %v. got: %v", uint64(attrs.Milliseconds), block.Milliseconds)
}
if attrs.PrevRandao != block.PrevRandao {
return fmt.Errorf("random field does not match. expected: %v. got: %v", attrs.PrevRandao, block.PrevRandao)
}
Expand Down
4 changes: 3 additions & 1 deletion op-node/rollup/attributes/engine_consolidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
validGasLimit = eth.Uint64Quantity(1000)
validWithdrawals = types.Withdrawals{}
validFeeRecipient = predeploys.SequencerFeeVaultAddr
validMilliseconds = eth.Uint64Quantity(123 * 1000)
)

type args struct {
Expand All @@ -45,7 +46,7 @@ func ecotoneArgs() args {
GasLimit: validGasLimit,
Withdrawals: &validWithdrawals,
FeeRecipient: validFeeRecipient,
Milliseconds: validTimestamp * 1000,
Milliseconds: validMilliseconds,
},
},
attrs: &eth.PayloadAttributes{
Expand All @@ -55,6 +56,7 @@ func ecotoneArgs() args {
ParentBeaconBlockRoot: &validParentBeaconRoot,
Withdrawals: &validWithdrawals,
SuggestedFeeRecipient: validFeeRecipient,
Milliseconds: validMilliseconds,
},
parentHash: validParentHash,
}
Expand Down
1 change: 1 addition & 0 deletions op-node/rollup/derive/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
GasLimit: (*eth.Uint64Quantity)(&sysConfig.GasLimit),
Withdrawals: withdrawals,
ParentBeaconBlockRoot: parentBeaconRoot,
Milliseconds: hexutil.Uint64(nextL2Time),
}, nil
}
1 change: 1 addition & 0 deletions op-node/rollup/derive/attributes_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestAttributesQueue(t *testing.T) {
Transactions: []eth.Data{l1InfoTx, eth.Data("foobar"), eth.Data("example")},
NoTxPool: true,
GasLimit: (*eth.Uint64Quantity)(&expectedL1Cfg.GasLimit),
Milliseconds: eth.Uint64Quantity(safeHead.Time + cfg.BlockTime),
}
attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l2Fetcher)

Expand Down
6 changes: 3 additions & 3 deletions op-node/rollup/derive/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestPreparePayloadAttributes(t *testing.T) {
attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch)
require.NoError(t, err)
require.NotNil(t, attrs)
require.Equal(t, l2Parent.Time+cfg.BlockTime, timeint.FromHexUint64SecToMilli(attrs.Timestamp))
require.Equal(t, l2Parent.Time+cfg.BlockTime, timeint.FromHexUint64MilliToMilli(attrs.Milliseconds))
require.Equal(t, eth.Bytes32(l1Info.InfoMixDigest), attrs.PrevRandao)
require.Equal(t, predeploys.SequencerFeeVaultAddr, attrs.SuggestedFeeRecipient)
require.Equal(t, 1, len(attrs.Transactions))
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestPreparePayloadAttributes(t *testing.T) {
attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch)
require.NoError(t, err)
require.NotNil(t, attrs)
require.Equal(t, l2Parent.Time+cfg.BlockTime, timeint.FromHexUint64SecToMilli(attrs.Timestamp))
require.Equal(t, l2Parent.Time+cfg.BlockTime, timeint.FromHexUint64MilliToMilli(attrs.Milliseconds))
require.Equal(t, eth.Bytes32(l1Info.InfoMixDigest), attrs.PrevRandao)
require.Equal(t, predeploys.SequencerFeeVaultAddr, attrs.SuggestedFeeRecipient)
require.Equal(t, len(l2Txs), len(attrs.Transactions), "Expected txs to equal l1 info tx + user deposit txs")
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestPreparePayloadAttributes(t *testing.T) {
attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch)
require.NoError(t, err)
require.NotNil(t, attrs)
require.Equal(t, l2Parent.Time+cfg.BlockTime, timeint.FromHexUint64SecToMilli(attrs.Timestamp))
require.Equal(t, l2Parent.Time+cfg.BlockTime, timeint.FromHexUint64MilliToMilli(attrs.Milliseconds))
require.Equal(t, eth.Bytes32(l1Info.InfoMixDigest), attrs.PrevRandao)
require.Equal(t, predeploys.SequencerFeeVaultAddr, attrs.SuggestedFeeRecipient)
require.Equal(t, 1, len(attrs.Transactions))
Expand Down
4 changes: 2 additions & 2 deletions op-node/rollup/sequencing/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,13 @@ func (d *Sequencer) startBuildingBlock() {
attrs.NoTxPool = timeint.FromHexUint64SecToSec(attrs.Timestamp) > l1Origin.Time+d.spec.MaxSequencerDrift(l1Origin.Time)

// For the Ecotone activation block we shouldn't include any sequencer transactions.
if d.rollupCfg.IsEcotoneActivationBlock(timeint.FromHexUint64SecToSec(attrs.Timestamp).ToMilliseconds()) {
if d.rollupCfg.IsEcotoneActivationBlock(timeint.FromHexUint64MilliToMilli(attrs.Milliseconds)) {
attrs.NoTxPool = true
d.log.Info("Sequencing Ecotone upgrade block")
}

// For the Fjord activation block we shouldn't include any sequencer transactions.
if d.rollupCfg.IsFjordActivationBlock(timeint.FromHexUint64SecToSec(attrs.Timestamp).ToMilliseconds()) {
if d.rollupCfg.IsFjordActivationBlock(timeint.FromHexUint64MilliToMilli(attrs.Milliseconds)) {
attrs.NoTxPool = true
d.log.Info("Sequencing Fjord upgrade block")
}
Expand Down
1 change: 1 addition & 0 deletions op-node/rollup/sequencing/sequencer_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (c *ChaoticEngine) OnEvent(ev event.Event) bool {
_, err := c.rng.Read(c.currentPayloadInfo.ID[:])
require.NoError(c.t, err)
c.currentPayloadInfo.Timestamp = timeint.FromHexUint64SecToSec(x.Attributes.Attributes.Timestamp)
c.currentPayloadInfo.Milliseconds = timeint.FromHexUint64MilliToMilli(x.Attributes.Attributes.Milliseconds)
// Move forward time, to simulate time consumption
c.clockRandomIncrement(0, time.Millisecond*300)
if c.rng.Intn(10) == 0 { // 10% chance the block start is slow
Expand Down
5 changes: 3 additions & 2 deletions op-node/rollup/sequencing/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ func (m *FakeAttributesBuilder) PreparePayloadAttributes(ctx context.Context,
Transactions: []eth.Data{encodeID(epoch)}, // simplified replacement for L1-info tx.
NoTxPool: false,
GasLimit: &gasLimit,
Milliseconds: eth.Uint64Quantity(l2Parent.Time + m.cfg.BlockTime),
}

if m.cfg.IsEcotone(timeint.FromHexUint64SecToSec(attrs.Timestamp).ToMilliseconds()) {
if m.cfg.IsEcotone(timeint.FromHexUint64MilliToMilli(attrs.Milliseconds)) {
r := testutils.RandomHash(m.rng)
attrs.ParentBeaconBlockRoot = &r
}
Expand Down Expand Up @@ -259,7 +260,7 @@ func TestSequencerBuild(t *testing.T) {
x, ok := ev.(engine.BuildStartEvent)
require.True(t, ok)
require.Equal(t, head, x.Attributes.Parent)
require.Equal(t, head.Time+deps.cfg.BlockTime, timeint.FromHexUint64SecToMilli(x.Attributes.Attributes.Timestamp))
require.Equal(t, head.Time+deps.cfg.BlockTime, timeint.FromHexUint64MilliToMilli(x.Attributes.Attributes.Milliseconds))
require.Equal(t, eth.L1BlockRef{}, x.Attributes.DerivedFrom)
sentAttributes = x.Attributes
})
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (c *Config) ForkchoiceUpdatedVersion(attr *eth.PayloadAttributes) eth.Engin
// Don't begin payload build process.
return eth.FCUV3
}
ts := timeint.FromHexUint64SecToSec(attr.Timestamp).ToMilliseconds() // Assumes attr.Timestamp is in seconds.
ts := timeint.FromHexUint64MilliToMilli(attr.Milliseconds) // Assumes attr.Timestamp is in seconds.
if c.IsEcotone(ts) {
// Cancun
return eth.FCUV3
Expand Down
6 changes: 3 additions & 3 deletions op-node/rollup/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,21 +590,21 @@ func TestForkchoiceUpdatedVersion(t *testing.T) {
name: "BeforeCanyon",
canyonTime: 10,
ecotoneTime: 20,
attrs: &eth.PayloadAttributes{Timestamp: 5},
attrs: &eth.PayloadAttributes{Timestamp: 5, Milliseconds: 5 * 1000},
expectedMethod: eth.FCUV1,
},
{
name: "Canyon",
canyonTime: 10,
ecotoneTime: 20,
attrs: &eth.PayloadAttributes{Timestamp: 15},
attrs: &eth.PayloadAttributes{Timestamp: 15, Milliseconds: 15 * 1000},
expectedMethod: eth.FCUV2,
},
{
name: "Ecotone",
canyonTime: 10,
ecotoneTime: 20,
attrs: &eth.PayloadAttributes{Timestamp: 25},
attrs: &eth.PayloadAttributes{Timestamp: 25, Milliseconds: 25 * 1000},
expectedMethod: eth.FCUV3,
},
}
Expand Down
1 change: 1 addition & 0 deletions op-program/client/l2/engineapi/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func NewBlockProcessorFromPayloadAttributes(provider BlockDataProvider, parent c
MixDigest: common.Hash(attrs.PrevRandao),
Nonce: types.EncodeNonce(0),
ParentBeaconRoot: attrs.ParentBeaconBlockRoot,
Millisecond: uint64(attrs.Milliseconds),
}

// Ecotone
Expand Down
5 changes: 5 additions & 0 deletions op-program/client/l2/engineapi/test/l2_engine_api_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func RunEngineAPITests(t *testing.T, createBackend func(t *testing.T) engineapi.
NoTxPool: true,
GasLimit: &gasLimit,
Withdrawals: w,
Milliseconds: eth.Uint64Quantity(genesis.Milliseconds + 1*1000)
})
api.assert.Error(err)
api.assert.Equal(eth.ExecutionInvalid, result.PayloadStatus.Status)
Expand Down Expand Up @@ -203,6 +204,7 @@ func RunEngineAPITests(t *testing.T, createBackend func(t *testing.T) engineapi.
Transactions: nil,
NoTxPool: true,
GasLimit: &gasLimit,
Milliseconds: eth.Uint64Quantity(genesis.Milliseconds),
})
api.assert.Error(err)
api.assert.Equal(eth.ExecutionInvalid, result.PayloadStatus.Status)
Expand All @@ -223,6 +225,7 @@ func RunEngineAPITests(t *testing.T, createBackend func(t *testing.T) engineapi.
Transactions: nil,
NoTxPool: true,
GasLimit: &gasLimit,
Milliseconds: eth.Uint64Quantity(genesis.Milliseconds - 1000),
})
api.assert.Error(err)
api.assert.Equal(eth.ExecutionInvalid, result.PayloadStatus.Status)
Expand All @@ -245,6 +248,7 @@ func RunEngineAPITests(t *testing.T, createBackend func(t *testing.T) engineapi.
Transactions: nil,
NoTxPool: true,
GasLimit: &gasLimit,
Milliseconds: eth.Uint64Quantity(genesis.Milliseconds + 1000),
})
api.assert.Error(err)
api.assert.Equal(eth.ExecutionInvalid, result.PayloadStatus.Status)
Expand Down Expand Up @@ -416,6 +420,7 @@ func (h *testHelper) startBlockBuilding(head *types.Header, newBlockTimestamp et
NoTxPool: true,
GasLimit: &gasLimit,
Withdrawals: w,
Milliseconds: newBlockTimestamp*1000,
})
h.assert.NoError(err)
h.assert.Equal(eth.ExecutionValid, result.PayloadStatus.Status)
Expand Down
3 changes: 2 additions & 1 deletion op-wheel/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func newPayloadAttributes(evp sources.EngineVersionProvider, timestamp timeint.S
Timestamp: hexutil.Uint64(timestamp.ToUint64Sec()),
PrevRandao: eth.Bytes32(prevRandao),
SuggestedFeeRecipient: feeRecipient,
Milliseconds: hexutil.Uint64(timestamp.ToUint64Milli()),
}

ver := evp.ForkchoiceUpdatedVersion(pa)
Expand Down Expand Up @@ -351,7 +352,7 @@ func CopyPayload(ctx context.Context, number uint64, copyFrom client.RPC, copyTo
func blockAsPayloadEnv(block *types.Block, evp sources.EngineVersionProvider) (*eth.ExecutionPayloadEnvelope, error) {
var canyon *timeint.Seconds
// hack: if we're calling at least FCUV2, get empty withdrawals by setting Canyon before the block time
if v := evp.ForkchoiceUpdatedVersion(&eth.PayloadAttributes{Timestamp: hexutil.Uint64(block.Time())}); v != eth.FCUV1 {
if v := evp.ForkchoiceUpdatedVersion(&eth.PayloadAttributes{Timestamp: hexutil.Uint64(block.Time()), Milliseconds: hexutil.Uint64(block.Milliseconds())}); v != eth.FCUV1 {
canyon = new(timeint.Seconds)
}
return eth.BlockAsPayloadEnv(block, canyon)
Expand Down

0 comments on commit 0cc2555

Please sign in to comment.