Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

feat(proposer): propose multiple L2 blocks in one L1 block #254

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/prysmaticlabs/prysm/v4 v4.0.1
github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.23.7
golang.org/x/sync v0.1.0
golang.org/x/sync v0.2.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
64 changes: 48 additions & 16 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/taikoxyz/taiko-client/metrics"
"github.com/taikoxyz/taiko-client/pkg/rpc"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"
)

var (
Expand Down Expand Up @@ -206,22 +207,49 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
return errNoNewTxs
}

for _, txs := range txLists {
txListBytes, err := rlp.EncodeToBytes(txs)
if err != nil {
return fmt.Errorf("failed to encode transactions: %w", err)
}
head, err := p.rpc.L1.BlockNumber(ctx)
if err != nil {
return err
}
nonce, err := p.rpc.L1.NonceAt(
ctx,
crypto.PubkeyToAddress(p.l1ProposerPrivKey.PublicKey),
new(big.Int).SetUint64(head),
)
if err != nil {
return err
}

if err := p.ProposeTxList(ctx, &encoding.TaikoL1BlockMetadataInput{
Beneficiary: p.l2SuggestedFeeRecipient,
GasLimit: uint32(sumTxsGasLimit(txs)),
TxListHash: crypto.Keccak256Hash(txListBytes),
TxListByteStart: common.Big0,
TxListByteEnd: new(big.Int).SetUint64(uint64(len(txListBytes))),
CacheTxListInfo: 0,
}, txListBytes, uint(txs.Len())); err != nil {
return fmt.Errorf("failed to propose transactions: %w", err)
}
log.Info("Proposer account information", "chainHead", head, "nonce", nonce)

g := new(errgroup.Group)
for i, txs := range txLists {
func(i int, txs types.Transactions) {
g.Go(func() error {
txListBytes, err := rlp.EncodeToBytes(txs)
if err != nil {
return fmt.Errorf("failed to encode transactions: %w", err)
}

txNonce := nonce + uint64(i)
if err := p.ProposeTxList(ctx, &encoding.TaikoL1BlockMetadataInput{
Beneficiary: p.l2SuggestedFeeRecipient,
GasLimit: uint32(sumTxsGasLimit(txs)),
TxListHash: crypto.Keccak256Hash(txListBytes),
TxListByteStart: common.Big0,
TxListByteEnd: new(big.Int).SetUint64(uint64(len(txListBytes))),
CacheTxListInfo: 0,
}, txListBytes, uint(txs.Len()), &txNonce); err != nil {
return fmt.Errorf("failed to propose transactions: %w", err)
}

return nil
})
}(i, txs)
}

if err := g.Wait(); err != nil {
return fmt.Errorf("failed to propose transactions: %w", err)
}

if p.AfterCommitHook != nil {
Expand All @@ -239,6 +267,7 @@ func (p *Proposer) ProposeTxList(
meta *encoding.TaikoL1BlockMetadataInput,
txListBytes []byte,
txNum uint,
nonce *uint64,
) error {
if p.minBlockGasLimit != nil && meta.GasLimit < uint32(*p.minBlockGasLimit) {
meta.GasLimit = uint32(*p.minBlockGasLimit)
Expand All @@ -254,6 +283,9 @@ func (p *Proposer) ProposeTxList(
if err != nil {
return err
}
if nonce != nil {
opts.Nonce = new(big.Int).SetUint64(*nonce)
}

proposeTx, err := p.rpc.TaikoL1.ProposeBlock(opts, inputs, txListBytes)
if err != nil {
Expand Down Expand Up @@ -281,7 +313,7 @@ func (p *Proposer) ProposeEmptyBlockOp(ctx context.Context) error {
TxListByteStart: common.Big0,
TxListByteEnd: common.Big0,
CacheTxListInfo: 0,
}, []byte{}, 0)
}, []byte{}, 0, nil)
}

// updateProposingTicker updates the internal proposing timer.
Expand Down
4 changes: 2 additions & 2 deletions testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ProposeInvalidTxListBytes(s *ClientTestSuite, proposer Proposer) {
TxListByteStart: common.Big0,
TxListByteEnd: new(big.Int).SetUint64(uint64(len(invalidTxListBytes))),
CacheTxListInfo: 0,
}, invalidTxListBytes, 1))
}, invalidTxListBytes, 1, nil))
}

func ProposeAndInsertEmptyBlocks(
Expand Down Expand Up @@ -65,7 +65,7 @@ func ProposeAndInsertEmptyBlocks(
TxListByteStart: common.Big0,
TxListByteEnd: new(big.Int).SetUint64(uint64(len(encoded))),
CacheTxListInfo: 0,
}, encoded, 0))
}, encoded, 0, nil))

ProposeInvalidTxListBytes(s, proposer)

Expand Down
1 change: 1 addition & 0 deletions testutils/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ type Proposer interface {
meta *encoding.TaikoL1BlockMetadataInput,
txListBytes []byte,
txNum uint,
nonce *uint64,
) error
}