Add command to mark given blocks as bad
This commit is contained in:
parent
11bfab67f9
commit
897cf72933
@ -41,6 +41,7 @@ type FullNode interface {
|
|||||||
SyncState(context.Context) (*SyncState, error)
|
SyncState(context.Context) (*SyncState, error)
|
||||||
SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) error
|
SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) error
|
||||||
SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error)
|
SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error)
|
||||||
|
SyncMarkBad(ctx context.Context, bcid cid.Cid) error
|
||||||
|
|
||||||
// messages
|
// messages
|
||||||
MpoolPending(context.Context, *types.TipSet) ([]*types.SignedMessage, error)
|
MpoolPending(context.Context, *types.TipSet) ([]*types.SignedMessage, error)
|
||||||
|
@ -58,6 +58,7 @@ type FullNodeStruct struct {
|
|||||||
SyncState func(context.Context) (*api.SyncState, error) `perm:"read"`
|
SyncState func(context.Context) (*api.SyncState, error) `perm:"read"`
|
||||||
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
|
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
|
||||||
SyncIncomingBlocks func(ctx context.Context) (<-chan *types.BlockHeader, error) `perm:"read"`
|
SyncIncomingBlocks func(ctx context.Context) (<-chan *types.BlockHeader, error) `perm:"read"`
|
||||||
|
SyncMarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"write"`
|
||||||
|
|
||||||
MpoolPending func(context.Context, *types.TipSet) ([]*types.SignedMessage, error) `perm:"read"`
|
MpoolPending func(context.Context, *types.TipSet) ([]*types.SignedMessage, error) `perm:"read"`
|
||||||
MpoolPush func(context.Context, *types.SignedMessage) error `perm:"write"`
|
MpoolPush func(context.Context, *types.SignedMessage) error `perm:"write"`
|
||||||
@ -360,6 +361,10 @@ func (c *FullNodeStruct) SyncIncomingBlocks(ctx context.Context) (<-chan *types.
|
|||||||
return c.Internal.SyncIncomingBlocks(ctx)
|
return c.Internal.SyncIncomingBlocks(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) SyncMarkBad(ctx context.Context, bcid cid.Cid) error {
|
||||||
|
return c.Internal.SyncMarkBad(ctx, bcid)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*api.ChainSectorInfo, error) {
|
func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*api.ChainSectorInfo, error) {
|
||||||
return c.Internal.StateMinerSectors(ctx, addr, ts)
|
return c.Internal.StateMinerSectors(ctx, addr, ts)
|
||||||
}
|
}
|
||||||
|
@ -1181,3 +1181,7 @@ func (syncer *Syncer) State() []SyncerState {
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (syncer *Syncer) MarkBad(blk cid.Cid) {
|
||||||
|
syncer.bad.Add(blk)
|
||||||
|
}
|
||||||
|
25
cli/sync.go
25
cli/sync.go
@ -19,6 +19,7 @@ var syncCmd = &cli.Command{
|
|||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
syncStatusCmd,
|
syncStatusCmd,
|
||||||
syncWaitCmd,
|
syncWaitCmd,
|
||||||
|
syncMarkBadCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +91,30 @@ var syncWaitCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var syncMarkBadCmd = &cli.Command{
|
||||||
|
Name: "mark-bad",
|
||||||
|
Usage: "Mark the given block as bad, will prevent syncing to a chain that contains it",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
napi, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
if !cctx.Args().Present() {
|
||||||
|
return fmt.Errorf("must specify block cid to mark")
|
||||||
|
}
|
||||||
|
|
||||||
|
bcid, err := cid.Decode(cctx.Args().First())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to decode input as a cid: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return napi.SyncMarkBad(ctx, bcid)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func SyncWait(ctx context.Context, napi api.FullNode) error {
|
func SyncWait(ctx context.Context, napi api.FullNode) error {
|
||||||
for {
|
for {
|
||||||
state, err := napi.SyncState(ctx)
|
state, err := napi.SyncState(ctx)
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain"
|
"github.com/filecoin-project/lotus/chain"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
cid "github.com/ipfs/go-cid"
|
||||||
|
"github.com/prometheus/common/log"
|
||||||
|
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
@ -80,3 +82,9 @@ func (a *SyncAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) erro
|
|||||||
func (a *SyncAPI) SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error) {
|
func (a *SyncAPI) SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error) {
|
||||||
return a.Syncer.IncomingBlocks(ctx)
|
return a.Syncer.IncomingBlocks(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *SyncAPI) SyncMarkBad(ctx context.Context, bcid cid.Cid) error {
|
||||||
|
log.Warnf("Marking block %s as bad", bcid)
|
||||||
|
a.Syncer.MarkBad(bcid)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user