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

Commit

Permalink
delete proposeEmptyBlockOp and fix test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored and mask-pp committed Apr 4, 2024
1 parent 233f0e8 commit b4a6182
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 186 deletions.
20 changes: 11 additions & 9 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ var (
Category: proposerCategory,
Value: 0,
}
BlockMinGasLimit = &cli.Uint64Flag{
Name: "epoch.minGasLimit",
Usage: "Minimum gas limit for a proposed block",
MinGasUsed = &cli.Uint64Flag{
Name: "epoch.minGasUsed",
Usage: "Minimum gas used for a transactions list to propose",
Category: proposerCategory,
Value: 0,
}
BlockMinTxListBytes = &cli.Uint64Flag{
MinTxListBytes = &cli.Uint64Flag{
Name: "epoch.minTxListBytes",
Usage: "Minimum bytes for a proposed transaction list",
Usage: "Minimum bytes for a transactions list to propose",
Category: proposerCategory,
Value: 0,
}
FroceProposingInternal = &cli.DurationFlag{
Name: "epoch.emptyBlockInterval",
Usage: "Time interval to propose empty blocks",
MinProposingInternal = &cli.DurationFlag{
Name: "epoch.minProposingInterval",
Usage: "Minimum time interval to force proposing a block, even if there are no transaction in mempool",
Category: proposerCategory,
Value: 0,
}
Expand Down Expand Up @@ -139,7 +139,9 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
TxPoolLocals,
TxPoolLocalsOnly,
ExtraData,
FroceProposingInternal,
MinGasUsed,
MinTxListBytes,
MinProposingInternal,
MaxProposedTxListsPerEpoch,
ProverEndpoints,
OptimisticTierFee,
Expand Down
65 changes: 64 additions & 1 deletion internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"crypto/rand"
"errors"
"fmt"
"math/big"
"net/http"
"net/url"
"os"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -21,6 +23,7 @@ import (
"github.com/phayes/freeport"

"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/pkg/rpc"
"github.com/taikoxyz/taiko-client/prover/server"
)

Expand All @@ -30,6 +33,17 @@ func (s *ClientTestSuite) ProposeInvalidTxListBytes(proposer Proposer) {
s.Nil(proposer.ProposeTxList(context.Background(), invalidTxListBytes, 1))
}

func (s *ClientTestSuite) proposeEmptyBlockOp(ctx context.Context, proposer Proposer) error {
emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{})
if err != nil {
return err
}
if err = proposer.ProposeTxList(ctx, emptyTxListBytes, 0); err != nil {
return err
}
return nil
}

func (s *ClientTestSuite) ProposeAndInsertEmptyBlocks(
proposer Proposer,
calldataSyncer CalldataSyncer,
Expand Down Expand Up @@ -58,7 +72,7 @@ func (s *ClientTestSuite) ProposeAndInsertEmptyBlocks(
s.ProposeInvalidTxListBytes(proposer)

// Random bytes txList
s.Nil(proposer.ProposeEmptyBlockOp(context.Background()))
s.Nil(s.proposeEmptyBlockOp(context.Background(), proposer))

events = append(events, []*bindings.TaikoL1ClientBlockProposed{<-sink, <-sink, <-sink}...)

Expand Down Expand Up @@ -299,3 +313,52 @@ func LocalRandomProverEndpoint() *url.URL {
func SignatureFromRSV(r, s string, v byte) []byte {
return append(append(hexutil.MustDecode(r), hexutil.MustDecode(s)...), v)
}

// MakeDynamicTx creates a dynamic transaction, used for tests.
func MakeDynamicTx(
client *rpc.EthClient,
priv *ecdsa.PrivateKey,
to *common.Address,
value *big.Int,
data []byte,
) (*types.Transaction, error) {
head, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
return nil, err
}

auth, err := bind.NewKeyedTransactorWithChainID(priv, client.ChainID)
if err != nil {
return nil, err
}

nonce, err := client.PendingNonceAt(context.Background(), auth.From)
if err != nil {
return nil, err
}

gasTipCap, err := client.SuggestGasTipCap(context.Background())
if err != nil {
return nil, err
}

tx, err := auth.Signer(auth.From, types.NewTx(&types.DynamicFeeTx{
To: to,
Nonce: nonce,
Value: value,
GasTipCap: gasTipCap,
GasFeeCap: new(big.Int).Add(
gasTipCap,
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
),
Gas: 2100_000,
Data: data,
}))
if err != nil {
return nil, err
}
if err = client.SendTransaction(context.Background(), tx); err != nil {
return nil, err
}
return tx, nil
}
1 change: 0 additions & 1 deletion internal/testutils/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type CalldataSyncer interface {
type Proposer interface {
utils.SubcommandApplication
ProposeOp(ctx context.Context) error
ProposeEmptyBlockOp(ctx context.Context) error
ProposeTxList(
ctx context.Context,
txListBytes []byte,
Expand Down
27 changes: 13 additions & 14 deletions proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type Config struct {
ProposeInterval time.Duration
LocalAddresses []common.Address
LocalAddressesOnly bool
BlockMinGasLimit uint64
BlockMinTxListBytes uint64
FroceProposingInternal time.Duration
MinGasUsed uint64
MinTxListBytes uint64
MinProposingInternal time.Duration
MaxProposedTxListsPerEpoch uint64
ProposeBlockTxGasLimit uint64
WaitReceiptTimeout time.Duration
Expand Down Expand Up @@ -88,17 +88,16 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
TaikoTokenAddress: common.HexToAddress(c.String(flags.TaikoTokenAddress.Name)),
Timeout: c.Duration(flags.RPCTimeout.Name),
},
AssignmentHookAddress: common.HexToAddress(c.String(flags.ProposerAssignmentHookAddress.Name)),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(l2SuggestedFeeRecipient),
ExtraData: c.String(flags.ExtraData.Name),
ProposeInterval: c.Duration(flags.ProposeInterval.Name),
LocalAddresses: localAddresses,
LocalAddressesOnly: c.Bool(flags.TxPoolLocalsOnly.Name),

BlockMinGasLimit: c.Uint64(flags.BlockMinGasLimit.Name),
BlockMinTxListBytes: c.Uint64(flags.BlockMinTxListBytes.Name),
FroceProposingInternal: c.Duration(flags.FroceProposingInternal.Name),
AssignmentHookAddress: common.HexToAddress(c.String(flags.ProposerAssignmentHookAddress.Name)),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(l2SuggestedFeeRecipient),
ExtraData: c.String(flags.ExtraData.Name),
ProposeInterval: c.Duration(flags.ProposeInterval.Name),
LocalAddresses: localAddresses,
LocalAddressesOnly: c.Bool(flags.TxPoolLocalsOnly.Name),
MinGasUsed: c.Uint64(flags.MinGasUsed.Name),
MinTxListBytes: c.Uint64(flags.MinTxListBytes.Name),
MinProposingInternal: c.Duration(flags.MinProposingInternal.Name),
MaxProposedTxListsPerEpoch: c.Uint64(flags.MaxProposedTxListsPerEpoch.Name),
ProposeBlockTxGasLimit: c.Uint64(flags.TxGasLimit.Name),
WaitReceiptTimeout: c.Duration(flags.WaitReceiptTimeout.Name),
Expand Down
6 changes: 3 additions & 3 deletions proposer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextL2RecipErr() {
"TestNewConfigFromCliContextL2RecipErr",
"--" + flags.L1ProposerPrivKey.Name, encoding.GoldenTouchPrivKey,
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.FroceProposingInternal.Name, proposeInterval,
"--" + flags.MinProposingInternal.Name, proposeInterval,
"--" + flags.L2SuggestedFeeRecipient.Name, "notAnAddress",
}), "invalid L2 suggested fee recipient address")
}
Expand All @@ -115,7 +115,7 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContextTxPoolLocalsErr() {
"TestNewConfigFromCliContextTxPoolLocalsErr",
"--" + flags.L1ProposerPrivKey.Name, encoding.GoldenTouchPrivKey,
"--" + flags.ProposeInterval.Name, proposeInterval,
"--" + flags.FroceProposingInternal.Name, proposeInterval,
"--" + flags.MinProposingInternal.Name, proposeInterval,
"--" + flags.L2SuggestedFeeRecipient.Name, goldenTouchAddress.Hex(),
"--" + flags.TxPoolLocals.Name, "notAnAddress",
}), "invalid account in --txpool.locals")
Expand All @@ -131,7 +131,7 @@ func (s *ProposerTestSuite) SetupApp() *cli.App {
&cli.StringFlag{Name: flags.TaikoTokenAddress.Name},
&cli.StringFlag{Name: flags.L1ProposerPrivKey.Name},
&cli.StringFlag{Name: flags.L2SuggestedFeeRecipient.Name},
&cli.DurationFlag{Name: flags.FroceProposingInternal.Name},
&cli.DurationFlag{Name: flags.MinProposingInternal.Name},
&cli.DurationFlag{Name: flags.ProposeInterval.Name},
&cli.StringFlag{Name: flags.TxPoolLocals.Name},
&cli.StringFlag{Name: flags.ProverEndpoints.Name},
Expand Down
Loading

0 comments on commit b4a6182

Please sign in to comment.