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

Commit

Permalink
fix(proposer): fix tier fee (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Apr 5, 2024
1 parent fd98d4b commit 651f188
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -154,4 +160,5 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ProposerAssignmentHookAddress,
BlobAllowed,
L1BlockBuilderTip,
MaxTierFee,
}, TxmgrFlags)
2 changes: 2 additions & 0 deletions proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Config struct {
BlobAllowed bool
TxmgrConfigs *txmgr.CLIConfig
L1BlockBuilderTip *big.Int
MaxTierFee *big.Int
}

// NewConfigFromCliContext initializes a Config instance from
Expand Down Expand Up @@ -120,5 +121,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
l1ProposerPrivKey,
c,
),
MaxTierFee: new(big.Int).SetUint64(c.Uint64(flags.MaxTierFee.Name)),
}, nil
}
1 change: 1 addition & 0 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 16 additions & 3 deletions proposer/prover_selector/eth_fee_eoa_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ETHFeeEOASelector struct {
maxTierFeePriceBumpIterations uint64
proposalExpiry time.Duration
requestTimeout time.Duration
MaxTierFee *big.Int
}

// NewETHFeeEOASelector creates a new ETHFeeEOASelector instance.
Expand All @@ -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
Expand All @@ -76,6 +78,7 @@ func NewETHFeeEOASelector(
maxTierFeePriceBumpIterations,
proposalExpiry,
requestTimeout,
MaxTierFee,
}, nil
}

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -118,7 +130,7 @@ func (s *ETHFeeEOASelector) AssignProver(
s.protocolConfigs.ChainId,
endpoint,
expiry,
tierFees,
fees,
s.taikoL1Address,
s.assignmentHookAddress,
txListHash,
Expand Down Expand Up @@ -180,6 +192,7 @@ func assignProver(
"endpoint", endpoint,
"expiry", expiry,
"txListHash", txListHash,
"tierFees", tierFees,
)

// Send the HTTP request
Expand Down
3 changes: 2 additions & 1 deletion proposer/prover_selector/eth_fee_eoa_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *ProverSelectorTestSuite) SetupTest() {
32,
1*time.Minute,
1*time.Minute,
common.Big32,
)
s.Nil(err)
}
Expand All @@ -56,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), 1)
s.Nil(err)
}

Expand Down
1 change: 1 addition & 0 deletions proposer/transaction_builder/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
32,
1*time.Minute,
1*time.Minute,
common.Big0,
)
s.Nil(err)
s.calldataTxBuilder = NewCalldataTransactionBuilder(
Expand Down

0 comments on commit 651f188

Please sign in to comment.