storageminer: cmd to list sector commitments
This commit is contained in:
parent
169c285fb3
commit
44f4ee0de1
10
api/api.go
10
api/api.go
@ -168,6 +168,8 @@ type StorageMiner interface {
|
|||||||
SectorsList(context.Context) ([]uint64, error)
|
SectorsList(context.Context) ([]uint64, error)
|
||||||
|
|
||||||
SectorsRefs(context.Context) (map[string][]SealedRef, error)
|
SectorsRefs(context.Context) (map[string][]SealedRef, error)
|
||||||
|
|
||||||
|
CommitmentsList(context.Context) ([]SectorCommitment, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version provides various build-time information
|
// Version provides various build-time information
|
||||||
@ -330,6 +332,14 @@ type SyncState struct {
|
|||||||
Height uint64
|
Height uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SectorCommitment struct {
|
||||||
|
SectorID uint64
|
||||||
|
Miner address.Address
|
||||||
|
|
||||||
|
CommitMsg cid.Cid
|
||||||
|
DealIDs []uint64
|
||||||
|
}
|
||||||
|
|
||||||
type SyncStateStage int
|
type SyncStateStage int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -133,6 +133,8 @@ type StorageMinerStruct struct {
|
|||||||
SectorsList func(context.Context) ([]uint64, error) `perm:"read"`
|
SectorsList func(context.Context) ([]uint64, error) `perm:"read"`
|
||||||
|
|
||||||
SectorsRefs func(context.Context) (map[string][]SealedRef, error) `perm:"read"`
|
SectorsRefs func(context.Context) (map[string][]SealedRef, error) `perm:"read"`
|
||||||
|
|
||||||
|
CommitmentsList func(context.Context) ([]SectorCommitment, error) `perm:"read"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,6 +481,10 @@ func (c *StorageMinerStruct) SectorsRefs(ctx context.Context) (map[string][]Seal
|
|||||||
return c.Internal.SectorsRefs(ctx)
|
return c.Internal.SectorsRefs(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *StorageMinerStruct) CommitmentsList(ctx context.Context) ([]SectorCommitment, error) {
|
||||||
|
return c.Internal.CommitmentsList(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
var _ Common = &CommonStruct{}
|
var _ Common = &CommonStruct{}
|
||||||
var _ FullNode = &FullNodeStruct{}
|
var _ FullNode = &FullNodeStruct{}
|
||||||
var _ StorageMiner = &StorageMinerStruct{}
|
var _ StorageMiner = &StorageMinerStruct{}
|
||||||
|
41
cmd/lotus-storage-miner/commitments.go
Normal file
41
cmd/lotus-storage-miner/commitments.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
|
||||||
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var commitmentsCmd = &cli.Command{
|
||||||
|
Name: "commitments",
|
||||||
|
Usage: "interact with commitment tracker",
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
commitmentsListCmd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var commitmentsListCmd = &cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "List tracked sector commitments",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
comms, err := api.CommitmentsList(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, comm := range comms {
|
||||||
|
fmt.Printf("%s:%d msg:%s, deals: %v\n", comm.Miner, comm.SectorID, comm.CommitMsg, comm.DealIDs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
@ -24,6 +24,7 @@ func main() {
|
|||||||
infoCmd,
|
infoCmd,
|
||||||
storeGarbageCmd,
|
storeGarbageCmd,
|
||||||
sectorsCmd,
|
sectorsCmd,
|
||||||
|
commitmentsCmd,
|
||||||
}
|
}
|
||||||
jaeger := tracing.SetupJaegerTracing("lotus")
|
jaeger := tracing.SetupJaegerTracing("lotus")
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/address"
|
"github.com/filecoin-project/lotus/chain/address"
|
||||||
"github.com/filecoin-project/lotus/lib/sectorbuilder"
|
"github.com/filecoin-project/lotus/lib/sectorbuilder"
|
||||||
"github.com/filecoin-project/lotus/storage"
|
"github.com/filecoin-project/lotus/storage"
|
||||||
|
"github.com/filecoin-project/lotus/storage/commitment"
|
||||||
"github.com/filecoin-project/lotus/storage/sector"
|
"github.com/filecoin-project/lotus/storage/sector"
|
||||||
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ type StorageMinerAPI struct {
|
|||||||
SectorBuilder *sectorbuilder.SectorBuilder
|
SectorBuilder *sectorbuilder.SectorBuilder
|
||||||
Sectors *sector.Store
|
Sectors *sector.Store
|
||||||
SectorBlocks *sectorblocks.SectorBlocks
|
SectorBlocks *sectorblocks.SectorBlocks
|
||||||
|
CommitmentTracker *commitment.Tracker
|
||||||
|
|
||||||
Miner *storage.Miner
|
Miner *storage.Miner
|
||||||
}
|
}
|
||||||
@ -81,4 +83,8 @@ func (sm *StorageMinerAPI) SectorsRefs(context.Context) (map[string][]api.Sealed
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sm *StorageMinerAPI) CommitmentsList(ctx context.Context) ([]api.SectorCommitment, error) {
|
||||||
|
return sm.CommitmentTracker.List()
|
||||||
|
}
|
||||||
|
|
||||||
var _ api.StorageMiner = &StorageMinerAPI{}
|
var _ api.StorageMiner = &StorageMinerAPI{}
|
||||||
|
@ -3,6 +3,8 @@ package commitment
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -12,8 +14,10 @@ import (
|
|||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/address"
|
"github.com/filecoin-project/lotus/chain/address"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
dsq "github.com/ipfs/go-datastore/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("commitment")
|
var log = logging.Logger("commitment")
|
||||||
@ -145,3 +149,56 @@ func (ct *Tracker) CheckCommitment(miner address.Address, sectorId uint64) (bool
|
|||||||
|
|
||||||
return ct.commitments.Has(key)
|
return ct.commitments.Has(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ct *Tracker) List() ([]api.SectorCommitment, error) {
|
||||||
|
out := make([]api.SectorCommitment, 0)
|
||||||
|
|
||||||
|
ct.lk.Lock()
|
||||||
|
defer ct.lk.Unlock()
|
||||||
|
|
||||||
|
res, err := ct.commitments.Query(dsq.Query{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer res.Close()
|
||||||
|
|
||||||
|
for {
|
||||||
|
res, ok := res.NextSync()
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Error != nil {
|
||||||
|
return nil, xerrors.Errorf("iterating commitments: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(res.Key, "/")
|
||||||
|
if len(parts) != 4 {
|
||||||
|
return nil, xerrors.Errorf("expected commitment key to be 4 parts, Key %s", res.Key)
|
||||||
|
}
|
||||||
|
|
||||||
|
miner, err := address.NewFromString(parts[2])
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("parsing miner address: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sectorID, err := strconv.ParseInt(parts[3], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("parsing sector id: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var comm commitment
|
||||||
|
if err := cbor.DecodeInto(res.Value, &comm); err != nil {
|
||||||
|
return nil, xerrors.Errorf("decoding commitment %s (`% X`): %w", res.Key, res.Value, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, api.SectorCommitment{
|
||||||
|
SectorID: uint64(sectorID),
|
||||||
|
Miner: miner,
|
||||||
|
CommitMsg: comm.Msg,
|
||||||
|
DealIDs: comm.DealIDs,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
@ -2,9 +2,9 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
|
Loading…
Reference in New Issue
Block a user