add localonly option to MpoolClear

This commit is contained in:
vyzo 2020-08-21 20:59:40 +03:00
parent e33d398c33
commit 087955e927
6 changed files with 29 additions and 14 deletions

View File

@ -185,7 +185,7 @@ type FullNode interface {
MpoolSub(context.Context) (<-chan MpoolUpdate, error) MpoolSub(context.Context) (<-chan MpoolUpdate, error)
// MpoolClear clears all pending messages from the mpool // MpoolClear clears all pending messages from the mpool
MpoolClear(context.Context) error MpoolClear(context.Context, bool) error
// MpoolGetConfig returns (a copy of) the current mpool config // MpoolGetConfig returns (a copy of) the current mpool config
MpoolGetConfig(context.Context) (*types.MpoolConfig, error) MpoolGetConfig(context.Context) (*types.MpoolConfig, error)

View File

@ -107,7 +107,7 @@ type FullNodeStruct struct {
MpoolSelect func(context.Context, types.TipSetKey, float64) ([]*types.SignedMessage, error) `perm:"read"` MpoolSelect func(context.Context, types.TipSetKey, float64) ([]*types.SignedMessage, error) `perm:"read"`
MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"`
MpoolClear func(context.Context) error `perm:"write"` MpoolClear func(context.Context, bool) error `perm:"write"`
MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"`
MpoolPushMessage func(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` MpoolPushMessage func(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"`
@ -496,8 +496,8 @@ func (c *FullNodeStruct) MpoolPending(ctx context.Context, tsk types.TipSetKey)
return c.Internal.MpoolPending(ctx, tsk) return c.Internal.MpoolPending(ctx, tsk)
} }
func (c *FullNodeStruct) MpoolClear(ctx context.Context) error { func (c *FullNodeStruct) MpoolClear(ctx context.Context, localonly bool) error {
return c.Internal.MpoolClear(ctx) return c.Internal.MpoolClear(ctx, localonly)
} }
func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) { func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) {

View File

@ -974,7 +974,7 @@ func (mp *MessagePool) loadLocal() error {
return nil return nil
} }
func (mp *MessagePool) Clear() { func (mp *MessagePool) Clear(localonly bool) {
mp.lk.Lock() mp.lk.Lock()
defer mp.lk.Unlock() defer mp.lk.Unlock()
@ -991,9 +991,14 @@ func (mp *MessagePool) Clear() {
log.Warnf("error deleting local message: %s", err) log.Warnf("error deleting local message: %s", err)
} }
} }
delete(mp.pending, a)
} }
// clear the maps // clear the maps
mp.pending = make(map[address.Address]*msgSet)
mp.republished = nil mp.republished = nil
if !localonly {
mp.pending = make(map[address.Address]*msgSet)
}
} }

View File

@ -87,6 +87,12 @@ var mpoolPending = &cli.Command{
var mpoolClear = &cli.Command{ var mpoolClear = &cli.Command{
Name: "clear", Name: "clear",
Usage: "Clear all pending messages from the mpool (USE WITH CARE)", Usage: "Clear all pending messages from the mpool (USE WITH CARE)",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "local",
Usage: "clear local messages only",
},
},
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
@ -94,9 +100,10 @@ var mpoolClear = &cli.Command{
} }
defer closer() defer closer()
ctx := ReqContext(cctx) local := cctx.Bool("local")
return api.MpoolClear(ctx) ctx := ReqContext(cctx)
return api.MpoolClear(ctx, local)
}, },
} }

View File

@ -20,7 +20,7 @@ The full node API defines the following methods for interacting with the mpool:
MpoolSub(context.Context) (<-chan MpoolUpdate, error) MpoolSub(context.Context) (<-chan MpoolUpdate, error)
MpoolGetConfig(context.Context) (*types.MpoolConfig, error) MpoolGetConfig(context.Context) (*types.MpoolConfig, error)
MpoolSetConfig(context.Context, *types.MpoolConfig) error MpoolSetConfig(context.Context, *types.MpoolConfig) error
MpoolClear(context.Context) error MpoolClear(context.Context, localonly bool) error
``` ```
### MpoolPending ### MpoolPending
@ -64,7 +64,8 @@ Sets the mpool configuration to (a copy of) the supplied configuration object.
### MpoolClear ### MpoolClear
Unconditionally clears all pending messages from the mpool. Clears pending messages from the mpool; if `localonly` is `true` then only local messages are cleared.
This should be used with extreme care and only in the case of errors during head changes that This should be used with extreme care and only in the case of errors during head changes that
would leave the mpool in an inconsistent state. would leave the mpool in an inconsistent state.
@ -82,7 +83,7 @@ lotus mpool stat [--local]
lotus mpool replace [--gas-feecap <feecap>] [--gas-premium <premium>] [--gas-limit <limit>] [from] [nonce] lotus mpool replace [--gas-feecap <feecap>] [--gas-premium <premium>] [--gas-limit <limit>] [from] [nonce]
lotus mpool find [--from <address>] [--to <address>] [--method <int>] lotus mpool find [--from <address>] [--to <address>] [--method <int>]
lotus mpool config [<configuration>] lotus mpool config [<configuration>]
lotus mpool clear lotus mpool clear [--local]
``` ```
### lotus mpool pending ### lotus mpool pending
@ -107,7 +108,9 @@ Searches for messages in the mpool.
Gets or sets the current mpool configuration. Gets or sets the current mpool configuration.
### lotus mpool clear ### lotus mpool clear
Unconditionally clears all pending messages from the mpool. Unconditionally clears pending messages from the mpool.
If the `--local` flag is passed, then only local messages are cleared; otherwise all messages
are cleared.
*Warning*: this command should only be used in the case of head change errors leaving the mpool in an *Warning*: this command should only be used in the case of head change errors leaving the mpool in an
inconsistent state. inconsistent state.

View File

@ -105,8 +105,8 @@ func (a *MpoolAPI) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*ty
} }
} }
func (a *MpoolAPI) MpoolClear(ctx context.Context) error { func (a *MpoolAPI) MpoolClear(ctx context.Context, localonly bool) error {
a.Mpool.Clear() a.Mpool.Clear(localonly)
return nil return nil
} }