Skip to content

Commit

Permalink
Better input type for chain prune
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Aug 5, 2022
1 parent 92b84de commit aed3aea
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 45 deletions.
7 changes: 6 additions & 1 deletion api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1223,3 +1223,8 @@ type MsigTransaction struct {

Approved []address.Address
}

type PruneOpts struct {
MovingGC bool
RetainState int64
}
2 changes: 1 addition & 1 deletion api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 4 additions & 32 deletions blockstore/splitstore/splitstore_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) }
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
9 changes: 4 additions & 5 deletions cli/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
},
Expand Down
3 changes: 2 additions & 1 deletion documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,8 @@ Inputs:
```json
[
{
"abc": 123
"MovingGC": true,
"RetainState": 9
}
]
```
Expand Down
3 changes: 1 addition & 2 deletions itests/splitstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aed3aea

Please sign in to comment.