Skip to content

Commit

Permalink
add helper functions for Milliseconds datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
fahimahmedx committed Jul 24, 2024
1 parent 0cc2555 commit 9a04f5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions op-e2e/op_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (d *OpGeth) StartBlockBuilding(ctx context.Context, attrs *eth.PayloadAttri
// CreatePayloadAttributes creates a valid PayloadAttributes containing a L1Info deposit transaction followed by the supplied transactions.
func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.PayloadAttributes, error) {
timestamp := timeint.FromHexUint64MilliToMilli(d.L2Head.Milliseconds + 2*1000) // assumes two second blocktimes
l1Info, err := derive.L1InfoDepositBytes(d.l2Engine.RollupConfig(), d.SystemConfig, d.sequenceNum, d.L1Head, timestamp.ToMilliseconds())
l1Info, err := derive.L1InfoDepositBytes(d.l2Engine.RollupConfig(), d.SystemConfig, d.sequenceNum, d.L1Head, timestamp)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.Payloa
GasLimit: (*eth.Uint64Quantity)(&d.SystemConfig.GasLimit),
Withdrawals: withdrawals,
ParentBeaconBlockRoot: parentBeaconBlockRoot,
Milliseconds: eth.Uint64Quantity(timestamp.toUint64Milli()),
Milliseconds: eth.Uint64Quantity(timestamp.ToUint64Milli()),
}
return &attrs, nil
}
13 changes: 13 additions & 0 deletions op-service/timeint/timeint.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ func FromHexUint64SecToMilli(t hexutil.Uint64) Milliseconds {
return s
}

func FromUint64MilliToMilli(t uint64) Milliseconds {
return Milliseconds(t)
}

func FromHexUint64MilliToMilli(t hexutil.Uint64) Milliseconds {
return Milliseconds(t)
}

func (t Milliseconds) ToUint64Milli() uint64 {
return uint64(t)
}

// This function is not reccomended as it truncates the timestamp.
func (t Milliseconds) ToUint64Sec() uint64 {
return uint64(t / 1000)
}
2 changes: 1 addition & 1 deletion op-wheel/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +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()),
Milliseconds: hexutil.Uint64(timestamp.ToMilliseconds().ToUint64Milli()),
}

ver := evp.ForkchoiceUpdatedVersion(pa)
Expand Down

0 comments on commit 9a04f5f

Please sign in to comment.