Add Replace by Fee

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-04-01 22:26:14 +02:00
parent f6c260c49f
commit d88c2f8a43
3 changed files with 46 additions and 9 deletions

View File

@ -34,6 +34,13 @@ var log = logging.Logger("messagepool")
const futureDebug = false
const ReplaceByFeeRatio = 1.25
var (
rbfNum = types.NewInt(uint64((ReplaceByFeeRatio - 1) * 256))
rbfDenom = types.NewInt(256)
)
var (
ErrMessageTooBig = errors.New("message too big")
@ -97,10 +104,20 @@ func (ms *msgSet) add(m *types.SignedMessage) error {
if len(ms.msgs) == 0 || m.Message.Nonce >= ms.nextNonce {
ms.nextNonce = m.Message.Nonce + 1
}
if _, has := ms.msgs[m.Message.Nonce]; has {
if m.Cid() != ms.msgs[m.Message.Nonce].Cid() {
log.Info("add with duplicate nonce")
return xerrors.Errorf("message to %s with nonce %d already in mpool", m.Message.To, m.Message.Nonce)
exms, has := ms.msgs[m.Message.Nonce]
if has {
if m.Cid() != exms.Cid() {
// check if RBF passes
minPrice := exms.Message.GasPrice
minPrice = types.BigAdd(minPrice, types.BigDiv(types.BigMul(minPrice, rbfNum), rbfDenom))
minPrice = types.BigAdd(minPrice, types.NewInt(1))
if types.BigCmp(m.Message.GasPrice, minPrice) > 0 {
log.Infow("add with RBF", "oldprice", exms.Message.GasPrice,
"newprice", m.Message.GasPrice, "addr", m.Message.From, "nonce", m.Message.Nonce)
} else {
log.Info("add with duplicate nonce")
return xerrors.Errorf("message to %s with nonce %d already in mpool", m.Message.To, m.Message.Nonce)
}
}
}
ms.msgs[m.Message.Nonce] = m

View File

@ -22,6 +22,11 @@ var sendCmd = &cli.Command{
Usage: "specify gas price to use in AttoFIL",
Value: "0",
},
&cli.Int64Flag{
Name: "nonce",
Usage: "specify the nonce to use",
Value: -1,
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
@ -76,9 +81,22 @@ var sendCmd = &cli.Command{
GasPrice: gp,
}
_, err = api.MpoolPushMessage(ctx, msg)
if err != nil {
return err
if cctx.Int64("nonce") > 0 {
msg.Nonce = uint64(cctx.Int64("nonce"))
sm, err := api.WalletSignMessage(ctx, fromAddr, msg)
if err != nil {
return err
}
_, err = api.MpoolPush(ctx, sm)
if err != nil {
return err
}
} else {
_, err = api.MpoolPushMessage(ctx, msg)
if err != nil {
return err
}
}
return nil

View File

@ -4,5 +4,7 @@ set -o xtrace
export TRUST_PARAMS=1
go run -tags=debug ./cmd/lotus-seed pre-seal
go run -tags=debug ./cmd/lotus daemon --lotus-make-random-genesis=devel.gen --genesis-presealed-sectors=~/.genesis-sectors/pre-seal-t0101.json
go run -tags=debug ./cmd/lotus-seed pre-seal --sector-size 2048 --num-sectors 2
go run -tags=debug ./cmd/lotus-seed genesis new localnet.json
go run -tags=debug ./cmd/lotus-seed genesis add-miner localnet.json ~/.genesis-sectors/pre-seal-t01000.json
go run -tags=debug ./cmd/lotus daemon --lotus-make-genesis=devel.gen --genesis-template=localnet.json --bootstrap=false