ensure replaced message can properly RBF
This commit is contained in:
parent
8c0994e290
commit
e9b85f5acb
@ -11,6 +11,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
@ -154,6 +155,11 @@ func newMsgSet(nonce uint64) *msgSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ComputeMinRBF(curPrem abi.TokenAmount) abi.TokenAmount {
|
||||||
|
minPrice := types.BigAdd(curPrem, types.BigDiv(types.BigMul(curPrem, rbfNumBig), rbfDenomBig))
|
||||||
|
return types.BigAdd(minPrice, types.NewInt(1))
|
||||||
|
}
|
||||||
|
|
||||||
func (ms *msgSet) add(m *types.SignedMessage, mp *MessagePool, strict bool) (bool, error) {
|
func (ms *msgSet) add(m *types.SignedMessage, mp *MessagePool, strict bool) (bool, error) {
|
||||||
nextNonce := ms.nextNonce
|
nextNonce := ms.nextNonce
|
||||||
nonceGap := false
|
nonceGap := false
|
||||||
@ -181,9 +187,7 @@ func (ms *msgSet) add(m *types.SignedMessage, mp *MessagePool, strict bool) (boo
|
|||||||
|
|
||||||
if m.Cid() != exms.Cid() {
|
if m.Cid() != exms.Cid() {
|
||||||
// check if RBF passes
|
// check if RBF passes
|
||||||
minPrice := exms.Message.GasPremium
|
minPrice := ComputeMinRBF(exms.Message.GasPremium)
|
||||||
minPrice = types.BigAdd(minPrice, types.BigDiv(types.BigMul(minPrice, rbfNumBig), rbfDenomBig))
|
|
||||||
minPrice = types.BigAdd(minPrice, types.NewInt(1))
|
|
||||||
if types.BigCmp(m.Message.GasPremium, minPrice) >= 0 {
|
if types.BigCmp(m.Message.GasPremium, minPrice) >= 0 {
|
||||||
log.Infow("add with RBF", "oldpremium", exms.Message.GasPremium,
|
log.Infow("add with RBF", "oldpremium", exms.Message.GasPremium,
|
||||||
"newpremium", m.Message.GasPremium, "addr", m.Message.From, "nonce", m.Message.Nonce)
|
"newpremium", m.Message.GasPremium, "addr", m.Message.From, "nonce", m.Message.Nonce)
|
||||||
|
@ -11,8 +11,10 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
lapi "github.com/filecoin-project/lotus/api"
|
lapi "github.com/filecoin-project/lotus/api"
|
||||||
|
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -356,7 +358,9 @@ var mpoolReplaceCmd = &cli.Command{
|
|||||||
return fmt.Errorf("failed to estimate gas values: %w", err)
|
return fmt.Errorf("failed to estimate gas values: %w", err)
|
||||||
}
|
}
|
||||||
msg.GasFeeCap = retm.GasFeeCap
|
msg.GasFeeCap = retm.GasFeeCap
|
||||||
msg.GasPremium = retm.GasPremium
|
|
||||||
|
minRBF := messagepool.ComputeMinRBF(msg.GasPremium)
|
||||||
|
msg.GasPremium = big.Max(retm.GasPremium, minRBF)
|
||||||
} else {
|
} else {
|
||||||
msg.GasLimit = cctx.Int64("gas-limit")
|
msg.GasLimit = cctx.Int64("gas-limit")
|
||||||
msg.GasPremium, err = types.BigFromString(cctx.String("gas-premium"))
|
msg.GasPremium, err = types.BigFromString(cctx.String("gas-premium"))
|
||||||
|
Loading…
Reference in New Issue
Block a user