diff --git a/lib/statestore/store.go b/lib/statestore/store.go index c32c3ff22..994938223 100644 --- a/lib/statestore/store.go +++ b/lib/statestore/store.go @@ -39,7 +39,7 @@ func (st *StateStore) Begin(i interface{}, state interface{}) error { return err } if has { - return xerrors.Errorf("Already tracking state for %s", i) + return xerrors.Errorf("already tracking state for %v", i) } b, err := cborutil.Dump(state) @@ -111,12 +111,16 @@ func (st *StateStore) mutate(i interface{}, mutator func([]byte) ([]byte, error) return st.ds.Put(k, mutated) } +func (st *StateStore) Has(i interface{}) (bool, error) { + return st.ds.Has(toKey(i)) +} + func (st *StateStore) Get(i interface{}, out cbg.CBORUnmarshaler) error { k := toKey(i) val, err := st.ds.Get(k) if err != nil { if xerrors.Is(err, datastore.ErrNotFound) { - return xerrors.Errorf("No state for %s", i) + return xerrors.Errorf("No state for %s: %w", i, err) } return err } diff --git a/storage/sealing.go b/storage/sealing.go index 637eb8da2..a2723680d 100644 --- a/storage/sealing.go +++ b/storage/sealing.go @@ -61,6 +61,15 @@ func (m *Miner) sectorStateLoop(ctx context.Context) { } func (m *Miner) onSectorIncoming(sector *SectorInfo) { + has, err := m.sectors.Has(sector.SectorID) + if err != nil { + return + } + if has { + log.Warnf("SealSector called more than once for sector %d", sector.SectorID) + return + } + if err := m.sectors.Begin(sector.SectorID, sector); err != nil { // We may have re-sent the proposal log.Errorf("deal tracking failed: %s", err)