Commit f39d270e authored by laser's avatar laser
Browse files

refactor(enum): extract sealed sector health into package

parent 632a680c
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"time" "time"
"unsafe" "unsafe"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
...@@ -24,18 +26,6 @@ func elapsed(what string) func() { ...@@ -24,18 +26,6 @@ func elapsed(what string) func() {
} }
} }
// SealedSectorHealth represents the healthiness of a sector managed by a
// sector builder.
type SealedSectorHealth int
const (
Unknown SealedSectorHealth = iota
Ok // everything is fine
ErrorInvalidChecksum // sector exists, but checksum is invalid
ErrorInvalidLength // sector exists, but length is incorrect
ErrorMissing // sector no longer exists
)
// SortedSectorInfo is a slice of SectorInfo sorted (lexicographically, // SortedSectorInfo is a slice of SectorInfo sorted (lexicographically,
// ascending) by replica commitment (CommR). // ascending) by replica commitment (CommR).
type SortedSectorInfo struct { type SortedSectorInfo struct {
...@@ -83,7 +73,7 @@ type SealedSectorMetadata struct { ...@@ -83,7 +73,7 @@ type SealedSectorMetadata struct {
CommRStar [CommitmentBytesLen]byte CommRStar [CommitmentBytesLen]byte
Proof []byte Proof []byte
Pieces []PieceMetadata Pieces []PieceMetadata
Health SealedSectorHealth Health sealed_sector_health.Health
} }
// SectorSealingStatus communicates how far along in the sealing process a // SectorSealingStatus communicates how far along in the sealing process a
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"unsafe" "unsafe"
sb "github.com/filecoin-project/go-sectorbuilder" sb "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -98,7 +99,7 @@ func TestSectorBuilderLifecycle(t *testing.T) { ...@@ -98,7 +99,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
sealedSector := sealedSectors[0] sealedSector := sealedSectors[0]
require.Equal(t, uint64(1), sealedSector.SectorID) require.Equal(t, uint64(1), sealedSector.SectorID)
require.Equal(t, 1, len(sealedSector.Pieces)) require.Equal(t, 1, len(sealedSector.Pieces))
require.Equal(t, sb.Ok, sealedSector.Health) require.Equal(t, sealed_sector_health.Ok, sealedSector.Health)
// the piece is the size of the sector, so its piece commitment should be the // the piece is the size of the sector, so its piece commitment should be the
// data commitment // data commitment
require.Equal(t, commP, sealedSector.CommD) require.Equal(t, commP, sealedSector.CommD)
......
package sealed_sector_health
// Health represents the healthiness of a sector managed by a
// sector builder.
type Health int
const (
Unknown Health = iota
Ok // everything is fine
ErrorInvalidChecksum // sector exists, but checksum is invalid
ErrorInvalidLength // sector exists, but length is incorrect
ErrorMissing // sector no longer exists
)
...@@ -3,6 +3,8 @@ package go_sectorbuilder ...@@ -3,6 +3,8 @@ package go_sectorbuilder
import ( import (
"unsafe" "unsafe"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
...@@ -127,19 +129,19 @@ func goPieceMetadata(src *C.sector_builder_ffi_FFIPieceMetadata, size C.size_t) ...@@ -127,19 +129,19 @@ func goPieceMetadata(src *C.sector_builder_ffi_FFIPieceMetadata, size C.size_t)
return ps, nil return ps, nil
} }
func goSealedSectorHealth(health C.sector_builder_ffi_FFISealedSectorHealth) (SealedSectorHealth, error) { func goSealedSectorHealth(health C.sector_builder_ffi_FFISealedSectorHealth) (sealed_sector_health.Health, error) {
switch health { switch health {
case C.Unknown: case C.Unknown:
return Unknown, nil return sealed_sector_health.Unknown, nil
case C.Ok: case C.Ok:
return Ok, nil return sealed_sector_health.Ok, nil
case C.ErrorInvalidChecksum: case C.ErrorInvalidChecksum:
return ErrorInvalidChecksum, nil return sealed_sector_health.ErrorInvalidChecksum, nil
case C.ErrorInvalidLength: case C.ErrorInvalidLength:
return ErrorInvalidLength, nil return sealed_sector_health.ErrorInvalidLength, nil
case C.ErrorMissing: case C.ErrorMissing:
return ErrorMissing, nil return sealed_sector_health.ErrorMissing, nil
default: default:
return Unknown, errors.Errorf("unhandled sealed sector health: %v", health) return sealed_sector_health.Unknown, errors.Errorf("unhandled sealed sector health: %v", health)
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment