add dagstore register-shard command
This commit is contained in:
@@ -37,8 +37,10 @@ import (
|
||||
"github.com/filecoin-project/go-fil-markets/piecestore"
|
||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||
filmktsstore "github.com/filecoin-project/go-fil-markets/stores"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
mktsdagstore "github.com/filecoin-project/lotus/markets/dagstore"
|
||||
|
||||
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
|
||||
@@ -83,6 +85,7 @@ type StorageMinerAPI struct {
|
||||
SectorBlocks *sectorblocks.SectorBlocks `optional:"true"`
|
||||
Host host.Host `optional:"true"`
|
||||
DAGStore *dagstore.DAGStore `optional:"true"`
|
||||
DAGStoreWrapper *mktsdagstore.Wrapper `optional:"true"`
|
||||
|
||||
// Miner / storage
|
||||
Miner *storage.Miner `optional:"true"`
|
||||
@@ -792,6 +795,35 @@ func (sm *StorageMinerAPI) DagstoreListShards(ctx context.Context) ([]api.Dagsto
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) DagstoreRegisterShard(ctx context.Context, key string) error {
|
||||
if sm.DAGStore == nil {
|
||||
return fmt.Errorf("dagstore not available on this node")
|
||||
}
|
||||
|
||||
// First check if the shard has already been registered
|
||||
k := shard.KeyFromString(key)
|
||||
_, err := sm.DAGStore.GetShardInfo(k)
|
||||
if err == nil {
|
||||
// Shard already registered, nothing further to do
|
||||
return nil
|
||||
}
|
||||
// If the shard is not registered we would expect ErrShardUnknown
|
||||
if !errors.Is(err, dagstore.ErrShardUnknown) {
|
||||
return fmt.Errorf("getting shard info from DAG store: %w", err)
|
||||
}
|
||||
|
||||
pieceCid, err := cid.Parse(key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing shard key as piece cid: %w", err)
|
||||
}
|
||||
|
||||
if err = filmktsstore.RegisterShardSync(ctx, sm.DAGStoreWrapper, pieceCid, "", true); err != nil {
|
||||
return fmt.Errorf("failed to register shard: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) DagstoreInitializeShard(ctx context.Context, key string) error {
|
||||
if sm.DAGStore == nil {
|
||||
return fmt.Errorf("dagstore not available on this node")
|
||||
|
||||
Reference in New Issue
Block a user