diff --git a/eth/catalyst/api_types.go b/eth/catalyst/api_types.go index a7d20b241..cc5f13d98 100644 --- a/eth/catalyst/api_types.go +++ b/eth/catalyst/api_types.go @@ -41,12 +41,14 @@ type assembleBlockParamsMarshaling struct { type AssembleL2BlockParams struct { Number uint64 `json:"number" gencodec:"required"` Transactions [][]byte `json:"transactions"` + Timestamp *uint64 `json:"timestamp"` } // JSON type overrides for assembleL2BlockParams. type assembleL2BlockParamsMarshaling struct { Number hexutil.Uint64 Transactions []hexutil.Bytes + Timestamp *hexutil.Uint64 } //go:generate go run github.com/fjl/gencodec -type executableData -field-override executableDataMarshaling -out gen_ed.go diff --git a/eth/catalyst/gen_l2blockparams.go b/eth/catalyst/gen_l2blockparams.go index 332f94f06..2da97c8bf 100644 --- a/eth/catalyst/gen_l2blockparams.go +++ b/eth/catalyst/gen_l2blockparams.go @@ -16,6 +16,7 @@ func (a AssembleL2BlockParams) MarshalJSON() ([]byte, error) { type AssembleL2BlockParams struct { Number hexutil.Uint64 `json:"number" gencodec:"required"` Transactions []hexutil.Bytes `json:"transactions"` + Timestamp *hexutil.Uint64 `json:"timestamp"` } var enc AssembleL2BlockParams enc.Number = hexutil.Uint64(a.Number) @@ -25,6 +26,7 @@ func (a AssembleL2BlockParams) MarshalJSON() ([]byte, error) { enc.Transactions[k] = v } } + enc.Timestamp = (*hexutil.Uint64)(a.Timestamp) return json.Marshal(&enc) } @@ -33,6 +35,7 @@ func (a *AssembleL2BlockParams) UnmarshalJSON(input []byte) error { type AssembleL2BlockParams struct { Number *hexutil.Uint64 `json:"number" gencodec:"required"` Transactions []hexutil.Bytes `json:"transactions"` + Timestamp *hexutil.Uint64 `json:"timestamp"` } var dec AssembleL2BlockParams if err := json.Unmarshal(input, &dec); err != nil { @@ -48,5 +51,8 @@ func (a *AssembleL2BlockParams) UnmarshalJSON(input []byte) error { a.Transactions[k] = v } } + if dec.Timestamp != nil { + a.Timestamp = (*uint64)(dec.Timestamp) + } return nil } diff --git a/eth/catalyst/l2_api.go b/eth/catalyst/l2_api.go index 50a2bb1e0..2655114c3 100644 --- a/eth/catalyst/l2_api.go +++ b/eth/catalyst/l2_api.go @@ -82,7 +82,11 @@ func (api *l2ConsensusAPI) AssembleL2Block(params AssembleL2BlockParams) (*Execu } start := time.Now() - newBlockResult, err := api.eth.Miner().BuildBlock(parent.Hash(), time.Now(), transactions) + timestamp := time.Now() + if params.Timestamp != nil { + timestamp = time.Unix(int64(*params.Timestamp), 0) + } + newBlockResult, err := api.eth.Miner().BuildBlock(parent.Hash(), timestamp, transactions) if err != nil { return nil, err } diff --git a/ethclient/authclient/engine.go b/ethclient/authclient/engine.go index e8d73c202..f82a0d6da 100644 --- a/ethclient/authclient/engine.go +++ b/ethclient/authclient/engine.go @@ -12,7 +12,7 @@ import ( ) // AssembleL2Block assembles L2 Block used for L2 sequencer to propose a block in L2 consensus progress -func (ec *Client) AssembleL2Block(ctx context.Context, number *big.Int, transactions types.Transactions) (*catalyst.ExecutableL2Data, error) { +func (ec *Client) AssembleL2Block(ctx context.Context, timeStamp *uint64, number *big.Int, transactions types.Transactions) (*catalyst.ExecutableL2Data, error) { txs := make([][]byte, 0, len(transactions)) for i, tx := range transactions { bz, err := tx.MarshalBinary() @@ -25,6 +25,7 @@ func (ec *Client) AssembleL2Block(ctx context.Context, number *big.Int, transact err := ec.c.CallContext(ctx, &result, "engine_assembleL2Block", &catalyst.AssembleL2BlockParams{ Number: number.Uint64(), Transactions: txs, + Timestamp: timeStamp, }) return &result, err } diff --git a/miner/worker.go b/miner/worker.go index 0e2bd995f..fbb2ba243 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -164,7 +164,7 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error) } timestamp := genParams.timestamp - if parent.Time() >= genParams.timestamp { + if parent.Time() > genParams.timestamp { timestamp = parent.Time() + 1 } var coinBase common.Address