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

feat: Reduce minimum replace fee from 1.25x to 1.1x #336

Merged
merged 1 commit into from
Apr 10, 2023
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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.10.0
github.com/filecoin-project/specs-actors/v5 v5.0.6
github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4
github.com/filecoin-project/venus v1.10.2-0.20230407075303-4beae95e57c1
github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
Expand Down Expand Up @@ -73,7 +73,6 @@ require (
github.com/filecoin-project/specs-actors/v3 v3.1.2 // indirect
github.com/filecoin-project/specs-actors/v4 v4.0.2 // indirect
github.com/filecoin-project/specs-actors/v7 v7.0.1 // indirect
github.com/filecoin-project/specs-storage v0.4.1 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.1-0.20210810190654-139e0e79e69e/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.1/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.3/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4IrzznwS98X5XW/irUP3Lhxg=
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.10.0 h1:vsSThZIaPmOxNGG59+8D/HnlWRtlbdOjduH6ye+v8f0=
Expand Down Expand Up @@ -419,13 +418,11 @@ github.com/filecoin-project/specs-actors/v7 v7.0.0/go.mod h1:TA5FwCna+Yi36POaT7S
github.com/filecoin-project/specs-actors/v7 v7.0.1 h1:w72xCxijK7xs1qzmJiw+WYJaVt2EPHN8oiwpA1Ay3/4=
github.com/filecoin-project/specs-actors/v7 v7.0.1/go.mod h1:tPLEYXoXhcpyLh69Ccq91SOuLXsPWjHiY27CzawjUEk=
github.com/filecoin-project/specs-storage v0.2.2/go.mod h1:6cc/lncmAxMUocPi0z1EPCX63beIX7F7UnlmUZ3hLQo=
github.com/filecoin-project/specs-storage v0.4.1 h1:yvLEaLZj8f+uByhNC4mFOtCUyL2wQku+NGBp6hjTe9M=
github.com/filecoin-project/specs-storage v0.4.1/go.mod h1:Z2eK6uMwAOSLjek6+sy0jNV2DSsMEENziMUz0GHRFBw=
github.com/filecoin-project/storetheindex v0.3.5/go.mod h1:0r3d0kSpK63O6AvLr1CjAINLi+nWD49clzcnKV+GLpI=
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0=
github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4 h1:yLcesIYnlrkLc9dVgIfMtNu11+sF5jeQP1ykTOhjCDg=
github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8=
github.com/filecoin-project/venus v1.10.2-0.20230407075303-4beae95e57c1 h1:uXMVA7j67xd0B8G2VS9vJdcT6qKVYiTl4OOyXCtfViU=
github.com/filecoin-project/venus v1.10.2-0.20230407075303-4beae95e57c1/go.mod h1:eCV4+qsHdDg7FXB8xLn5w/ay+Uu5pG3oAlPsB1nb6qU=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e h1:Bxpt1AzPeNxmUnFT2Y8rpabr9x0wIC0Q87DeRmjL2co=
github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs=
Expand Down Expand Up @@ -2012,7 +2009,6 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2/go.mod h1:f
github.com/whyrusleeping/cbor-gen v0.0.0-20210303213153-67a261a1d291/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20220224212727-7a699437a831/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20221021053955-c138aae13722 h1:0HEhvpGQJ2Gd0ngPW83aduQQuF/V9v13+3zpSrR3lrA=
github.com/whyrusleeping/cbor-gen v0.0.0-20221021053955-c138aae13722/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
Expand Down
1 change: 1 addition & 0 deletions service/message_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func CapGasFee(msg *venusTypes.Message, maxFee abi.TokenAmount) {
totalFee := venusTypes.BigMul(msg.GasFeeCap, gl)

if totalFee.LessThanEqual(maxFee) {
msg.GasPremium = big.Min(msg.GasFeeCap, msg.GasPremium) // cap premium at FeeCap
return
}

Expand Down
27 changes: 15 additions & 12 deletions service/message_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,12 @@ func (ms *MessageService) ReplaceMessage(ctx context.Context, params *types.Repl
}

if params.Auto {
minRBF := computeMinRBF(msg.GasPremium)
cfg, err := ms.nodeClient.MpoolGetConfig(ctx)
if err != nil {
return cid.Undef, fmt.Errorf("failed to lookup the message pool config: %w", err)
}

minRBF := computeRBF(msg.GasPremium, cfg.ReplaceByFeeRatio)

mss := &venusTypes.MessageSendSpec{
MaxFee: params.MaxFee,
Expand Down Expand Up @@ -1020,17 +1025,15 @@ func (ms *MessageService) recordMetricsProc(ctx context.Context) {
}
}

const (
ReplaceByFeeRatioDefault = 1.25
RbfDenom = 256
)
const replaceByFeePercentageMinimum = 110

var (
rbfNumBig = big.NewInt(int64((ReplaceByFeeRatioDefault - 1) * RbfDenom))
rbfDenomBig = big.NewInt(RbfDenom)
)
var rbfDenomBig = venusTypes.NewInt(100)

func computeMinRBF(curPrem abi.TokenAmount) abi.TokenAmount {
minPrice := big.Add(curPrem, big.Div(big.Mul(curPrem, rbfNumBig), rbfDenomBig))
return big.Add(minPrice, big.NewInt(1))
func computeRBF(curPrem abi.TokenAmount, replaceByFeeRatio venusTypes.Percent) abi.TokenAmount {
if replaceByFeeRatio < replaceByFeePercentageMinimum {
replaceByFeeRatio = replaceByFeePercentageMinimum
}
rbfNumBig := venusTypes.NewInt(uint64(replaceByFeeRatio))
minPrice := venusTypes.BigDiv(venusTypes.BigMul(curPrem, rbfNumBig), rbfDenomBig)
return venusTypes.BigAdd(minPrice, venusTypes.NewInt(1))
}
13 changes: 12 additions & 1 deletion service/message_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ func TestReplaceMessage(t *testing.T) {
msh.start()
defer msh.stop()

smallerPremium := big.Sub(testhelper.MinPackedPremium, big.NewInt(20))
blockedMsgs := make(map[string]*types.Message, 0)
msgs := genMessages(addrs, len(addrs)*10)
for i, msg := range msgs {
if i%2 == 0 {
msg.GasPremium = big.Sub(testhelper.MinPackedPremium, big.NewInt(100))
msg.GasPremium = smallerPremium
blockedMsgs[msg.ID] = msg
}
}
Expand Down Expand Up @@ -112,6 +113,16 @@ func TestReplaceMessage(t *testing.T) {
res, err := ms.GetMessageByUid(ctx, msg.ID)
assert.NoError(t, err)
replacedMsgs = append(replacedMsgs, res)

// check gas premium
defPremium := testhelper.DefGasPremium
expectPremium := big.Div(big.Mul(smallerPremium, big.NewInt(int64(testhelper.DefReplaceByFeePercent))), big.NewInt(100))
if msg.Meta != nil && msg.Meta.GasOverPremium != 0 {
gasOverPremium := big.Mul(big.NewInt(int64(100*msg.Meta.GasOverPremium)), big.NewInt(100))
expectPremium = big.Mul(expectPremium, gasOverPremium)
defPremium = big.Mul(defPremium, gasOverPremium)
}
assert.Equal(t, big.Max(expectPremium, defPremium), res.GasPremium)
}

ctx, calcel := context.WithTimeout(ctx, time.Minute*3)
Expand Down
8 changes: 8 additions & 0 deletions testhelper/mock_full_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (

// MinPackedPremium If the gas premium is lower than this value, the message will not be packaged
MinPackedPremium = abi.NewTokenAmount(500)

DefReplaceByFeePercent types.Percent = 125
)

type MockFullNode struct {
Expand Down Expand Up @@ -589,6 +591,12 @@ func (f *MockFullNode) MpoolBatchPushUntrusted(ctx context.Context, smsgs []*typ
return cids, nil
}

func (f *MockFullNode) MpoolGetConfig(_ context.Context) (*types.MpoolConfig, error) {
return &types.MpoolConfig{
ReplaceByFeeRatio: DefReplaceByFeePercent,
}, nil
}

func (f *MockFullNode) StateSearchMsg(ctx context.Context, from types.TipSetKey, msgCid cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*types.MsgLookup, error) {
f.l.Lock()
defer f.l.Unlock()
Expand Down