From 33ec492d986f3407470b6e8bc11baa1a199c3e78 Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 5 Apr 2024 13:41:49 +0800 Subject: [PATCH 1/5] fix(proposer): fix tier fee --- cmd/flags/proposer.go | 7 +++++++ proposer/config.go | 2 ++ proposer/proposer.go | 1 + .../prover_selector/eth_fee_eoa_selector.go | 19 ++++++++++++++++--- .../eth_fee_eoa_selector_test.go | 1 + proposer/transaction_builder/common_test.go | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cmd/flags/proposer.go b/cmd/flags/proposer.go index 90e99fd70..ead62a41f 100644 --- a/cmd/flags/proposer.go +++ b/cmd/flags/proposer.go @@ -59,6 +59,12 @@ var ( Category: proposerCategory, Value: 3, } + MaxTierFee = &cli.Uint64Flag{ + Name: "tierFee.max", + Usage: "Fee max limit for all tier types. 0 means unlimited", + Value: 0, + Category: proposerCategory, + } // Proposing epoch related. ProposeInterval = &cli.DurationFlag{ Name: "epoch.interval", @@ -152,4 +158,5 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{ ProposerAssignmentHookAddress, BlobAllowed, L1BlockBuilderTip, + MaxTierFee, }, TxmgrFlags) diff --git a/proposer/config.go b/proposer/config.go index 644b16df2..8834cc865 100644 --- a/proposer/config.go +++ b/proposer/config.go @@ -42,6 +42,7 @@ type Config struct { BlobAllowed bool TxmgrConfigs *txmgr.CLIConfig L1BlockBuilderTip *big.Int + MaxTierFee *big.Int } // NewConfigFromCliContext initializes a Config instance from @@ -112,5 +113,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { l1ProposerPrivKey, c, ), + MaxTierFee: new(big.Int).SetUint64(c.Uint64(flags.OptimisticTierFee.Name)), }, nil } diff --git a/proposer/proposer.go b/proposer/proposer.go index a58785385..df531ce7c 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -123,6 +123,7 @@ func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error) cfg.MaxTierFeePriceBumps, proverAssignmentTimeout, requestProverServerTimeout, + cfg.MaxTierFee, ); err != nil { return err } diff --git a/proposer/prover_selector/eth_fee_eoa_selector.go b/proposer/prover_selector/eth_fee_eoa_selector.go index a6b9082a4..698984c29 100644 --- a/proposer/prover_selector/eth_fee_eoa_selector.go +++ b/proposer/prover_selector/eth_fee_eoa_selector.go @@ -40,6 +40,7 @@ type ETHFeeEOASelector struct { maxTierFeePriceBumpIterations uint64 proposalExpiry time.Duration requestTimeout time.Duration + MaxTierFee *big.Int } // NewETHFeeEOASelector creates a new ETHFeeEOASelector instance. @@ -54,6 +55,7 @@ func NewETHFeeEOASelector( maxTierFeePriceBumpIterations uint64, proposalExpiry time.Duration, requestTimeout time.Duration, + MaxTierFee *big.Int, ) (*ETHFeeEOASelector, error) { if len(proverEndpoints) == 0 { return nil, errEmptyProverEndpoints @@ -76,6 +78,7 @@ func NewETHFeeEOASelector( maxTierFeePriceBumpIterations, proposalExpiry, requestTimeout, + MaxTierFee, }, nil } @@ -94,7 +97,11 @@ func (s *ETHFeeEOASelector) AssignProver( big100 = new(big.Int).SetUint64(uint64(100)) maxProverFee = common.Big0 ) - copy(fees, tierFees) + + // Deep copy + for i, fee := range tierFees { + fees[i] = encoding.TierFee{Tier: fee.Tier, Fee: fee.Fee} + } // Iterate over each configured endpoint, and see if someone wants to accept this block. // If it is denied, we continue on to the next endpoint. @@ -105,7 +112,12 @@ func (s *ETHFeeEOASelector) AssignProver( for idx := range fees { if i > 0 { fee := new(big.Int).Mul(fees[idx].Fee, cumulativeBumpPercent) - fees[idx].Fee = fees[idx].Fee.Add(fees[idx].Fee, fee.Div(fee, big100)) + tempFee := fees[idx].Fee.Add(fees[idx].Fee, fee.Div(fee, big100)) + if s.MaxTierFee.Cmp(common.Big0) > 0 && tempFee.Cmp(s.MaxTierFee) > 0 { + fees[idx].Fee = s.MaxTierFee + } else { + fees[idx].Fee = tempFee + } } if fees[idx].Fee.Cmp(maxProverFee) > 0 { maxProverFee = fees[idx].Fee @@ -118,7 +130,7 @@ func (s *ETHFeeEOASelector) AssignProver( s.protocolConfigs.ChainId, endpoint, expiry, - tierFees, + fees, s.taikoL1Address, s.assignmentHookAddress, txListHash, @@ -180,6 +192,7 @@ func assignProver( "endpoint", endpoint, "expiry", expiry, "txListHash", txListHash, + "tierFees", tierFees, ) // Send the HTTP request diff --git a/proposer/prover_selector/eth_fee_eoa_selector_test.go b/proposer/prover_selector/eth_fee_eoa_selector_test.go index cb7bbf62e..3d857d969 100644 --- a/proposer/prover_selector/eth_fee_eoa_selector_test.go +++ b/proposer/prover_selector/eth_fee_eoa_selector_test.go @@ -42,6 +42,7 @@ func (s *ProverSelectorTestSuite) SetupTest() { 32, 1*time.Minute, 1*time.Minute, + common.Big0, ) s.Nil(err) } diff --git a/proposer/transaction_builder/common_test.go b/proposer/transaction_builder/common_test.go index 851ad5385..9d67f2d72 100644 --- a/proposer/transaction_builder/common_test.go +++ b/proposer/transaction_builder/common_test.go @@ -42,6 +42,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() { 32, 1*time.Minute, 1*time.Minute, + common.Big0, ) s.Nil(err) s.calldataTxBuilder = NewCalldataTransactionBuilder( From cea44d73eebab84adcfbfd31e9f2c0c4fe54476e Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 5 Apr 2024 14:03:48 +0800 Subject: [PATCH 2/5] test(proposer): modified unit test --- proposer/prover_selector/eth_fee_eoa_selector_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposer/prover_selector/eth_fee_eoa_selector_test.go b/proposer/prover_selector/eth_fee_eoa_selector_test.go index 3d857d969..2b763f371 100644 --- a/proposer/prover_selector/eth_fee_eoa_selector_test.go +++ b/proposer/prover_selector/eth_fee_eoa_selector_test.go @@ -42,7 +42,7 @@ func (s *ProverSelectorTestSuite) SetupTest() { 32, 1*time.Minute, 1*time.Minute, - common.Big0, + common.Big32, ) s.Nil(err) } @@ -57,7 +57,7 @@ func (s *ProverSelectorTestSuite) TestProverAssignProver() { {Tier: encoding.TierSgxID, Fee: common.Big256}, }, testutils.RandomHash()) s.NotEmpty(sig) - s.True(fee.Cmp(common.Big0) > 0) + s.Equal(fee.Cmp(common.Big32), 0) s.Nil(err) } From 8204bafb1242268be140ee3472aea30235eb9a32 Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 5 Apr 2024 14:06:43 +0800 Subject: [PATCH 3/5] test(proposer): fix test --- proposer/prover_selector/eth_fee_eoa_selector_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposer/prover_selector/eth_fee_eoa_selector_test.go b/proposer/prover_selector/eth_fee_eoa_selector_test.go index 2b763f371..f74351042 100644 --- a/proposer/prover_selector/eth_fee_eoa_selector_test.go +++ b/proposer/prover_selector/eth_fee_eoa_selector_test.go @@ -57,7 +57,7 @@ func (s *ProverSelectorTestSuite) TestProverAssignProver() { {Tier: encoding.TierSgxID, Fee: common.Big256}, }, testutils.RandomHash()) s.NotEmpty(sig) - s.Equal(fee.Cmp(common.Big32), 0) + s.Equal(fee.Cmp(common.Big32), 1) s.Nil(err) } From 7995f9756e544426187b5f071dd60d3091c25f12 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 5 Apr 2024 21:55:33 +0800 Subject: [PATCH 4/5] Update proposer/config.go --- proposer/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposer/config.go b/proposer/config.go index 8834cc865..f460d1b55 100644 --- a/proposer/config.go +++ b/proposer/config.go @@ -113,6 +113,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { l1ProposerPrivKey, c, ), - MaxTierFee: new(big.Int).SetUint64(c.Uint64(flags.OptimisticTierFee.Name)), + MaxTierFee: new(big.Int).SetUint64(c.Uint64(flags. MaxTierFee.Name)), }, nil } From ae724e4033befb7973886b3b184d80af9bfb0b15 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Fri, 5 Apr 2024 11:08:53 -0700 Subject: [PATCH 5/5] lint --- proposer/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposer/config.go b/proposer/config.go index cbdd053d2..33287ef42 100644 --- a/proposer/config.go +++ b/proposer/config.go @@ -121,6 +121,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { l1ProposerPrivKey, c, ), - MaxTierFee: new(big.Int).SetUint64(c.Uint64(flags. MaxTierFee.Name)), + MaxTierFee: new(big.Int).SetUint64(c.Uint64(flags.MaxTierFee.Name)), }, nil }