From 30272837564b5a79d71ecc1c5e1efb2a355adcc5 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 21 Aug 2020 20:28:45 +0300 Subject: [PATCH] add MpoolClear api --- api/api_full.go | 3 +++ api/apistruct/struct.go | 8 +++++++- chain/messagepool/messagepool.go | 8 ++++++++ node/impl/full/mpool.go | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/api_full.go b/api/api_full.go index 71e3987df..7cc88fa80 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -184,6 +184,9 @@ type FullNode interface { MpoolGetNonce(context.Context, address.Address) (uint64, error) MpoolSub(context.Context) (<-chan MpoolUpdate, error) + // MpoolClear clears all pending messages from the mpool + MpoolClear(context.Context) error + // MpoolGetConfig returns (a copy of) the current mpool config MpoolGetConfig(context.Context) (*types.MpoolConfig, error) // MpoolSetConfig sets the mpool config to (a copy of) the supplied config diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 5f027543e..219aea495 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -106,7 +106,9 @@ type FullNodeStruct struct { 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"` + MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` MpoolPushMessage func(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` @@ -494,6 +496,10 @@ func (c *FullNodeStruct) MpoolPending(ctx context.Context, tsk types.TipSetKey) return c.Internal.MpoolPending(ctx, tsk) } +func (c *FullNodeStruct) MpoolClear(ctx context.Context) error { + return c.Internal.MpoolClear(ctx) +} + func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) { return c.Internal.MpoolPush(ctx, smsg) } diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 90d856258..79590ae86 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -973,3 +973,11 @@ func (mp *MessagePool) loadLocal() error { return nil } + +func (mp *MessagePool) Clear() { + mp.lk.Lock() + defer mp.lk.Unlock() + + mp.pending = make(map[address.Address]*msgSet) + mp.republished = nil +} diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index bde7d4f81..bb4ce2b62 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -105,6 +105,11 @@ func (a *MpoolAPI) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*ty } } +func (a *MpoolAPI) MpoolClear(ctx context.Context) error { + a.Mpool.Clear() + return nil +} + func (a *MpoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) { return a.Mpool.Push(smsg) }