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
4d2aefad
Commit
4d2aefad
authored
Sep 13, 2019
by
laser
Browse files
feat(enum): extract sector sealing state to enum
parent
f39d270e
Changes
3
Show whitespace changes
Inline
Side-by-side
bindings.go
View file @
4d2aefad
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"unsafe"
"unsafe"
"github.com/filecoin-project/go-sectorbuilder/sealed_sector_health"
"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"
...
@@ -80,13 +81,13 @@ type SealedSectorMetadata struct {
...
@@ -80,13 +81,13 @@ type SealedSectorMetadata struct {
// 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.
...
@@ -408,11 +409,11 @@ func GetSectorSealingStatusByID(sectorBuilderPtr unsafe.Pointer, sectorID uint64
...
@@ -408,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
...
@@ -435,7 +436,7 @@ func GetSectorSealingStatusByID(sectorBuilderPtr unsafe.Pointer, sectorID uint64
...
@@ -435,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 @
4d2aefad
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
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/sealed_sector_health"
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -64,7 +65,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
...
@@ -64,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"
)
...
@@ -111,7 +112,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
...
@@ -111,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
)
...
@@ -128,7 +129,7 @@ func pollForSectorSealingStatus(ptr unsafe.Pointer, sectorID uint64, sealStatusC
...
@@ -128,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
}
}
...
...
sealing_state/state.go
0 → 100644
View file @
4d2aefad
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
)
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