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 (
"time"
"unsafe"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
logging "github.com/ipfs/go-log"
"github.com/pkg/errors"
)
......@@ -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,
// ascending) by replica commitment (CommR).
type SortedSectorInfo struct {
......@@ -83,7 +73,7 @@ type SealedSectorMetadata struct {
CommRStar [CommitmentBytesLen]byte
Proof []byte
Pieces []PieceMetadata
Health SealedSectorHealth
Health sealed_sector_health.Health
}
// SectorSealingStatus communicates how far along in the sealing process a
......
......@@ -12,6 +12,7 @@ import (
"unsafe"
sb "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
"github.com/stretchr/testify/require"
)
......@@ -98,7 +99,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
sealedSector := sealedSectors[0]
require.Equal(t, uint64(1), sealedSector.SectorID)
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
// data commitment
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
import (
"unsafe"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
"github.com/pkg/errors"
)
......@@ -127,19 +129,19 @@ func goPieceMetadata(src *C.sector_builder_ffi_FFIPieceMetadata, size C.size_t)
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 {
case C.Unknown:
return Unknown, nil
return sealed_sector_health.Unknown, nil
case C.Ok:
return Ok, nil
return sealed_sector_health.Ok, nil
case C.ErrorInvalidChecksum:
return ErrorInvalidChecksum, nil
return sealed_sector_health.ErrorInvalidChecksum, nil
case C.ErrorInvalidLength:
return ErrorInvalidLength, nil
return sealed_sector_health.ErrorInvalidLength, nil
case C.ErrorMissing:
return ErrorMissing, nil
return sealed_sector_health.ErrorMissing, nil
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