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
730fec46
Unverified
Commit
730fec46
authored
Jan 14, 2020
by
Łukasz Magiera
Committed by
GitHub
Jan 14, 2020
Browse files
Merge pull request #66 from filecoin-project/feat/interfaces
Interfaces
parents
9656ce47
6f68be66
Changes
4
Hide whitespace changes
Inline
Side-by-side
interface.go
0 → 100644
View file @
730fec46
package
sectorbuilder
import
(
"context"
"io"
"github.com/filecoin-project/go-address"
)
type
Interface
interface
{
RateLimit
()
func
()
AddPiece
(
uint64
,
uint64
,
io
.
Reader
,
[]
uint64
)
(
PublicPieceInfo
,
error
)
SectorSize
()
uint64
AcquireSectorId
()
(
uint64
,
error
)
Scrub
(
SortedPublicSectorInfo
)
[]
*
Fault
GenerateEPostCandidates
(
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[
CommLen
]
byte
,
faults
[]
uint64
)
([]
EPostCandidate
,
error
)
GenerateFallbackPoSt
(
SortedPublicSectorInfo
,
[
CommLen
]
byte
,
[]
uint64
)
([]
EPostCandidate
,
[]
byte
,
error
)
ComputeElectionPoSt
(
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
winners
[]
EPostCandidate
)
([]
byte
,
error
)
SealPreCommit
(
context
.
Context
,
uint64
,
SealTicket
,
[]
PublicPieceInfo
)
(
RawSealPreCommitOutput
,
error
)
SealCommit
(
context
.
Context
,
uint64
,
SealTicket
,
SealSeed
,
[]
PublicPieceInfo
,
RawSealPreCommitOutput
)
([]
byte
,
error
)
ReadPieceFromSealedSector
(
sectorID
uint64
,
offset
uint64
,
size
uint64
,
ticket
[]
byte
,
commD
[]
byte
)
(
io
.
ReadCloser
,
error
)
GetPath
(
string
,
string
)
(
string
,
error
)
WorkerStats
()
WorkerStats
AddWorker
(
context
.
Context
,
WorkerCfg
)
(
<-
chan
WorkerTask
,
error
)
TaskDone
(
context
.
Context
,
uint64
,
SealRes
)
error
}
type
Verifier
interface
{
VerifyElectionPost
(
ctx
context
.
Context
,
sectorSize
uint64
,
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
proof
[]
byte
,
candidates
[]
EPostCandidate
,
proverID
address
.
Address
)
(
bool
,
error
)
VerifyFallbackPost
(
ctx
context
.
Context
,
sectorSize
uint64
,
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
proof
[]
byte
,
candidates
[]
EPostCandidate
,
proverID
address
.
Address
,
faults
uint64
)
(
bool
,
error
)
VerifySeal
(
sectorSize
uint64
,
commR
,
commD
[]
byte
,
proverID
address
.
Address
,
ticket
[]
byte
,
seed
[]
byte
,
sectorID
uint64
,
proof
[]
byte
)
(
bool
,
error
)
}
var
_
Verifier
=
ProofVerifier
var
_
Interface
=
&
SectorBuilder
{}
sectorbuilder.go
View file @
730fec46
...
...
@@ -676,7 +676,7 @@ func (sb *SectorBuilder) pubSectorToPriv(sectorInfo SortedPublicSectorInfo, faul
SealedSectorPath
:
sealedPath
,
})
}
return
N
ewSortedPrivateSectorInfo
(
out
),
nil
return
n
ewSortedPrivateSectorInfo
(
out
),
nil
}
func
(
sb
*
SectorBuilder
)
GenerateFallbackPoSt
(
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[
CommLen
]
byte
,
faults
[]
uint64
)
([]
EPostCandidate
,
[]
byte
,
error
)
{
...
...
sectorbuilder_test.go
View file @
730fec46
...
...
@@ -72,7 +72,7 @@ func (s *seal) commit(t *testing.T, sb *sectorbuilder.SectorBuilder, done func()
t
.
Fatalf
(
"%+v"
,
err
)
}
ok
,
err
:=
sectorbuilder
.
VerifySeal
(
sectorSize
,
s
.
pco
.
CommR
[
:
],
s
.
pco
.
CommD
[
:
],
sb
.
Miner
,
s
.
ticket
.
TicketBytes
[
:
],
seed
.
TicketBytes
[
:
],
s
.
sid
,
proof
)
ok
,
err
:=
sectorbuilder
.
ProofVerifier
.
VerifySeal
(
sectorSize
,
s
.
pco
.
CommR
[
:
],
s
.
pco
.
CommD
[
:
],
sb
.
Miner
,
s
.
ticket
.
TicketBytes
[
:
],
seed
.
TicketBytes
[
:
],
s
.
sid
,
proof
)
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
}
...
...
@@ -113,7 +113,7 @@ func post(t *testing.T, sb *sectorbuilder.SectorBuilder, seals ...seal) time.Tim
t
.
Fatalf
(
"%+v"
,
err
)
}
ok
,
err
:=
sectorbuilder
.
VerifyElectionPost
(
context
.
TODO
(),
sb
.
SectorSize
(),
ssi
,
cSeed
[
:
],
postProof
,
candndates
,
sb
.
Miner
)
ok
,
err
:=
sectorbuilder
.
ProofVerifier
.
VerifyElectionPost
(
context
.
TODO
(),
sb
.
SectorSize
(),
ssi
,
cSeed
[
:
],
postProof
,
candndates
,
sb
.
Miner
)
if
err
!=
nil
{
t
.
Fatalf
(
"%+v"
,
err
)
}
...
...
simple.go
View file @
730fec46
...
...
@@ -14,9 +14,12 @@ func (sb *SectorBuilder) SectorSize() uint64 {
return
sb
.
ssize
}
type
proofVerifier
struct
{}
var
ProofVerifier
=
proofVerifier
{}
var
UserBytesForSectorSize
=
sectorbuilder
.
GetMaxUserBytesPerStagedSector
func
VerifySeal
(
sectorSize
uint64
,
commR
,
commD
[]
byte
,
proverID
address
.
Address
,
ticket
[]
byte
,
seed
[]
byte
,
sectorID
uint64
,
proof
[]
byte
)
(
bool
,
error
)
{
func
(
proofVerifier
)
VerifySeal
(
sectorSize
uint64
,
commR
,
commD
[]
byte
,
proverID
address
.
Address
,
ticket
[]
byte
,
seed
[]
byte
,
sectorID
uint64
,
proof
[]
byte
)
(
bool
,
error
)
{
var
commRa
,
commDa
,
ticketa
,
seeda
[
32
]
byte
copy
(
commRa
[
:
],
commR
)
copy
(
commDa
[
:
],
commD
)
...
...
@@ -27,20 +30,12 @@ func VerifySeal(sectorSize uint64, commR, commD []byte, proverID address.Address
return
sectorbuilder
.
VerifySeal
(
sectorSize
,
commRa
,
commDa
,
proverIDa
,
ticketa
,
seeda
,
sectorID
,
proof
)
}
func
NewSortedPrivateSectorInfo
(
sectors
[]
sectorbuilder
.
PrivateSectorInfo
)
SortedPrivateSectorInfo
{
return
sectorbuilder
.
NewSortedPrivateSectorInfo
(
sectors
...
)
}
func
NewSortedPublicSectorInfo
(
sectors
[]
sectorbuilder
.
PublicSectorInfo
)
SortedPublicSectorInfo
{
return
sectorbuilder
.
NewSortedPublicSectorInfo
(
sectors
...
)
}
func
VerifyElectionPost
(
ctx
context
.
Context
,
sectorSize
uint64
,
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
proof
[]
byte
,
candidates
[]
EPostCandidate
,
proverID
address
.
Address
)
(
bool
,
error
)
{
func
(
proofVerifier
)
VerifyElectionPost
(
ctx
context
.
Context
,
sectorSize
uint64
,
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
proof
[]
byte
,
candidates
[]
EPostCandidate
,
proverID
address
.
Address
)
(
bool
,
error
)
{
challengeCount
:=
ElectionPostChallengeCount
(
uint64
(
len
(
sectorInfo
.
Values
())),
0
)
return
verifyPost
(
ctx
,
sectorSize
,
sectorInfo
,
challengeCount
,
challengeSeed
,
proof
,
candidates
,
proverID
)
}
func
VerifyFallbackPost
(
ctx
context
.
Context
,
sectorSize
uint64
,
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
proof
[]
byte
,
candidates
[]
EPostCandidate
,
proverID
address
.
Address
,
faults
uint64
)
(
bool
,
error
)
{
func
(
proofVerifier
)
VerifyFallbackPost
(
ctx
context
.
Context
,
sectorSize
uint64
,
sectorInfo
SortedPublicSectorInfo
,
challengeSeed
[]
byte
,
proof
[]
byte
,
candidates
[]
EPostCandidate
,
proverID
address
.
Address
,
faults
uint64
)
(
bool
,
error
)
{
challengeCount
:=
fallbackPostChallengeCount
(
uint64
(
len
(
sectorInfo
.
Values
())),
faults
)
return
verifyPost
(
ctx
,
sectorSize
,
sectorInfo
,
challengeCount
,
challengeSeed
,
proof
,
candidates
,
proverID
)
}
...
...
@@ -55,6 +50,14 @@ func verifyPost(ctx context.Context, sectorSize uint64, sectorInfo SortedPublicS
return
sectorbuilder
.
VerifyPoSt
(
sectorSize
,
sectorInfo
,
challengeSeeda
,
challengeCount
,
proof
,
candidates
,
prover
)
}
func
newSortedPrivateSectorInfo
(
sectors
[]
sectorbuilder
.
PrivateSectorInfo
)
SortedPrivateSectorInfo
{
return
sectorbuilder
.
NewSortedPrivateSectorInfo
(
sectors
...
)
}
func
NewSortedPublicSectorInfo
(
sectors
[]
sectorbuilder
.
PublicSectorInfo
)
SortedPublicSectorInfo
{
return
sectorbuilder
.
NewSortedPublicSectorInfo
(
sectors
...
)
}
func
GeneratePieceCommitment
(
piece
io
.
Reader
,
pieceSize
uint64
)
(
commP
[
CommLen
]
byte
,
err
error
)
{
f
,
werr
,
err
:=
toReadableFile
(
piece
,
int64
(
pieceSize
))
if
err
!=
nil
{
...
...
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