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
c6682d93
Unverified
Commit
c6682d93
authored
Sep 17, 2019
by
Erin Swenson-Healey
Committed by
GitHub
Sep 17, 2019
Browse files
Merge pull request #21 from filecoin-project/feat/4-consts-for-seal-status-codes
feat/4 consts for seal status codes
parents
632a680c
6e668981
Changes
5
Show whitespace changes
Inline
Side-by-side
bindings.go
View file @
c6682d93
...
@@ -6,6 +6,9 @@ import (
...
@@ -6,6 +6,9 @@ import (
"time"
"time"
"unsafe"
"unsafe"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
logging
"github.com/ipfs/go-log"
logging
"github.com/ipfs/go-log"
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
...
@@ -24,18 +27,6 @@ func elapsed(what string) func() {
...
@@ -24,18 +27,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,20 +74,20 @@ type SealedSectorMetadata struct {
...
@@ -83,20 +74,20 @@ 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
// sector has progressed.
// sector has progressed.
type
SectorSealingStatus
struct
{
type
SectorSealingStatus
struct
{
SectorID
uint64
SectorID
uint64
S
ealStatusCode
uint8
// Sealed = 0, Pending = 1, Failed = 2, Sealing = 3
S
tate
sealing_state
.
State
SealErrorMsg
string
// will be nil unless S
ealStatusCode == 2
SealErrorMsg
string
// will be nil unless S
tate == Failed
CommD
[
CommitmentBytesLen
]
byte
// will be empty unless S
ealStatusCode == 0
CommD
[
CommitmentBytesLen
]
byte
// will be empty unless S
tate == Sealed
CommR
[
CommitmentBytesLen
]
byte
// will be empty unless S
ealStatusCode == 0
CommR
[
CommitmentBytesLen
]
byte
// will be empty unless S
tate == Sealed
CommRStar
[
CommitmentBytesLen
]
byte
// will be empty unless S
ealStatusCode == 0
CommRStar
[
CommitmentBytesLen
]
byte
// will be empty unless S
tate == Sealed
Proof
[]
byte
// will be empty unless S
ealStatusCode == 0
Proof
[]
byte
// will be empty unless S
tate == Sealed
Pieces
[]
PieceMetadata
// will be empty unless S
ealStatusCode == 0
Pieces
[]
PieceMetadata
// will be empty unless S
tate == Sealed
}
}
// PieceMetadata represents a piece stored by the sector builder.
// PieceMetadata represents a piece stored by the sector builder.
...
@@ -418,11 +409,11 @@ func GetSectorSealingStatusByID(sectorBuilderPtr unsafe.Pointer, sectorID uint64
...
@@ -418,11 +409,11 @@ func GetSectorSealingStatusByID(sectorBuilderPtr unsafe.Pointer, sectorID uint64
}
}
if
resPtr
.
seal_status_code
==
C
.
Failed
{
if
resPtr
.
seal_status_code
==
C
.
Failed
{
return
SectorSealingStatus
{
SectorID
:
sectorID
,
S
ealStatusCode
:
2
,
SealErrorMsg
:
C
.
GoString
(
resPtr
.
seal_error_msg
)},
nil
return
SectorSealingStatus
{
SectorID
:
sectorID
,
S
tate
:
sealing_state
.
Failed
,
SealErrorMsg
:
C
.
GoString
(
resPtr
.
seal_error_msg
)},
nil
}
else
if
resPtr
.
seal_status_code
==
C
.
Pending
{
}
else
if
resPtr
.
seal_status_code
==
C
.
Pending
{
return
SectorSealingStatus
{
SectorID
:
sectorID
,
S
ealStatusCode
:
1
},
nil
return
SectorSealingStatus
{
SectorID
:
sectorID
,
S
tate
:
sealing_state
.
Pending
},
nil
}
else
if
resPtr
.
seal_status_code
==
C
.
Sealing
{
}
else
if
resPtr
.
seal_status_code
==
C
.
Sealing
{
return
SectorSealingStatus
{
SectorID
:
sectorID
,
S
ealStatusCode
:
3
},
nil
return
SectorSealingStatus
{
SectorID
:
sectorID
,
S
tate
:
sealing_state
.
Sealing
},
nil
}
else
if
resPtr
.
seal_status_code
==
C
.
Sealed
{
}
else
if
resPtr
.
seal_status_code
==
C
.
Sealed
{
commRSlice
:=
goBytes
(
&
resPtr
.
comm_r
[
0
],
CommitmentBytesLen
)
commRSlice
:=
goBytes
(
&
resPtr
.
comm_r
[
0
],
CommitmentBytesLen
)
var
commR
[
CommitmentBytesLen
]
byte
var
commR
[
CommitmentBytesLen
]
byte
...
@@ -445,7 +436,7 @@ func GetSectorSealingStatusByID(sectorBuilderPtr unsafe.Pointer, sectorID uint64
...
@@ -445,7 +436,7 @@ func GetSectorSealingStatusByID(sectorBuilderPtr unsafe.Pointer, sectorID uint64
return
SectorSealingStatus
{
return
SectorSealingStatus
{
SectorID
:
sectorID
,
SectorID
:
sectorID
,
S
ealStatusCode
:
0
,
S
tate
:
sealing_state
.
Sealed
,
CommD
:
commD
,
CommD
:
commD
,
CommR
:
commR
,
CommR
:
commR
,
CommRStar
:
commRStar
,
CommRStar
:
commRStar
,
...
...
bindings_test.go
View file @
c6682d93
...
@@ -12,6 +12,8 @@ import (
...
@@ -12,6 +12,8 @@ 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/filecoin-project/go-sectorbuilder/sealing_state"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -63,7 +65,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
...
@@ -63,7 +65,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
// block until Groth parameter cache is (lazily) hydrated and sector has
// block until Groth parameter cache is (lazily) hydrated and sector has
// been sealed (or timeout)
// been sealed (or timeout)
status
,
err
:=
pollForSectorSealingStatus
(
ptr
,
sectorID
,
0
,
time
.
Minute
*
30
)
status
,
err
:=
pollForSectorSealingStatus
(
ptr
,
sectorID
,
sealing_state
.
Sealed
,
time
.
Minute
*
30
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
1
,
len
(
status
.
Pieces
),
"expected to see the one piece we added"
)
require
.
Equal
(
t
,
1
,
len
(
status
.
Pieces
),
"expected to see the one piece we added"
)
...
@@ -98,7 +100,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
...
@@ -98,7 +100,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
)
...
@@ -110,7 +112,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
...
@@ -110,7 +112,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
require
.
Equal
(
t
,
pieceBytes
,
unsealedPieceBytes
)
require
.
Equal
(
t
,
pieceBytes
,
unsealedPieceBytes
)
}
}
func
pollForSectorSealingStatus
(
ptr
unsafe
.
Pointer
,
sectorID
uint64
,
sealStatusCode
uint8
,
timeout
time
.
Duration
)
(
status
sb
.
SectorSealingStatus
,
retErr
error
)
{
func
pollForSectorSealingStatus
(
ptr
unsafe
.
Pointer
,
sectorID
uint64
,
targetState
sealing_state
.
State
,
timeout
time
.
Duration
)
(
status
sb
.
SectorSealingStatus
,
retErr
error
)
{
timeoutCh
:=
time
.
After
(
timeout
)
timeoutCh
:=
time
.
After
(
timeout
)
tick
:=
time
.
Tick
(
5
*
time
.
Second
)
tick
:=
time
.
Tick
(
5
*
time
.
Second
)
...
@@ -127,7 +129,7 @@ func pollForSectorSealingStatus(ptr unsafe.Pointer, sectorID uint64, sealStatusC
...
@@ -127,7 +129,7 @@ func pollForSectorSealingStatus(ptr unsafe.Pointer, sectorID uint64, sealStatusC
return
return
}
}
if
sealingStatus
.
S
ealStatusCode
==
sealStatusCod
e
{
if
sealingStatus
.
S
tate
==
targetStat
e
{
status
=
sealingStatus
status
=
sealingStatus
return
return
}
}
...
...
sealed_sector_health/health.go
0 → 100644
View file @
c6682d93
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
InvalidChecksum
// sector exists, but checksum is invalid
InvalidLength
// sector exists, but length is incorrect
Missing
// sector no longer exists
)
var
labels
=
[
...
]
string
{
"Unknown"
,
"Ok"
,
"InvalidChecksum"
,
"InvalidLength"
,
"Missing"
,
}
func
(
el
Health
)
String
()
string
{
return
labels
[
el
]
}
sealing_state/state.go
0 → 100644
View file @
c6682d93
package
sealing_state
// State communicates the state of the sector with respect to sealing.
type
State
int
const
(
Unknown
State
=
iota
Pending
// sector is still accepting user data
Failed
// sealing failed
Sealing
// sector is currently being sealed
Sealed
// sector has been sealed successfully
)
var
labels
=
[
...
]
string
{
"Unknown"
,
"Pending"
,
"Failed"
,
"Sealing"
,
"Sealed"
,
}
func
(
el
State
)
String
()
string
{
return
labels
[
el
]
}
transforms.go
View file @
c6682d93
...
@@ -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
Error
InvalidChecksum
,
nil
return
sealed_sector_health
.
InvalidChecksum
,
nil
case
C
.
ErrorInvalidLength
:
case
C
.
ErrorInvalidLength
:
return
Error
InvalidLength
,
nil
return
sealed_sector_health
.
InvalidLength
,
nil
case
C
.
ErrorMissing
:
case
C
.
ErrorMissing
:
return
Error
Missing
,
nil
return
sealed_sector_health
.
Missing
,
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