-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lo6165 price bump cap #62
base: main
Are you sure you want to change the base?
Conversation
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
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
gasFeeCap := targetTx.GasFeeCap.ToInt() | ||
gasTipCap := targetTx.GasTipCap.ToInt() | ||
gasFeeCap := new(big.Int).Set(targetTx.GasFeeCap.ToInt()) | ||
gasTipCap := new(big.Int).Set(targetTx.GasTipCap.ToInt()) |
There was a problem hiding this comment.
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 <[email protected]>
@dai1975 You have replaced the |
@dai1975 To easily mock all the functions of the Specifically, |
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
if err := NewGasFeeCalculator(chain.client, &chain.config).Apply(ctx, txOpts); err != nil { | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
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
@siburu moved interface definition to ethereum package. |
pkg/relay/ethereum/client.go
Outdated
func (cl *ChainClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) { | ||
return cl.ETHClient.Client.SuggestGasPrice(ctx) | ||
} | ||
func (cl *ChainClient) HeaderByNumber(ctx context.Context, number *big.Int) (*gethtypes.Header, error) { | ||
return cl.ETHClient.Client.HeaderByNumber(ctx, number) | ||
} | ||
func (cl *ChainClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) { | ||
return cl.ETHClient.Client.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dai1975 You need not redefine these 3 functions. In the Go language, if an embedded struct implements an interface, the embedding struct also inherits the interface. Specifically, ChainClient
inherits all the methods implemented by ethclient.Client
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, these codes are remains of try of struct version. Removed.
pkg/relay/ethereum/client.go
Outdated
type IChainClient interface { | ||
SuggestGasPrice(ctx context.Context) (*big.Int, error) | ||
HeaderByNumber(ctx context.Context, number *big.Int) (*gethtypes.Header, error); | ||
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) | ||
GetMinimumRequiredFee(ctx context.Context, address common.Address, nonce uint64, priceBump uint64) (*txpool.RPCTransaction, *big.Int, *big.Int, error); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dai1975
Do you know that go-ethereum defines ETH JSON RPC client interfaces in interfaces.go?
ethclient.Client
implements all these interfaces, and so client.ETHClient
and ChainClient
inherit them.
I think it is better to pick up some or all of these interfaces and embed them into IChainClient
like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know it. fixed.
pkg/relay/ethereum/gas.go
Outdated
@@ -61,6 +66,9 @@ func (m *GasFeeCalculator) Apply(ctx context.Context, txOpts *bind.TransactOpts) | |||
// GasFeeCap = min(LimitFeePerGas, GasTipCap + BaseFee * BaseFeeRate) | |||
m.config.DynamicTxGasConfig.BaseFeeRate.Mul(gasFeeCap) | |||
gasFeeCap.Add(gasFeeCap, gasTipCap) | |||
if oldTx != nil && oldTx.GasFeeCap != nil && oldTx.GasFeeCap.ToInt().Cmp(gasFeeCap) > 0 { | |||
return fmt.Errorf("old tx's gasFeeCap(%v) is higher than suggestion(%v)", oldTx.GasFeeCap.ToInt(), gasFeeCap) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dai1975 I think that we should give up tx replacement only if both the tip and fee caps of the pending tx are higher than the new tx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely. fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add error case when new caps are equals to old caps(Cmp returns zero)
Signed-off-by: Daisuke Kanda <[email protected]>