sync unmark-bad --all
This commit is contained in:
parent
1401efb115
commit
18e58467f8
@ -172,6 +172,9 @@ type FullNode interface {
|
|||||||
// SyncUnmarkBad unmarks a blocks as bad, making it possible to be validated and synced again.
|
// SyncUnmarkBad unmarks a blocks as bad, making it possible to be validated and synced again.
|
||||||
SyncUnmarkBad(ctx context.Context, bcid cid.Cid) error
|
SyncUnmarkBad(ctx context.Context, bcid cid.Cid) error
|
||||||
|
|
||||||
|
// SyncUnmarkAllBad purges bad block cache, making it possible to sync to chains previously marked as bad
|
||||||
|
SyncUnmarkAllBad(ctx context.Context) error
|
||||||
|
|
||||||
// SyncCheckBad checks if a block was marked as bad, and if it was, returns
|
// SyncCheckBad checks if a block was marked as bad, and if it was, returns
|
||||||
// the reason.
|
// the reason.
|
||||||
SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error)
|
SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error)
|
||||||
|
@ -111,6 +111,7 @@ type FullNodeStruct struct {
|
|||||||
SyncCheckpoint func(ctx context.Context, key types.TipSetKey) error `perm:"admin"`
|
SyncCheckpoint func(ctx context.Context, key types.TipSetKey) error `perm:"admin"`
|
||||||
SyncMarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"admin"`
|
SyncMarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"admin"`
|
||||||
SyncUnmarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"admin"`
|
SyncUnmarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"admin"`
|
||||||
|
SyncUnmarkAllBad func(ctx context.Context) error `perm:"admin"`
|
||||||
SyncCheckBad func(ctx context.Context, bcid cid.Cid) (string, error) `perm:"read"`
|
SyncCheckBad func(ctx context.Context, bcid cid.Cid) (string, error) `perm:"read"`
|
||||||
SyncValidateTipset func(ctx context.Context, tsk types.TipSetKey) (bool, error) `perm:"read"`
|
SyncValidateTipset func(ctx context.Context, tsk types.TipSetKey) (bool, error) `perm:"read"`
|
||||||
|
|
||||||
@ -780,6 +781,10 @@ func (c *FullNodeStruct) SyncUnmarkBad(ctx context.Context, bcid cid.Cid) error
|
|||||||
return c.Internal.SyncUnmarkBad(ctx, bcid)
|
return c.Internal.SyncUnmarkBad(ctx, bcid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) SyncUnmarkAllBad(ctx context.Context) error {
|
||||||
|
return c.Internal.SyncUnmarkAllBad(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error) {
|
func (c *FullNodeStruct) SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error) {
|
||||||
return c.Internal.SyncCheckBad(ctx, bcid)
|
return c.Internal.SyncCheckBad(ctx, bcid)
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,10 @@ func (bts *BadBlockCache) Remove(c cid.Cid) {
|
|||||||
bts.badBlocks.Remove(c)
|
bts.badBlocks.Remove(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bts *BadBlockCache) Purge() {
|
||||||
|
bts.badBlocks.Purge()
|
||||||
|
}
|
||||||
|
|
||||||
func (bts *BadBlockCache) Has(c cid.Cid) (BadBlockReason, bool) {
|
func (bts *BadBlockCache) Has(c cid.Cid) (BadBlockReason, bool) {
|
||||||
rval, ok := bts.badBlocks.Get(c)
|
rval, ok := bts.badBlocks.Get(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -1740,6 +1740,10 @@ func (syncer *Syncer) UnmarkBad(blk cid.Cid) {
|
|||||||
syncer.bad.Remove(blk)
|
syncer.bad.Remove(blk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (syncer *Syncer) UnmarkAllBad() {
|
||||||
|
syncer.bad.Purge()
|
||||||
|
}
|
||||||
|
|
||||||
func (syncer *Syncer) CheckBadBlockCache(blk cid.Cid) (string, bool) {
|
func (syncer *Syncer) CheckBadBlockCache(blk cid.Cid) (string, bool) {
|
||||||
bbr, ok := syncer.bad.Has(blk)
|
bbr, ok := syncer.bad.Has(blk)
|
||||||
return bbr.String(), ok
|
return bbr.String(), ok
|
||||||
|
10
cli/sync.go
10
cli/sync.go
@ -124,6 +124,12 @@ var syncMarkBadCmd = &cli.Command{
|
|||||||
var syncUnmarkBadCmd = &cli.Command{
|
var syncUnmarkBadCmd = &cli.Command{
|
||||||
Name: "unmark-bad",
|
Name: "unmark-bad",
|
||||||
Usage: "Unmark the given block as bad, makes it possible to sync to a chain containing it",
|
Usage: "Unmark the given block as bad, makes it possible to sync to a chain containing it",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "all",
|
||||||
|
Usage: "drop the entire bad block cache",
|
||||||
|
},
|
||||||
|
},
|
||||||
ArgsUsage: "[blockCid]",
|
ArgsUsage: "[blockCid]",
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
napi, closer, err := GetFullNodeAPI(cctx)
|
napi, closer, err := GetFullNodeAPI(cctx)
|
||||||
@ -133,6 +139,10 @@ var syncUnmarkBadCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
if cctx.Bool("all") {
|
||||||
|
return napi.SyncUnmarkAllBad(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
if !cctx.Args().Present() {
|
if !cctx.Args().Present() {
|
||||||
return fmt.Errorf("must specify block cid to unmark")
|
return fmt.Errorf("must specify block cid to unmark")
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,12 @@ func (a *SyncAPI) SyncUnmarkBad(ctx context.Context, bcid cid.Cid) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *SyncAPI) SyncUnmarkAllBad(ctx context.Context) error {
|
||||||
|
log.Warnf("Dropping bad block cache")
|
||||||
|
a.Syncer.UnmarkAllBad()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *SyncAPI) SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error) {
|
func (a *SyncAPI) SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error) {
|
||||||
reason, ok := a.Syncer.CheckBadBlockCache(bcid)
|
reason, ok := a.Syncer.CheckBadBlockCache(bcid)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user