diff --git a/api/api_full.go b/api/api_full.go index c8c60dd6fea..697d87e63f4 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -171,7 +171,7 @@ type FullNode interface { // ChainPrune prunes the stored chain state and garbage collects; only supported if you // are using the splitstore - ChainPrune(ctx context.Context, opts map[string]interface{}) error //perm:admin + ChainPrune(ctx context.Context, opts PruneOpts) error //perm:admin // ChainCheckBlockstore performs an (asynchronous) health check on the chain/state blockstore // if supported by the underlying implementation. @@ -1223,3 +1223,8 @@ type MsigTransaction struct { Approved []address.Address } + +type PruneOpts struct { + MovingGC bool + RetainState int64 +} diff --git a/api/mocks/mock_full.go b/api/mocks/mock_full.go index adf34224a58..5aa152c85e2 100644 --- a/api/mocks/mock_full.go +++ b/api/mocks/mock_full.go @@ -378,7 +378,7 @@ func (mr *MockFullNodeMockRecorder) ChainNotify(arg0 interface{}) *gomock.Call { } // ChainPrune mocks base method. -func (m *MockFullNode) ChainPrune(arg0 context.Context, arg1 map[string]interface{}) error { +func (m *MockFullNode) ChainPrune(arg0 context.Context, arg1 api.PruneOpts) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ChainPrune", arg0, arg1) ret0, _ := ret[0].(error) diff --git a/api/proxy_gen.go b/api/proxy_gen.go index 92820a92812..5de9caae22b 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -145,7 +145,7 @@ type FullNodeStruct struct { ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) `perm:"read"` - ChainPrune func(p0 context.Context, p1 map[string]interface{}) error `perm:"admin"` + ChainPrune func(p0 context.Context, p1 PruneOpts) error `perm:"admin"` ChainPutObj func(p0 context.Context, p1 blocks.Block) error `perm:"admin"` @@ -1342,14 +1342,14 @@ func (s *FullNodeStub) ChainNotify(p0 context.Context) (<-chan []*HeadChange, er return nil, ErrNotSupported } -func (s *FullNodeStruct) ChainPrune(p0 context.Context, p1 map[string]interface{}) error { +func (s *FullNodeStruct) ChainPrune(p0 context.Context, p1 PruneOpts) error { if s.Internal.ChainPrune == nil { return ErrNotSupported } return s.Internal.ChainPrune(p0, p1) } -func (s *FullNodeStub) ChainPrune(p0 context.Context, p1 map[string]interface{}) error { +func (s *FullNodeStub) ChainPrune(p0 context.Context, p1 PruneOpts) error { return ErrNotSupported } diff --git a/blockstore/splitstore/splitstore_prune.go b/blockstore/splitstore/splitstore_prune.go index ba7a68e3f8b..c997c075b94 100644 --- a/blockstore/splitstore/splitstore_prune.go +++ b/blockstore/splitstore/splitstore_prune.go @@ -14,6 +14,7 @@ import ( "go.opencensus.io/stats" "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/api" bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" @@ -44,40 +45,11 @@ var ( // PruneChain instructs the SplitStore to prune chain state in the coldstore, according to the // options specified. -func (s *SplitStore) PruneChain(opts map[string]interface{}) error { - // options - var onlineGC, movingGC bool - var retainState int64 = -1 - - for k, v := range opts { - switch k { - case PruneOnlineGC: - onlineGC = true - case PruneRetainState: - retaini64, ok := v.(int64) - if !ok { - // deal with json-rpc types... - retainf64, ok := v.(float64) - if !ok { - return xerrors.Errorf("bad state retention specification; expected int64 or float64 but got %T", v) - } - retainState = int64(retainf64) - } else { - retainState = retaini64 - } - default: - return xerrors.Errorf("unrecognized option %s", k) - } - } +func (s *SplitStore) PruneChain(opts api.PruneOpts) error { + retainState := opts.RetainState - if onlineGC && movingGC { - return xerrors.Errorf("at most one of online, moving GC can be specified") - } - if !onlineGC && !movingGC { - onlineGC = true - } var gcOpts []bstore.BlockstoreGCOption - if movingGC { + if opts.MovingGC { gcOpts = append(gcOpts, bstore.WithFullGC(true)) } doGC := func() error { return s.gcBlockstore(s.cold, gcOpts) } diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index 2e1a976aae7..29959a5d145 100644 Binary files a/build/openrpc/full.json.gz and b/build/openrpc/full.json.gz differ diff --git a/cli/chain.go b/cli/chain.go index 80b3ffa61ec..48fbb849ddc 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -35,7 +35,6 @@ import ( "github.com/filecoin-project/lotus/api" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/v0api" - "github.com/filecoin-project/lotus/blockstore/splitstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/consensus/filcns" @@ -1497,14 +1496,14 @@ var ChainPruneCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) - opts := make(map[string]interface{}) + opts := lapi.PruneOpts{} if cctx.Bool("online-gc") { - opts[splitstore.PruneOnlineGC] = true + opts.MovingGC = false } if cctx.Bool("moving-gc") { - opts[splitstore.PruneMovingGC] = cctx.String("move-to") + opts.MovingGC = true } - opts[splitstore.PruneRetainState] = int64(cctx.Int("retention")) + opts.RetainState = int64(cctx.Int("retention")) return api.ChainPrune(ctx, opts) }, diff --git a/documentation/en/api-v1-unstable-methods.md b/documentation/en/api-v1-unstable-methods.md index 76aae58e340..a0015a51e68 100644 --- a/documentation/en/api-v1-unstable-methods.md +++ b/documentation/en/api-v1-unstable-methods.md @@ -974,7 +974,8 @@ Inputs: ```json [ { - "abc": 123 + "MovingGC": true, + "RetainState": 9 } ] ``` diff --git a/itests/splitstore_test.go b/itests/splitstore_test.go index 618a71aee65..2bb188598fa 100644 --- a/itests/splitstore_test.go +++ b/itests/splitstore_test.go @@ -161,8 +161,7 @@ func TestColdStorePrune(t *testing.T) { break } } - pruneOpts := make(map[string]interface{}) - pruneOpts[splitstore.PruneRetainState] = int64(0) // Prune from compaction boundary + pruneOpts := api.PruneOpts{RetainState: int64(0), MovingGC: false} require.NoError(t, full.ChainPrune(ctx, pruneOpts)) bm.Restart() waitForPrune(ctx, t, 1, full)