Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-sectorbuilder
Commits
f39d270e
Commit
f39d270e
authored
Sep 13, 2019
by
laser
Browse files
refactor(enum): extract sealed sector health into package
parent
632a680c
Changes
4
Hide whitespace changes
Inline
Side-by-side
bindings.go
View file @
f39d270e
...
@@ -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
S
ealed
S
ectorHealth
Health
s
ealed
_s
ector
_health
.
Health
}
}
// SectorSealingStatus communicates how far along in the sealing process a
// SectorSealingStatus communicates how far along in the sealing process a
...
...
bindings_test.go
View file @
f39d270e
...
@@ -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
,
s
b
.
Ok
,
sealedSector
.
Health
)
require
.
Equal
(
t
,
s
ealed_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
)
...
...
sealed_sector_health/health.go
0 → 100644
View file @
f39d270e
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
)
transforms.go
View file @
f39d270e
...
@@ -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
)
(
S
ealed
S
ectorHealth
,
error
)
{
func
goSealedSectorHealth
(
health
C
.
sector_builder_ffi_FFISealedSectorHealth
)
(
s
ealed
_s
ector
_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
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment