Skip to content

Lo6165 price bump cap#62

Merged
siburu merged 10 commits intodatachainlab:mainfrom
dai1975:lo6165-price-bump-cap
Feb 13, 2025
Merged

Lo6165 price bump cap#62
siburu merged 10 commits intodatachainlab:mainfrom
dai1975:lo6165-price-bump-cap

Conversation

@dai1975
Copy link
Contributor

@dai1975 dai1975 commented Jan 30, 2025

  • fix price bump bug to set opts.Nonce before GasFeeCalculator#Apply
  • check latest(replacing) transaction's gas fee is already high enough
  • make IETHClient interface and use it in gas.go and txpool.go for testing

Daisuke Kanda added 2 commits January 26, 2025 02:33
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
gasFeeCap := targetTx.GasFeeCap.ToInt()
gasTipCap := targetTx.GasTipCap.ToInt()
gasFeeCap := new(big.Int).Set(targetTx.GasFeeCap.ToInt())
gasTipCap := new(big.Int).Set(targetTx.GasTipCap.ToInt())
Copy link
Contributor Author

@dai1975 dai1975 Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hexuti.Big.ToInt() returns same pointer of receiver instance and following inclByPercent() overwrite it. This make problems when targetTx object is stored and reused such as testing mock.

Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
@siburu
Copy link
Contributor

siburu commented Feb 3, 2025

@dai1975 You have replaced the ETHClient struct with the IETHClient interface to mock it for testing. They are all defined in the pkg/client package.
However, actual tests that want to mock the ethereum client are not in pkg/client but in pkg/relay/ethereum (gas_test.go).
Therefore, I think, you didn't need to modify the pkg/client package and should only have modified the type of the client argument of NewGasFeeCalculator.

@siburu
Copy link
Contributor

siburu commented Feb 3, 2025

@dai1975 To easily mock all the functions of the pkg/client package and the pkg/client/txpool package, you may need to move the functions defined in the pkg/client/txpool package to the pkg/client and convert them into methods of the ETHClient struct.

Specifically, GetMinimumRequiredFee must be converted into a method of the ETHClient, since it is called from GasFeeCalculator.
However, I suggest to convert all the other functions (ContentFrom and PendingTransactions), too.

Daisuke Kanda added 4 commits February 4, 2025 00:15
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
if err := NewGasFeeCalculator(chain.client, &chain.config).Apply(ctx, txOpts); err != nil {
return nil, err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statement move to fix bug

@dai1975
Copy link
Contributor Author

dai1975 commented Feb 5, 2025

@siburu moved interface definition to ethereum package.

Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dai1975 Sorry but I have specified some to fix. Please check them 🙇


if oldTx != nil && oldTx.GasFeeCap != nil && oldTx.GasTipCap != nil {
if oldTx.GasFeeCap.ToInt().Cmp(gasFeeCap) >= 0 && oldTx.GasTipCap.ToInt().Cmp(gasTipCap) >= 0 {
return fmt.Errorf("old tx's gasFeeCap(%v) and gasTipCap(%v) are higher than suggestion(%v, %v)", oldTx.GasFeeCap.ToInt(), oldTx.GasTipCap.ToInt(), gasFeeCap, gasTipCap)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the error message by replacing higher than with greater than or equal to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 297 to 298
cli.MockHistoryGasTipCap.SetUint64(99) // lower than 100
cli.MockHistoryGasFeeCap.SetUint64(299 - 99) //lower than 300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should replace 99 and 299 - 99 with 100 and 300 - 100 to test the corner case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Signed-off-by: Daisuke Kanda <daisuke.kanda@datachain.jp>
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dai1975 LGTM. Great work, thank you!

@siburu siburu merged commit 70ce3fd into datachainlab:main Feb 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants