Skip to content
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

Fix GasPremium capping logic #3552

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/filecoin-project/go-address"
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/ipfs/go-cid"

Expand Down Expand Up @@ -96,7 +96,8 @@ type MessageSendSpec struct {
}

var DefaultMessageSendSpec = MessageSendSpec{
MaxFee: big.Zero(),
// MaxFee of 0.1FIL
MaxFee: abi.NewTokenAmount(int64(build.FilecoinPrecision) / 10),
}

func (ms *MessageSendSpec) Get() MessageSendSpec {
Expand Down
4 changes: 2 additions & 2 deletions cli/paych_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestPaymentChannelStatus(t *testing.T) {
go func() {
// creator: paych get <creator> <receiver> <amount>
cmd = []string{creatorAddr.String(), receiverAddr.String(), fmt.Sprintf("%d", channelAmt)}
create <- creatorCLI.runCmd(paychGetCmd, cmd)
create <- creatorCLI.runCmd(paychAddFundsCmd, cmd)
}()

// Wait for the output to stop being "Channel does not exist"
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestPaymentChannelVoucherCreateShortfall(t *testing.T) {
// creator: paych get <creator> <receiver> <amount>
channelAmt := 100
cmd := []string{creatorAddr.String(), receiverAddr.String(), fmt.Sprintf("%d", channelAmt)}
chstr := creatorCLI.runCmd(paychGetCmd, cmd)
chstr := creatorCLI.runCmd(paychAddFundsCmd, cmd)

chAddr, err := address.NewFromString(chstr)
require.NoError(t, err)
Expand Down
7 changes: 1 addition & 6 deletions node/impl/full/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,11 @@ func capGasFee(msg *types.Message, maxFee abi.TokenAmount) {

gl := types.NewInt(uint64(msg.GasLimit))
totalFee := types.BigMul(msg.GasFeeCap, gl)
minerFee := types.BigMul(msg.GasPremium, gl)

if totalFee.LessThanEqual(maxFee) {
return
}

// scale chain/miner fee down proportionally to fit in our budget
// TODO: there are probably smarter things we can do here to optimize
// message inclusion latency

msg.GasFeeCap = big.Div(maxFee, gl)
msg.GasPremium = big.Div(big.Div(big.Mul(minerFee, maxFee), totalFee), gl)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line was completly wrong:
TotalForMiner*MaxAcceptable/TotalMessage/GasLimit

msg.GasPremium = big.Min(msg.GasFeeCap, msg.GasPremium) // cap premium at FeeCap
}