Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(taiko-client): cleanup pre-ontake proposer code #18672

Merged
merged 4 commits into from
Dec 30, 2024
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
1 change: 0 additions & 1 deletion packages/taiko-client/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ linters:
- misspell
- gosimple
- staticcheck
- revive
- staticcheck
- sqlclosecheck
- staticcheck
Expand Down
94 changes: 0 additions & 94 deletions packages/taiko-client/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
Expand Down Expand Up @@ -310,40 +309,6 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {

// ProposeTxList proposes the given transactions lists to TaikoL1 smart contract.
func (p *Proposer) ProposeTxLists(ctx context.Context, txLists []types.Transactions) error {
// Check if the current L2 chain is after ontake fork.
state, err := rpc.GetProtocolStateVariables(p.rpc.TaikoL1, &bind.CallOpts{Context: ctx})
if err != nil {
return err
}

// If the current L2 chain is before ontake fork, propose the transactions lists one by one.
if !p.chainConfig.IsOntake(new(big.Int).SetUint64(state.B.NumBlocks)) {
g, gCtx := errgroup.WithContext(ctx)
for _, txs := range txLists[:utils.Min(p.MaxProposedTxListsPerEpoch, uint64(len(txLists)))] {
nonce, err := p.rpc.L1.PendingNonceAt(ctx, p.proposerAddress)
if err != nil {
log.Error("Failed to get proposer nonce", "error", err)
break
}

log.Info("Proposer current pending nonce", "nonce", nonce)

g.Go(func() error {
if err := p.ProposeTxListLegacy(gCtx, txs); err != nil {
return err
}
p.lastProposedAt = time.Now()
return nil
})

if err := p.rpc.WaitL1NewPendingTransaction(ctx, p.proposerAddress, nonce); err != nil {
log.Error("Failed to wait for new pending transaction", "error", err)
}
}

return g.Wait()
}

// If the current L2 chain is after ontake fork, batch propose all L2 transactions lists.
if err := p.ProposeTxListOntake(ctx, txLists); err != nil {
return err
Expand All @@ -352,65 +317,6 @@ func (p *Proposer) ProposeTxLists(ctx context.Context, txLists []types.Transacti
return nil
}

// ProposeTxListLegacy proposes the given transactions list to TaikoL1 smart contract.
func (p *Proposer) ProposeTxListLegacy(
ctx context.Context,
txList types.Transactions,
) error {
txListBytes, err := rlp.EncodeToBytes(txList)
if err != nil {
return fmt.Errorf("failed to encode transactions: %w", err)
}

compressedTxListBytes, err := utils.Compress(txListBytes)
if err != nil {
return err
}

proverAddress := p.proposerAddress
if p.Config.ClientConfig.ProverSetAddress != rpc.ZeroAddress {
proverAddress = p.Config.ClientConfig.ProverSetAddress
}

ok, err := rpc.CheckProverBalance(
ctx,
p.rpc,
proverAddress,
p.TaikoL1Address,
p.protocolConfigs.LivenessBond,
)

if err != nil {
log.Warn("Failed to check prover balance", "error", err)
return err
}

if !ok {
return errors.New("insufficient prover balance")
}

txCandidate, err := p.txBuilder.BuildLegacy(
ctx,
p.IncludeParentMetaHash,
compressedTxListBytes,
)
if err != nil {
log.Warn("Failed to build TaikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err))
return err
}

if err := p.sendTx(ctx, txCandidate); err != nil {
return err
}

log.Info("📝 Propose transactions succeeded", "txs", len(txList))

metrics.ProposerProposedTxListsCounter.Add(1)
metrics.ProposerProposedTxsCounter.Add(float64(len(txList)))

return nil
}

// ProposeTxListOntake proposes the given transactions lists to TaikoL1 smart contract.
func (p *Proposer) ProposeTxListOntake(
ctx context.Context,
Expand Down
87 changes: 0 additions & 87 deletions packages/taiko-client/proposer/transaction_builder/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package builder
import (
"context"
"crypto/ecdsa"
"crypto/sha256"
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/kzg4844"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
Expand Down Expand Up @@ -58,90 +55,6 @@ func NewBlobTransactionBuilder(
}
}

// BuildLegacy implements the ProposeBlockTransactionBuilder interface.
func (b *BlobTransactionBuilder) BuildLegacy(
ctx context.Context,
includeParentMetaHash bool,
txListBytes []byte,
) (*txmgr.TxCandidate, error) {
// Check if the current L2 chain is after ontake fork.
state, err := rpc.GetProtocolStateVariables(b.rpc.TaikoL1, &bind.CallOpts{Context: ctx})
if err != nil {
return nil, err
}

if b.chainConfig.IsOntake(new(big.Int).SetUint64(state.B.NumBlocks)) {
return nil, fmt.Errorf("legacy transaction builder is not supported after ontake fork")
}

var blob = &eth.Blob{}
if err := blob.FromData(txListBytes); err != nil {
return nil, err
}

commitment, err := blob.ComputeKZGCommitment()
if err != nil {
return nil, err
}
blobHash := kzg4844.CalcBlobHashV1(sha256.New(), &commitment)

signature, err := crypto.Sign(blobHash[:], b.proposerPrivateKey)
if err != nil {
return nil, err
}
signature[64] = signature[64] + 27

var (
parentMetaHash = [32]byte{}
to = &b.taikoL1Address
data []byte
encodedParams []byte
)

// If the current proposer wants to include the parent meta hash, then fetch it from the protocol.
if includeParentMetaHash {
if parentMetaHash, err = getParentMetaHash(
ctx,
b.rpc,
new(big.Int).SetUint64(b.chainConfig.ProtocolConfigs.OntakeForkHeight),
); err != nil {
return nil, err
}
}

// ABI encode the TaikoL1.proposeBlock / ProverSet.proposeBlock parameters.
encodedParams, err = encoding.EncodeBlockParams(&encoding.BlockParams{
ExtraData: rpc.StringToBytes32(b.extraData),
Coinbase: b.l2SuggestedFeeRecipient,
ParentMetaHash: parentMetaHash,
Signature: signature,
})
if err != nil {
return nil, err
}

if b.proverSetAddress != rpc.ZeroAddress {
to = &b.proverSetAddress

data, err = encoding.ProverSetABI.Pack("proposeBlock", encodedParams, []byte{})
if err != nil {
return nil, err
}
} else {
data, err = encoding.TaikoL1ABI.Pack("proposeBlock", encodedParams, []byte{})
if err != nil {
return nil, err
}
}

return &txmgr.TxCandidate{
TxData: data,
Blobs: []*eth.Blob{blob},
To: to,
GasLimit: b.gasLimit,
}, nil
}

// BuildOntake implements the ProposeBlockTransactionBuilder interface.
func (b *BlobTransactionBuilder) BuildOntake(
ctx context.Context,
Expand Down
69 changes: 0 additions & 69 deletions packages/taiko-client/proposer/transaction_builder/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
Expand Down Expand Up @@ -55,74 +54,6 @@ func NewCalldataTransactionBuilder(
}
}

// BuildLegacy implements the ProposeBlockTransactionBuilder interface.
func (b *CalldataTransactionBuilder) BuildLegacy(
ctx context.Context,
includeParentMetaHash bool,
txListBytes []byte,
) (*txmgr.TxCandidate, error) {
// If the current proposer wants to include the parent meta hash, then fetch it from the protocol.
var (
parentMetaHash = [32]byte{}
err error
)
if includeParentMetaHash {
if parentMetaHash, err = getParentMetaHash(
ctx,
b.rpc,
new(big.Int).SetUint64(b.chainConfig.ProtocolConfigs.OntakeForkHeight),
); err != nil {
return nil, err
}
}

signature, err := crypto.Sign(crypto.Keccak256(txListBytes), b.proposerPrivateKey)
if err != nil {
return nil, err
}
signature[64] = signature[64] + 27

var (
to = &b.taikoL1Address
data []byte
)
if b.proverSetAddress != rpc.ZeroAddress {
to = &b.proverSetAddress
}

// ABI encode the TaikoL1.proposeBlock / ProverSet.proposeBlock parameters.
encodedParams, err := encoding.EncodeBlockParams(&encoding.BlockParams{
Coinbase: b.l2SuggestedFeeRecipient,
ExtraData: rpc.StringToBytes32(b.extraData),
ParentMetaHash: parentMetaHash,
Signature: signature,
})
if err != nil {
return nil, err
}

if b.proverSetAddress != rpc.ZeroAddress {
to = &b.proverSetAddress

data, err = encoding.ProverSetABI.Pack("proposeBlock", encodedParams, txListBytes)
if err != nil {
return nil, err
}
} else {
data, err = encoding.TaikoL1ABI.Pack("proposeBlock", encodedParams, txListBytes)
if err != nil {
return nil, err
}
}

return &txmgr.TxCandidate{
TxData: data,
Blobs: nil,
To: to,
GasLimit: b.gasLimit,
}, nil
}

// BuildOntake implements the ProposeBlockTransactionBuilder interface.
func (b *CalldataTransactionBuilder) BuildOntake(
ctx context.Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,64 @@ package builder

import (
"context"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/testutils"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
)

type TransactionBuilderTestSuite struct {
testutils.ClientTestSuite
calldataTxBuilder *CalldataTransactionBuilder
blobTxBuiler *BlobTransactionBuilder
}

func (s *TransactionBuilderTestSuite) SetupTest() {
s.ClientTestSuite.SetupTest()

l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

protocolConfigs, err := rpc.GetProtocolConfigs(s.RPCClient.TaikoL1, nil)
s.Nil(err)

chainConfig := config.NewChainConfig(&protocolConfigs)

s.calldataTxBuilder = NewCalldataTransactionBuilder(
s.RPCClient,
l1ProposerPrivKey,
common.HexToAddress(os.Getenv("TAIKO_L2")),
common.HexToAddress(os.Getenv("TAIKO_L1")),
common.Address{},
0,
"test",
chainConfig,
false,
)
s.blobTxBuiler = NewBlobTransactionBuilder(
s.RPCClient,
l1ProposerPrivKey,
common.HexToAddress(os.Getenv("TAIKO_L1")),
common.Address{},
common.HexToAddress(os.Getenv("TAIKO_L2")),
10_000_000,
"test",
chainConfig,
false,
)
}

func (s *TransactionBuilderTestSuite) TestBuildCalldata() {
_, err := s.calldataTxBuilder.BuildOntake(context.Background(), [][]byte{{1}, {2}})
s.Nil(err)
}

func TestTransactionBuilderTestSuite(t *testing.T) {
suite.Run(t, new(TransactionBuilderTestSuite))
}
Loading
Loading