fix: Eth JSON-RPC api: handle messages with gasFeeCap less than baseFee

This commit is contained in:
ychiao 2023-04-03 17:25:41 -04:00 committed by Maciej Witowski
parent ed553a8363
commit 565eddfb92
2 changed files with 8 additions and 3 deletions

View File

@ -220,12 +220,17 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version)
} }
// EffectiveGasPremium returns the effective gas premium claimable by the miner // EffectiveGasPremium returns the effective gas premium claimable by the miner
// given the supplied base fee. // given the supplied base fee. This method is not used anywhere except the Eth API.
// //
// Filecoin clamps the gas premium at GasFeeCap - BaseFee, if lower than the // Filecoin clamps the gas premium at GasFeeCap - BaseFee, if lower than the
// specified premium. // specified premium. Returns 0 if GasFeeCap is less than BaseFee.
func (m *Message) EffectiveGasPremium(baseFee abi.TokenAmount) abi.TokenAmount { func (m *Message) EffectiveGasPremium(baseFee abi.TokenAmount) abi.TokenAmount {
available := big.Sub(m.GasFeeCap, baseFee) available := big.Sub(m.GasFeeCap, baseFee)
// It's possible that storage providers may include messages with gasFeeCap less than the baseFee
// In such cases, their reward should be viewed as zero
if available.LessThan(big.NewInt(0)) {
available = big.NewInt(0)
}
if big.Cmp(m.GasPremium, available) <= 0 { if big.Cmp(m.GasPremium, available) <= 0 {
return m.GasPremium return m.GasPremium
} }

View File

@ -114,7 +114,7 @@ func TestReward(t *testing.T) {
{maxFeePerGas: big.NewInt(600), maxPriorityFeePerGas: big.NewInt(500), answer: big.NewInt(500)}, {maxFeePerGas: big.NewInt(600), maxPriorityFeePerGas: big.NewInt(500), answer: big.NewInt(500)},
{maxFeePerGas: big.NewInt(600), maxPriorityFeePerGas: big.NewInt(600), answer: big.NewInt(500)}, {maxFeePerGas: big.NewInt(600), maxPriorityFeePerGas: big.NewInt(600), answer: big.NewInt(500)},
{maxFeePerGas: big.NewInt(600), maxPriorityFeePerGas: big.NewInt(1000), answer: big.NewInt(500)}, {maxFeePerGas: big.NewInt(600), maxPriorityFeePerGas: big.NewInt(1000), answer: big.NewInt(500)},
{maxFeePerGas: big.NewInt(50), maxPriorityFeePerGas: big.NewInt(200), answer: big.NewInt(-50)}, {maxFeePerGas: big.NewInt(50), maxPriorityFeePerGas: big.NewInt(200), answer: big.NewInt(0)},
} }
for _, tc := range testcases { for _, tc := range testcases {
msg := &types.Message{GasFeeCap: tc.maxFeePerGas, GasPremium: tc.maxPriorityFeePerGas} msg := &types.Message{GasFeeCap: tc.maxFeePerGas, GasPremium: tc.maxPriorityFeePerGas}