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

Commit

Permalink
feat(proposer): improve proposer flag configs (#589)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
mask-pp and davidtaikocha committed Mar 6, 2024
1 parent 1fd9084 commit 8159155
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 55 deletions.
2 changes: 2 additions & 0 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ var (
Name: "epoch.interval",
Usage: "Time interval to propose L2 pending transactions",
Category: proposerCategory,
Value: 0,
}
ProposeEmptyBlocksInterval = &cli.DurationFlag{
Name: "epoch.emptyBlockInterval",
Usage: "Time interval to propose empty blocks",
Category: proposerCategory,
Value: 0,
}
// Proposing metadata related.
ExtraData = &cli.StringFlag{
Expand Down
3 changes: 1 addition & 2 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
prop := new(proposer.Proposer)
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)
proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests

s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
Expand All @@ -58,7 +57,7 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: s.ProverEndpoints,
Expand Down
3 changes: 1 addition & 2 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (s *ChainSyncerTestSuite) SetupTest() {
prop := new(proposer.Proposer)
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)
proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests

s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
Expand All @@ -59,7 +58,7 @@ func (s *ChainSyncerTestSuite) SetupTest() {
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: s.ProverEndpoints,
Expand Down
3 changes: 2 additions & 1 deletion driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Config struct {
P2PSyncVerifiedBlocks bool
P2PSyncTimeout time.Duration
RPCTimeout time.Duration
RetryInterval time.Duration
}

// NewConfigFromCliContext creates a new config instance from
Expand Down Expand Up @@ -53,9 +54,9 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)),
L2EngineEndpoint: c.String(flags.L2AuthEndpoint.Name),
JwtSecret: string(jwtSecret),
RetryInterval: c.Duration(flags.BackOffRetryInterval.Name),
Timeout: timeout,
},
RetryInterval: c.Duration(flags.BackOffRetryInterval.Name),
P2PSyncVerifiedBlocks: p2pSyncVerifiedBlocks,
P2PSyncTimeout: c.Duration(flags.P2PSyncTimeout.Name),
RPCTimeout: timeout,
Expand Down
1 change: 0 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (d *Driver) InitFromCli(ctx context.Context, c *cli.Context) error {
// InitFromConfig initializes the driver instance based on the given configurations.
func (d *Driver) InitFromConfig(ctx context.Context, cfg *Config) (err error) {
d.l1HeadCh = make(chan *types.Header, 1024)
d.wg = sync.WaitGroup{}
d.syncNotify = make(chan struct{}, 1)
d.ctx = ctx
d.Config = cfg
Expand Down
3 changes: 1 addition & 2 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (s *DriverTestSuite) SetupTest() {
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests
s.Nil(p.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
Expand All @@ -66,7 +65,7 @@ func (s *DriverTestSuite) SetupTest() {
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: s.ProverEndpoints,
Expand Down
2 changes: 0 additions & 2 deletions internal/testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"strconv"

"github.com/cenkalti/backoff/v4"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -61,7 +60,6 @@ func (s *ClientTestSuite) SetupTest() {
GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: string(jwtSecret),
RetryInterval: backoff.DefaultMaxInterval,
})
s.Nil(err)
s.RPCClient = rpcCli
Expand Down
6 changes: 3 additions & 3 deletions pkg/chain_iterator/block_batch_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type BlockBatchIteratorConfig struct {
EndHeight *big.Int
OnBlocks OnBlocksFunc
ReorgRewindDepth *uint64
RetryInterval *time.Duration
RetryInterval time.Duration
}

// NewBlockBatchIterator creates a new block batch iterator instance.
Expand Down Expand Up @@ -109,10 +109,10 @@ func NewBlockBatchIterator(ctx context.Context, cfg *BlockBatchIteratorConfig) (
iterator.blocksReadPerEpoch = DefaultBlocksReadPerEpoch
}

if cfg.RetryInterval == nil {
if cfg.RetryInterval == 0 {
iterator.retryInterval = DefaultRetryInterval
} else {
iterator.retryInterval = *cfg.RetryInterval
iterator.retryInterval = cfg.RetryInterval
}

if cfg.EndHeight != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/chain_iterator/block_batch_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ func (s *BlockBatchIteratorTestSuite) TestIterCtxCancel() {
headHeight, err := s.RPCClient.L1.BlockNumber(context.Background())
s.Nil(err)
ctx, cancel := context.WithCancel(context.Background())
retry := 5 * time.Second

itr, err := NewBlockBatchIterator(ctx, &BlockBatchIteratorConfig{
Client: s.RPCClient.L1,
MaxBlocksReadPerEpoch: nil,
RetryInterval: &retry,
RetryInterval: 5 * time.Second,
StartHeight: common.Big0,
EndHeight: new(big.Int).SetUint64(headHeight),
OnBlocks: func(
Expand Down
2 changes: 0 additions & 2 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ type ClientConfig struct {
GuardianProverAddress common.Address
L2EngineEndpoint string
JwtSecret string
RetryInterval time.Duration
Timeout time.Duration
BackOffMaxRetries uint64
}

// NewClient initializes all RPC clients used by Taiko client software.
Expand Down
3 changes: 0 additions & 3 deletions pkg/rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
Expand All @@ -20,7 +19,6 @@ func newTestClient(t *testing.T) *Client {
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: os.Getenv("JWT_SECRET"),
RetryInterval: backoff.DefaultMaxInterval,
})

require.Nil(t, err)
Expand All @@ -38,7 +36,6 @@ func newTestClientWithTimeout(t *testing.T) *Client {
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: os.Getenv("JWT_SECRET"),
RetryInterval: backoff.DefaultMaxInterval,
Timeout: 5 * time.Second,
})

Expand Down
22 changes: 4 additions & 18 deletions proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type Config struct {
L1ProposerPrivKey *ecdsa.PrivateKey
L2SuggestedFeeRecipient common.Address
ExtraData string
ProposeInterval *time.Duration
ProposeInterval time.Duration
LocalAddresses []common.Address
LocalAddressesOnly bool
ProposeEmptyBlocksInterval *time.Duration
ProposeEmptyBlocksInterval time.Duration
MaxProposedTxListsPerEpoch uint64
ProposeBlockTxGasLimit uint64
ProposeBlockTxReplacementMultiplier uint64
Expand All @@ -52,19 +52,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
return nil, fmt.Errorf("invalid L1 proposer private key: %w", err)
}

// Proposing configuration
var proposingInterval *time.Duration
if c.IsSet(flags.ProposeInterval.Name) {
interval := c.Duration(flags.ProposeInterval.Name)
proposingInterval = &interval
}

var proposeEmptyBlocksInterval *time.Duration
if c.IsSet(flags.ProposeEmptyBlocksInterval.Name) {
interval := c.Duration(flags.ProposeEmptyBlocksInterval.Name)
proposeEmptyBlocksInterval = &interval
}

l2SuggestedFeeRecipient := c.String(flags.L2SuggestedFeeRecipient.Name)
if !common.IsHexAddress(l2SuggestedFeeRecipient) {
return nil, fmt.Errorf("invalid L2 suggested fee recipient address: %s", l2SuggestedFeeRecipient)
Expand Down Expand Up @@ -109,17 +96,16 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)),
TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)),
TaikoTokenAddress: common.HexToAddress(c.String(flags.TaikoTokenAddress.Name)),
RetryInterval: c.Duration(flags.BackOffRetryInterval.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: proposingInterval,
ProposeInterval: c.Duration(flags.ProposeInterval.Name),
LocalAddresses: localAddresses,
LocalAddressesOnly: c.Bool(flags.TxPoolLocalsOnly.Name),
ProposeEmptyBlocksInterval: proposeEmptyBlocksInterval,
ProposeEmptyBlocksInterval: c.Duration(flags.ProposeEmptyBlocksInterval.Name),
MaxProposedTxListsPerEpoch: c.Uint64(flags.MaxProposedTxListsPerEpoch.Name),
ProposeBlockTxGasLimit: c.Uint64(flags.ProposeBlockTxGasLimit.Name),
ProposeBlockTxReplacementMultiplier: proposeBlockTxReplacementMultiplier,
Expand Down
9 changes: 4 additions & 5 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (p *Proposer) InitFromCli(ctx context.Context, c *cli.Context) error {
// InitFromConfig initializes the proposer instance based on the given configurations.
func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error) {
p.proposerAddress = crypto.PubkeyToAddress(cfg.L1ProposerPrivKey.PublicKey)
p.wg = sync.WaitGroup{}
p.ctx = ctx
p.Config = cfg

Expand Down Expand Up @@ -160,8 +159,8 @@ func (p *Proposer) eventLoop() {
continue
}
// if no new transactions and empty block interval has passed, propose an empty block
if p.ProposeEmptyBlocksInterval != nil {
if time.Now().Before(lastNonEmptyBlockProposedAt.Add(*p.ProposeEmptyBlocksInterval)) {
if p.ProposeEmptyBlocksInterval != 0 {
if time.Now().Before(lastNonEmptyBlockProposedAt.Add(p.ProposeEmptyBlocksInterval)) {
continue
}

Expand Down Expand Up @@ -518,8 +517,8 @@ func (p *Proposer) updateProposingTicker() {
}

var duration time.Duration
if p.ProposeInterval != nil {
duration = *p.ProposeInterval
if p.ProposeInterval != 0 {
duration = p.ProposeInterval
} else {
// Random number between 12 - 120
randomSeconds := rand.Intn(120-11) + 12 // nolint: gosec
Expand Down
8 changes: 3 additions & 5 deletions proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (s *ProposerTestSuite) SetupTest() {
p := new(Proposer)

ctx, cancel := context.WithCancel(context.Background())
proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests

s.Nil(p.InitFromConfig(ctx, &Config{
ClientConfig: &rpc.ClientConfig{
Expand All @@ -46,7 +45,7 @@ func (s *ProposerTestSuite) SetupTest() {
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
ProposeBlockTxReplacementMultiplier: 2,
WaitReceiptTimeout: 12 * time.Second,
Expand Down Expand Up @@ -202,11 +201,10 @@ func (s *ProposerTestSuite) TestAssignProverSuccessFirstRound() {
}

func (s *ProposerTestSuite) TestUpdateProposingTicker() {
oneHour := 1 * time.Hour
s.p.ProposeInterval = &oneHour
s.p.ProposeInterval = 1 * time.Hour
s.NotPanics(s.p.updateProposingTicker)

s.p.ProposeInterval = nil
s.p.ProposeInterval = 0
s.NotPanics(s.p.updateProposingTicker)
}

Expand Down
3 changes: 1 addition & 2 deletions prover/proof_submitter/proof_submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func (s *ProofSubmitterTestSuite) SetupTest() {
prop := new(proposer.Proposer)
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)
proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests

s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
Expand All @@ -100,7 +99,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() {

L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: s.ProverEndpoints,
Expand Down
2 changes: 0 additions & 2 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
TaikoL2Address: cfg.TaikoL2Address,
TaikoTokenAddress: cfg.TaikoTokenAddress,
GuardianProverAddress: cfg.GuardianProverAddress,
RetryInterval: cfg.BackOffRetryInterval,
Timeout: cfg.RPCTimeout,
BackOffMaxRetries: cfg.BackOffMaxRetrys,
}); err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (s *ProverTestSuite) SetupTest() {

prop := new(proposer.Proposer)

proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests
s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{
ClientConfig: &rpc.ClientConfig{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
Expand All @@ -83,7 +82,7 @@ func (s *ProverTestSuite) SetupTest() {
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
ProposeInterval: 1024 * time.Hour,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 12 * time.Second,
ProverEndpoints: []*url.URL{proverServerURL},
Expand Down
1 change: 0 additions & 1 deletion prover/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (s *ProverServerTestSuite) SetupTest() {
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"),
JwtSecret: os.Getenv("JWT_SECRET"),
RetryInterval: backoff.DefaultMaxInterval,
Timeout: 5 * time.Second,
})
s.Nil(err)
Expand Down

0 comments on commit 8159155

Please sign in to comment.