From 613bb252973b654f53ef18103cf7ee748003d16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 11 Dec 2019 15:17:38 +0100 Subject: [PATCH] sectors: Handle sector state reload errors more gracefully --- build/version.go | 2 +- lib/statestore/store.go | 6 ++++- storage/sectors.go | 2 +- storage/sectors_test.go | 56 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 storage/sectors_test.go diff --git a/build/version.go b/build/version.go index 5b2079a61..10832a76a 100644 --- a/build/version.go +++ b/build/version.go @@ -22,7 +22,7 @@ const ( MajorOnlyMask = 0xff0000 MinorOnlyMask = 0x00ff00 PatchOnlyMask = 0x0000ff -c) +) // VersionInts returns (major, minor, patch) versions func VersionInts(version uint32) (uint32, uint32, uint32) { diff --git a/lib/statestore/store.go b/lib/statestore/store.go index 994938223..a334b60b8 100644 --- a/lib/statestore/store.go +++ b/lib/statestore/store.go @@ -8,6 +8,7 @@ import ( "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/query" cbg "github.com/whyrusleeping/cbor-gen" + "go.uber.org/multierr" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/lib/cborutil" @@ -139,6 +140,8 @@ func (st *StateStore) List(out interface{}) error { outT := reflect.TypeOf(out).Elem().Elem() rout := reflect.ValueOf(out) + var errs error + for { res, ok := res.NextSync() if !ok { @@ -151,7 +154,8 @@ func (st *StateStore) List(out interface{}) error { elem := reflect.New(outT) err := cborutil.ReadCborRPC(bytes.NewReader(res.Value), elem.Interface()) if err != nil { - return err + errs = multierr.Append(errs, xerrors.Errorf("decoding state for key '%s': %w", res.Key, err)) + continue } rout.Elem().Set(reflect.Append(rout.Elem(), elem.Elem())) diff --git a/storage/sectors.go b/storage/sectors.go index 8dad777cc..d52dc70b6 100644 --- a/storage/sectors.go +++ b/storage/sectors.go @@ -65,7 +65,7 @@ func (m *Miner) UpdateSectorState(ctx context.Context, sector uint64, snonce uin func (m *Miner) sectorStateLoop(ctx context.Context) error { trackedSectors, err := m.ListSectors() if err != nil { - return xerrors.Errorf("loading sector list: %w", err) + log.Errorf("loading sector list: %+v", err) } go func() { diff --git a/storage/sectors_test.go b/storage/sectors_test.go new file mode 100644 index 000000000..858e3876e --- /dev/null +++ b/storage/sectors_test.go @@ -0,0 +1,56 @@ +package storage + +import ( + "bytes" + "testing" + + "gotest.tools/assert" + + "github.com/filecoin-project/lotus/lib/cborutil" +) + +func TestSectorInfoSelialization(t *testing.T) { + si := &SectorInfo{ + State: 123, + SectorID: 234, + Nonce: 345, + Pieces: []Piece{{ + DealID: 1234, + Size: 5, + CommP: []byte{3}, + }}, + CommD: []byte{32, 4}, + CommR: nil, + Proof: nil, + Ticket: SealTicket{ + BlockHeight: 345, + TicketBytes: []byte{87, 78, 7, 87}, + }, + PreCommitMessage: nil, + Seed: SealSeed{}, + CommitMessage: nil, + FaultReportMsg: nil, + LastErr: "hi", + } + + b, err := cborutil.Dump(si) + if err != nil { + t.Fatal(err) + } + + var si2 SectorInfo + if err := cborutil.ReadCborRPC(bytes.NewReader(b), &si); err != nil { + return + } + + assert.Equal(t, si.State, si2.State) + assert.Equal(t, si.Nonce, si2.Nonce) + assert.Equal(t, si.SectorID, si2.SectorID) + + assert.Equal(t, si.Pieces, si2.Pieces) + assert.Equal(t, si.CommD, si2.CommD) + assert.Equal(t, si.Ticket, si2.Ticket) + + assert.Equal(t, si, si2) + +}