diff --git a/eth/catalyst/api_types.go b/eth/catalyst/api_types.go index a7d20b241..8434dc97c 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..1890eee5c 100644 --- a/eth/catalyst/gen_l2blockparams.go +++ b/eth/catalyst/gen_l2blockparams.go @@ -16,9 +16,11 @@ func (a AssembleL2BlockParams) MarshalJSON() ([]byte, error) { type AssembleL2BlockParams struct { Number hexutil.Uint64 `json:"number" gencodec:"required"` Transactions []hexutil.Bytes `json:"transactions"` + Timestamp *uint64 `json:"timestamp"` } var enc AssembleL2BlockParams enc.Number = hexutil.Uint64(a.Number) + enc.Timestamp = a.Timestamp if a.Transactions != nil { enc.Transactions = make([]hexutil.Bytes, len(a.Transactions)) for k, v := range a.Transactions { @@ -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 *uint64 `json:"timestamp"` } var dec AssembleL2BlockParams if err := json.Unmarshal(input, &dec); err != nil { @@ -42,6 +45,7 @@ func (a *AssembleL2BlockParams) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'number' for AssembleL2BlockParams") } a.Number = uint64(*dec.Number) + a.Timestamp = dec.Timestamp if dec.Transactions != nil { a.Transactions = make([][]byte, len(dec.Transactions)) for k, v := range dec.Transactions { diff --git a/eth/catalyst/l2_api.go b/eth/catalyst/l2_api.go index 50a2bb1e0..f7ce192a3 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 := uint64(time.Now().Unix()) + if params.Timestamp != nil { + timestamp = *params.Timestamp + } + newBlockResult, err := api.eth.Miner().BuildBlock(parent.Hash(), timestamp, transactions) if err != nil { return nil, err } diff --git a/eth/catalyst/l2_api_test.go b/eth/catalyst/l2_api_test.go index fcacb35fd..4f79916ef 100644 --- a/eth/catalyst/l2_api_test.go +++ b/eth/catalyst/l2_api_test.go @@ -111,7 +111,7 @@ func TestValidateL2Block(t *testing.T) { // generic case err = sendTransfer(config, ethService) require.NoError(t, err) - ret, err := ethService.Miner().BuildBlock(ethService.BlockChain().CurrentHeader().Hash(), time.Now(), nil) + ret, err := ethService.Miner().BuildBlock(ethService.BlockChain().CurrentHeader().Hash(), uint64(time.Now().Unix()), nil) require.NoError(t, err) block := ret.Block l2Data := ExecutableL2Data{ @@ -170,7 +170,7 @@ func TestNewL2Block(t *testing.T) { err := sendTransfer(config, ethService) require.NoError(t, err) - ret, err := ethService.Miner().BuildBlock(ethService.BlockChain().CurrentHeader().Hash(), time.Now(), nil) + ret, err := ethService.Miner().BuildBlock(ethService.BlockChain().CurrentHeader().Hash(), uint64(time.Now().Unix()), nil) block := ret.Block require.NoError(t, err) l2Data := ExecutableL2Data{ @@ -223,7 +223,7 @@ func TestNewSafeL2Block(t *testing.T) { err := sendTransfer(config, ethService) require.NoError(t, err) - ret, err := ethService.Miner().BuildBlock(ethService.BlockChain().CurrentHeader().Hash(), time.Now(), nil) + ret, err := ethService.Miner().BuildBlock(ethService.BlockChain().CurrentHeader().Hash(), uint64(time.Now().Unix()), nil) require.NoError(t, err) block := ret.Block l2Data := SafeL2Data{ 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/miner.go b/miner/miner.go index 8328fb991..7db7319c4 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -167,9 +167,9 @@ func (miner *Miner) getSealingBlockAndState(params *generateParams) (*NewBlockRe } } -func (miner *Miner) BuildBlock(parentHash common.Hash, timestamp time.Time, transactions types.Transactions) (*NewBlockResult, error) { +func (miner *Miner) BuildBlock(parentHash common.Hash, timestamp uint64, transactions types.Transactions) (*NewBlockResult, error) { return miner.getSealingBlockAndState(&generateParams{ - timestamp: uint64(timestamp.Unix()), + timestamp: timestamp, parentHash: parentHash, transactions: transactions, timeout: miner.newBlockTimeout,