Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface-test
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
interface-test
Commits
3a0969bc
Commit
3a0969bc
authored
Sep 17, 2021
by
董子豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test
parent
7bcaa30c
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
746 additions
and
430 deletions
+746
-430
proof.go
build/proof/proof.go
+11
-9
storage.go
build/storage/storage.go
+0
-2
main.go
cmd/bench/main.go
+34
-3
proofs.go
extern/filecoin-ffi/proofs.go
+14
-14
types.go
extern/filecoin-ffi/types.go
+0
-12
workflows.go
extern/filecoin-ffi/workflows.go
+3
-3
seal_api.go
seal/seal_api.go
+348
-266
test.go
seal/test.go
+181
-0
test_seal.go
seal/test_seal.go
+130
-109
type.go
seal/type.go
+25
-12
No files found.
build/proof/proof.go
View file @
3a0969bc
...
@@ -6,18 +6,20 @@ import(
...
@@ -6,18 +6,20 @@ import(
)
)
type
SectorInfo
struct
{
type
SectorInfo
struct
{
Seal
Proof
abi
.
RegisteredSealProof
// RegisteredProof used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
Seal
Type
abi
.
RegisteredSealProof
// RegisteredProof used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
SectorNumber
abi
.
SectorNumber
SectorNumber
abi
.
SectorNumber
SealedCID
cid
.
Cid
// CommR
SealedCID
cid
.
Cid
// CommR
}
}
type
Proof
[]
byte
type
SealVerifyInfo
struct
{
type
SealVerifyInfo
struct
{
Seal
Proof
abi
.
RegisteredSealProof
Seal
Type
abi
.
RegisteredSealProof
SectorID
abi
.
SectorID
SectorID
abi
.
SectorID
DealIDs
[]
abi
.
DealID
DealIDs
[]
abi
.
DealID
Randomness
abi
.
SealRandomness
Randomness
abi
.
SealRandomness
InteractiveRandomness
abi
.
InteractiveSealRandomness
InteractiveRandomness
abi
.
InteractiveSealRandomness
Proof
[]
byte
SealProof
Proof
// Safe because we get those from the miner actor
// Safe because we get those from the miner actor
SealedCID
cid
.
Cid
`checked:"true"`
// CommR
SealedCID
cid
.
Cid
`checked:"true"`
// CommR
...
@@ -36,15 +38,15 @@ type AggregateSealVerifyInfo struct {
...
@@ -36,15 +38,15 @@ type AggregateSealVerifyInfo struct {
type
AggregateSealVerifyProofAndInfos
struct
{
type
AggregateSealVerifyProofAndInfos
struct
{
Miner
abi
.
ActorID
Miner
abi
.
ActorID
Seal
Proof
abi
.
RegisteredSealProof
Seal
Type
abi
.
RegisteredSealProof
Aggregate
Proof
abi
.
RegisteredAggregationProof
Aggregate
Type
abi
.
RegisteredAggregationProof
Proof
[]
byte
AggregateProof
Proof
Infos
[]
AggregateSealVerifyInfo
Infos
[]
AggregateSealVerifyInfo
}
}
type
PoStProof
struct
{
type
PoStProof
struct
{
PoStProof
abi
.
RegisteredPoStProof
PoStProof
abi
.
RegisteredPoStProof
ProofBytes
[]
byte
ProofBytes
Proof
}
}
type
WinningPoStVerifyInfo
struct
{
type
WinningPoStVerifyInfo
struct
{
...
@@ -64,9 +66,9 @@ type WindowPoStVerifyInfo struct {
...
@@ -64,9 +66,9 @@ type WindowPoStVerifyInfo struct {
type
AggregateWindowPostInfos
struct
{
type
AggregateWindowPostInfos
struct
{
PoStType
abi
.
RegisteredPoStProof
PoStType
abi
.
RegisteredPoStProof
AggregateType
abi
.
RegisteredAggregationProof
AggregateType
abi
.
RegisteredAggregationProof
Miner
abi
.
ActorID
AggregateProof
Proof
AggregationProof
[]
byte
ChallengedSectors
[]
SectorInfo
ChallengedSectors
[]
SectorInfo
SectorCount
[]
uint
SectorCount
[]
uint
Randomnesses
[]
abi
.
PoStRandomness
Randomnesses
[]
abi
.
PoStRandomness
Prover
abi
.
ActorID
}
}
\ No newline at end of file
build/storage/storage.go
View file @
3a0969bc
...
@@ -27,8 +27,6 @@ type PreCommit1Out []byte
...
@@ -27,8 +27,6 @@ type PreCommit1Out []byte
type
Commit1Out
[]
byte
type
Commit1Out
[]
byte
type
Proof
[]
byte
type
SectorCids
struct
{
type
SectorCids
struct
{
Unsealed
cid
.
Cid
Unsealed
cid
.
Cid
Sealed
cid
.
Cid
Sealed
cid
.
Cid
...
...
cmd/bench/main.go
View file @
3a0969bc
...
@@ -25,6 +25,7 @@ func main() {
...
@@ -25,6 +25,7 @@ func main() {
Version
:
"1.0.1"
,
Version
:
"1.0.1"
,
Commands
:
[]
*
cli
.
Command
{
Commands
:
[]
*
cli
.
Command
{
test
,
test
,
testSealAndWindowPoSt
,
testSealCmd
,
testSealCmd
,
testAggregationCmd
,
testAggregationCmd
,
testSplitDataCmd
,
testSplitDataCmd
,
...
@@ -46,9 +47,39 @@ var test = &cli.Command{
...
@@ -46,9 +47,39 @@ var test = &cli.Command{
},
},
}
}
var
testSealAndWindowPoSt
=
&
cli
.
Command
{
Name
:
"test-all"
,
Usage
:
"Test Seal the sectors and generate window post"
,
Flags
:
[]
cli
.
Flag
{
&
cli
.
StringFlag
{
Name
:
"sector-size"
,
Value
:
"8MiB"
,
Usage
:
"size of the sectors in bytes"
,
},
&
cli
.
IntFlag
{
Name
:
"num-agg"
,
Value
:
4
,
Usage
:
"How many window-post proofs used to aggregate"
,
},
},
Action
:
func
(
c
*
cli
.
Context
)
error
{
sectorSizeInt
,
err
:=
units
.
RAMInBytes
(
c
.
String
(
"sector-size"
))
if
err
!=
nil
{
return
err
}
sectorSize
:=
abi
.
SectorSize
(
sectorSizeInt
)
numAggregate
:=
c
.
Int
(
"num-agg"
)
err
=
seal
.
TestSealAndWindowPoSt
(
sectorSize
,
numAggregate
)
if
err
!=
nil
{
return
err
}
return
nil
},
}
var
testSealCmd
=
&
cli
.
Command
{
var
testSealCmd
=
&
cli
.
Command
{
Name
:
"test-seal"
,
Name
:
"test-seal"
,
Usage
:
"Test
interface
"
,
Usage
:
"Test
sealing the sectors
"
,
Action
:
func
(
c
*
cli
.
Context
)
error
{
Action
:
func
(
c
*
cli
.
Context
)
error
{
// Test 8MiB sector
// Test 8MiB sector
err
:=
seal
.
TestSealAndUnseal
()
err
:=
seal
.
TestSealAndUnseal
()
...
@@ -61,7 +92,7 @@ var testSealCmd = &cli.Command{
...
@@ -61,7 +92,7 @@ var testSealCmd = &cli.Command{
var
testSplitDataCmd
=
&
cli
.
Command
{
var
testSplitDataCmd
=
&
cli
.
Command
{
Name
:
"test-split"
,
Name
:
"test-split"
,
Usage
:
"Test
interface
"
,
Usage
:
"Test
encode data into pieces
"
,
Action
:
func
(
c
*
cli
.
Context
)
error
{
Action
:
func
(
c
*
cli
.
Context
)
error
{
// Test 8MiB sector
// Test 8MiB sector
err
:=
seal
.
TestSplitDataInToPieces
()
err
:=
seal
.
TestSplitDataInToPieces
()
...
@@ -74,7 +105,7 @@ var testSplitDataCmd = &cli.Command{
...
@@ -74,7 +105,7 @@ var testSplitDataCmd = &cli.Command{
var
testAggregationCmd
=
&
cli
.
Command
{
var
testAggregationCmd
=
&
cli
.
Command
{
Name
:
"test-aggregation"
,
Name
:
"test-aggregation"
,
Usage
:
"Test
interface
"
,
Usage
:
"Test
aggregate some window-post proofs
"
,
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
&
cli
.
StringFlag
{
&
cli
.
StringFlag
{
Name
:
"sector-size"
,
Name
:
"sector-size"
,
...
...
extern/filecoin-ffi/proofs.go
View file @
3a0969bc
...
@@ -27,7 +27,7 @@ import (
...
@@ -27,7 +27,7 @@ import (
// VerifySeal returns true if the sealing operation from which its inputs were
// VerifySeal returns true if the sealing operation from which its inputs were
// derived was valid, and false if not.
// derived was valid, and false if not.
func
VerifySeal
(
info
spproof
.
SealVerifyInfo
)
(
bool
,
error
)
{
func
VerifySeal
(
info
spproof
.
SealVerifyInfo
)
(
bool
,
error
)
{
sp
,
err
:=
toFilRegisteredSealProof
(
info
.
Seal
Proof
)
sp
,
err
:=
toFilRegisteredSealProof
(
info
.
Seal
Type
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -47,7 +47,7 @@ func VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
...
@@ -47,7 +47,7 @@ func VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
return
false
,
err
return
false
,
err
}
}
resp
:=
generated
.
FilVerifySeal
(
sp
,
commR
,
commD
,
proverID
,
to32ByteArray
(
info
.
Randomness
),
to32ByteArray
(
info
.
InteractiveRandomness
),
uint64
(
info
.
SectorID
.
Number
),
info
.
Proof
,
uint
(
len
(
info
.
Proof
)))
resp
:=
generated
.
FilVerifySeal
(
sp
,
commR
,
commD
,
proverID
,
to32ByteArray
(
info
.
Randomness
),
to32ByteArray
(
info
.
InteractiveRandomness
),
uint64
(
info
.
SectorID
.
Number
),
info
.
SealProof
,
uint
(
len
(
info
.
Seal
Proof
)))
resp
.
Deref
()
resp
.
Deref
()
defer
generated
.
FilDestroyVerifySealResponse
(
resp
)
defer
generated
.
FilDestroyVerifySealResponse
(
resp
)
...
@@ -64,7 +64,7 @@ func VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (b
...
@@ -64,7 +64,7 @@ func VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (b
return
false
,
xerrors
.
New
(
"no seal verify infos"
)
return
false
,
xerrors
.
New
(
"no seal verify infos"
)
}
}
spt
:=
aggregate
.
Seal
Proof
// todo assuming this needs to be the same for all sectors, potentially makes sense to put in AggregateSealVerifyProofAndInfos
spt
:=
aggregate
.
Seal
Type
// todo assuming this needs to be the same for all sectors, potentially makes sense to put in AggregateSealVerifyProofAndInfos
inputs
:=
make
([]
generated
.
FilAggregationInputs
,
len
(
aggregate
.
Infos
))
inputs
:=
make
([]
generated
.
FilAggregationInputs
,
len
(
aggregate
.
Infos
))
for
i
,
info
:=
range
aggregate
.
Infos
{
for
i
,
info
:=
range
aggregate
.
Infos
{
...
@@ -97,12 +97,12 @@ func VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (b
...
@@ -97,12 +97,12 @@ func VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (b
return
false
,
err
return
false
,
err
}
}
rap
,
err
:=
toFilRegisteredAggregationProof
(
aggregate
.
Aggregate
Proof
)
rap
,
err
:=
toFilRegisteredAggregationProof
(
aggregate
.
Aggregate
Type
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
resp
:=
generated
.
FilVerifyAggregateSealProof
(
sp
,
rap
,
proverID
,
aggregate
.
Proof
,
uint
(
len
(
aggregate
.
Proof
)),
inputs
,
uint
(
len
(
inputs
)))
resp
:=
generated
.
FilVerifyAggregateSealProof
(
sp
,
rap
,
proverID
,
aggregate
.
AggregateProof
,
uint
(
len
(
aggregate
.
Aggregate
Proof
)),
inputs
,
uint
(
len
(
inputs
)))
resp
.
Deref
()
resp
.
Deref
()
defer
generated
.
FilDestroyVerifyAggregateSealResponse
(
resp
)
defer
generated
.
FilDestroyVerifyAggregateSealResponse
(
resp
)
...
@@ -171,7 +171,7 @@ func VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error) {
...
@@ -171,7 +171,7 @@ func VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error) {
return
false
,
err
return
false
,
err
}
}
resp
:=
generated
.
FilVerifyWindowPoSt
(
resp
:=
generated
.
FilVerifyWindowPoSt
(
to32ByteArray
(
info
.
Randomness
),
to32ByteArray
(
info
.
Randomness
),
filPublicReplicaInfos
,
filPublicReplicaInfosLen
,
filPublicReplicaInfos
,
filPublicReplicaInfosLen
,
filPoStProofs
,
filPoStProofsLen
,
filPoStProofs
,
filPoStProofsLen
,
...
@@ -205,7 +205,7 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
...
@@ -205,7 +205,7 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
return
false
,
err
return
false
,
err
}
}
proverID
,
err
:=
toProverID
(
aggregateInfo
.
Min
er
)
proverID
,
err
:=
toProverID
(
aggregateInfo
.
Prov
er
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -225,8 +225,8 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
...
@@ -225,8 +225,8 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
sp
,
sp
,
rap
,
rap
,
proverID
,
proverID
,
aggregateInfo
.
Aggregat
ion
Proof
,
aggregateInfo
.
Aggregat
e
Proof
,
uint
(
len
(
aggregateInfo
.
Aggregat
ion
Proof
)),
uint
(
len
(
aggregateInfo
.
Aggregat
e
Proof
)),
randomnesses
,
randomnesses
,
uint
(
len
(
randomnesses
)),
uint
(
len
(
randomnesses
)),
filPublicReplicaInfos
,
filPublicReplicaInfos
,
...
@@ -549,8 +549,8 @@ func SealCommitPhase2(
...
@@ -549,8 +549,8 @@ func SealCommitPhase2(
// infos [commRs, seeds],
// infos [commRs, seeds],
// }
// }
// TODO AggregateSealProofs it only needs InteractiveRandomness out of the aggregateInfo.Infos
// TODO AggregateSealProofs it only needs InteractiveRandomness out of the aggregateInfo.Infos
func
AggregateSealProofs
(
aggregateInfo
spproof
.
AggregateSealVerifyProofAndInfos
,
proofs
[]
[]
byte
)
(
out
[]
byte
,
err
error
)
{
func
AggregateSealProofs
(
aggregateInfo
spproof
.
AggregateSealVerifyProofAndInfos
,
proofs
[]
spproof
.
Proof
)
(
out
[]
byte
,
err
error
)
{
sp
,
err
:=
toFilRegisteredSealProof
(
aggregateInfo
.
Seal
Proof
)
sp
,
err
:=
toFilRegisteredSealProof
(
aggregateInfo
.
Seal
Type
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -573,7 +573,7 @@ func AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos,
...
@@ -573,7 +573,7 @@ func AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos,
}
}
}
}
rap
,
err
:=
toFilRegisteredAggregationProof
(
aggregateInfo
.
Aggregate
Proof
)
rap
,
err
:=
toFilRegisteredAggregationProof
(
aggregateInfo
.
Aggregate
Type
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -959,7 +959,7 @@ func toFilPublicReplicaInfos(src []spproof.SectorInfo, typ string) ([]generated.
...
@@ -959,7 +959,7 @@ func toFilPublicReplicaInfos(src []spproof.SectorInfo, typ string) ([]generated.
switch
typ
{
switch
typ
{
case
"window"
:
case
"window"
:
p
,
err
:=
src
[
idx
]
.
Seal
Proof
.
RegisteredWindowPoStProof
()
p
,
err
:=
src
[
idx
]
.
Seal
Type
.
RegisteredWindowPoStProof
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
...
@@ -969,7 +969,7 @@ func toFilPublicReplicaInfos(src []spproof.SectorInfo, typ string) ([]generated.
...
@@ -969,7 +969,7 @@ func toFilPublicReplicaInfos(src []spproof.SectorInfo, typ string) ([]generated.
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
case
"winning"
:
case
"winning"
:
p
,
err
:=
src
[
idx
]
.
Seal
Proof
.
RegisteredWinningPoStProof
()
p
,
err
:=
src
[
idx
]
.
Seal
Type
.
RegisteredWinningPoStProof
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
...
...
extern/filecoin-ffi/types.go
View file @
3a0969bc
...
@@ -10,18 +10,6 @@ import (
...
@@ -10,18 +10,6 @@ import (
spproof
"fil_integrate/build/proof"
spproof
"fil_integrate/build/proof"
)
)
type
AggregateWindowPostInfos
struct
{
PoStType
abi
.
RegisteredPoStProof
AggregateType
abi
.
RegisteredAggregationProof
Miner
abi
.
ActorID
AggregationProof
[]
byte
ChallengedSectors
[]
spproof
.
SectorInfo
Arr
[]
uint
Proofs
[]
spproof
.
PoStProof
Randomnesses
[]
abi
.
PoStRandomness
SectorCount
uint
}
// BLS
// BLS
// SignatureBytes is the length of a BLS signature
// SignatureBytes is the length of a BLS signature
...
...
extern/filecoin-ffi/workflows.go
View file @
3a0969bc
...
@@ -144,8 +144,8 @@ func WorkflowProofsLifecycle(t TestHelper) {
...
@@ -144,8 +144,8 @@ func WorkflowProofsLifecycle(t TestHelper) {
Number
:
sectorNum
,
Number
:
sectorNum
,
},
},
SealedCID
:
sealedCID
,
SealedCID
:
sealedCID
,
Seal
Proof
:
sealProofType
,
Seal
Type
:
sealProofType
,
Proof
:
proof
,
SealProof
:
proof
,
DealIDs
:
[]
abi
.
DealID
{},
DealIDs
:
[]
abi
.
DealID
{},
Randomness
:
ticket
,
Randomness
:
ticket
,
InteractiveRandomness
:
seed
,
InteractiveRandomness
:
seed
,
...
@@ -228,7 +228,7 @@ func WorkflowProofsLifecycle(t TestHelper) {
...
@@ -228,7 +228,7 @@ func WorkflowProofsLifecycle(t TestHelper) {
})
})
provingSet
:=
[]
spproof
.
SectorInfo
{{
provingSet
:=
[]
spproof
.
SectorInfo
{{
Seal
Proof
:
sealProofType
,
Seal
Type
:
sealProofType
,
SectorNumber
:
sectorNum
,
SectorNumber
:
sectorNum
,
SealedCID
:
sealedCID
,
SealedCID
:
sealedCID
,
}}
}}
...
...
seal/seal_api.go
View file @
3a0969bc
This diff is collapsed.
Click to expand it.
seal/test.go
0 → 100644
View file @
3a0969bc
package
seal
import
(
"context"
"os"
"fmt"
"io/ioutil"
"path/filepath"
"golang.org/x/xerrors"
"github.com/mitchellh/go-homedir"
"github.com/filecoin-project/go-state-types/abi"
spproof
"fil_integrate/build/proof"
"fil_integrate/build/storage"
"fil_integrate/seal/basicfs"
)
const
minerID
=
1000
func
TestSealAndWindowPoSt
(
sectorSize
abi
.
SectorSize
,
numAggregate
int
)
error
{
sdir
,
err
:=
homedir
.
Expand
(
"~/tmp/bench"
)
if
err
!=
nil
{
return
err
}
tsdir
,
err
:=
ioutil
.
TempDir
(
sdir
,
"bench"
)
if
err
!=
nil
{
return
err
}
// defer func() {
// if err := os.RemoveAll(tsdir); err != nil {
// log.Warn("remove all: ", err)
// }
// }()
// TODO: pretty sure this isnt even needed?
if
err
:=
os
.
MkdirAll
(
tsdir
,
0775
);
err
!=
nil
{
return
err
}
sbfs
:=
&
basicfs
.
Provider
{
Root
:
tsdir
,
}
sb
,
err
:=
New
(
sbfs
)
if
err
!=
nil
{
return
err
}
sp
:=
&
Provider
{
Root
:
tsdir
,
}
// sectorSize := abi.SectorSize(8*1024*1024)
ctx
:=
context
.
TODO
()
b
:=
[]
byte
(
string
(
"random data"
))
seed
:=
[]
byte
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
,
27
,
28
,
29
,
30
,
31
,
255
}
var
sectorsInfo
[][]
storage
.
SectorRef
var
postProofs
[]
spproof
.
PoStProof
var
randomnesses
[]
abi
.
PoStRandomness
var
sectorCount
[]
uint
var
index
=
0
for
i
:=
0
;
i
<
numAggregate
;
i
++
{
filename
:=
filepath
.
Join
(
tsdir
,
"input.dat"
)
b
,
err
=
generateRandomData
(
filename
,
b
)
if
err
!=
nil
{
return
err
}
in
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
err
}
defer
in
.
Close
()
_
,
piecesHash
,
err
:=
sp
.
EncodeDataToPieces
(
ctx
,
sectorSize
,
in
)
if
err
!=
nil
{
return
err
}
var
infos
[]
spproof
.
AggregateSealVerifyInfo
var
sealedSectors
[]
spproof
.
SectorInfo
var
sectors
[]
storage
.
SectorRef
var
proofs
[]
spproof
.
Proof
for
_
,
pieceHash
:=
range
piecesHash
{
filename
=
filepath
.
Join
(
tsdir
,
"pieces"
,
fmt
.
Sprintf
(
"%x.dat"
,
pieceHash
[
:
]))
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
err
}
sid
:=
storage
.
SectorRef
{
ID
:
abi
.
SectorID
{
Miner
:
minerID
,
Number
:
abi
.
SectorNumber
(
index
),
},
ProofType
:
spt
(
sectorSize
),
}
pieceInfo
,
err
:=
sb
.
AddPiece
(
ctx
,
sid
,
nil
,
abi
.
PaddedPieceSize
(
sectorSize
)
.
Unpadded
(),
f
)
if
err
!=
nil
{
return
err
}
var
pieces
[]
abi
.
PieceInfo
pieces
=
append
(
pieces
,
pieceInfo
)
cids
,
err
:=
sb
.
Sealed
(
ctx
,
sid
,
pieces
)
if
err
!=
nil
{
return
err
}
proof
,
err
:=
sb
.
GenerateCommitProof
(
ctx
,
sid
,
seed
,
pieces
,
cids
)
if
err
!=
nil
{
return
err
}
infos
=
append
(
infos
,
spproof
.
AggregateSealVerifyInfo
{
Number
:
sid
.
ID
.
Number
,
InteractiveRandomness
:
seed
,
SealedCID
:
cids
.
Sealed
,
UnsealedCID
:
cids
.
Unsealed
,
})
sealedSectors
=
append
(
sealedSectors
,
spproof
.
SectorInfo
{
SealType
:
sid
.
ProofType
,
SectorNumber
:
sid
.
ID
.
Number
,
SealedCID
:
cids
.
Sealed
,
})
sectors
=
append
(
sectors
,
sid
)
proofs
=
append
(
proofs
,
proof
)
index
++
}
//
aggregateInfo
:=
spproof
.
AggregateSealVerifyProofAndInfos
{
Miner
:
minerID
,
SealType
:
spt
(
sectorSize
),
AggregateType
:
DefaultAggregationType
(),
Infos
:
infos
,
}
proof
,
err
:=
sb
.
AggregateSealProofs
(
aggregateInfo
,
proofs
)
if
err
!=
nil
{
return
err
}
aggregateInfo
.
AggregateProof
=
proof
ok
,
err
:=
ProofVerifier
.
VerifyAggregateSeals
(
aggregateInfo
)
if
err
!=
nil
{
return
err
}
if
!
ok
{
return
xerrors
.
Errorf
(
"Verify Seal Aggregation proof failed"
)
}
postProof
,
_
,
err
:=
sb
.
GenerateWindowPoStProofs
(
ctx
,
minerID
,
sealedSectors
,
seed
)
if
err
!=
nil
{
return
err
}
randomnesses
=
append
(
randomnesses
,
seed
)
sectorCount
=
append
(
sectorCount
,
uint
(
len
(
sealedSectors
)))
sectorsInfo
=
append
(
sectorsInfo
,
sectors
)
postProofs
=
append
(
postProofs
,
postProof
...
)
}
proof
,
err
:=
sb
.
AggregateWindowPoStProofs
(
spproof
.
AggregateWindowPostInfos
{
AggregateType
:
DefaultAggregationType
(),
Randomnesses
:
randomnesses
,
SectorCount
:
sectorCount
,
},
postProofs
)
if
err
!=
nil
{
return
err
}
ok
,
err
:=
ProofVerifier
.
VerifyAggregateWindowPostProofs
(
sectorsInfo
,
proof
,
randomnesses
,
minerID
)
if
err
!=
nil
{
return
err
}
if
ok
{
fmt
.
Println
(
"verify success"
)
}
else
{
fmt
.
Println
(
"verify failed"
)
}
return
nil
}
\ No newline at end of file
seal/test_seal.go
View file @
3a0969bc
This diff is collapsed.
Click to expand it.
seal/type.go
View file @
3a0969bc
...
@@ -4,6 +4,7 @@ import(
...
@@ -4,6 +4,7 @@ import(
"context"
"context"
"io"
"io"
"github.com/minio/blake2b-simd"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-cid"
...
@@ -13,28 +14,40 @@ import(
...
@@ -13,28 +14,40 @@ import(
"fil_integrate/seal/basicfs"
"fil_integrate/seal/basicfs"
)
)
//interface
var
b
=
blake2b
.
Sum256
([]
byte
(
"randomness"
))
type
SectorSealer
interface
{
var
Ticket
abi
.
SealRandomness
=
abi
.
SealRandomness
(
b
[
:
])
AddPiece
(
ctx
context
.
Context
,
sector
storage
.
SectorRef
,
existingPieceSizes
[]
abi
.
UnpaddedPieceSize
,
pieceSize
abi
.
UnpaddedPieceSize
,
file
storage
.
Data
)
(
abi
.
PieceInfo
,
error
)
type
PieceProvider
interface
{
CheckPieceAndDataRoot
(
sid
storage
.
SectorRef
,
commd
cid
.
Cid
,
pieces
[]
abi
.
PieceInfo
)
(
bool
,
error
)
Sealed
(
ctx
context
.
Context
,
sid
storage
.
SectorRef
,
seed
abi
.
InteractiveSealRandomness
,
ticket
abi
.
SealRandomness
,
pieces
[]
abi
.
PieceInfo
)
(
storage
.
SectorCids
,
[]
byte
,
error
)
// Split and encode data into pieces
// Split and encode data into pieces
// Pieces structure is [ Tag | MetaData | HashData ] or [ Tag | PreHash | HashData]
// Pieces structure is [ Tag | MetaData | HashData ] or [ Tag | PreHash | HashData]
EncodeDataToPieces
(
ctx
context
.
Context
,
sectorSize
abi
.
SectorSize
,
file
storage
.
Data
)
(
storage
.
Hash
,
[]
storage
.
Hash
,
error
)
EncodeDataToPieces
(
ctx
context
.
Context
,
sectorSize
abi
.
SectorSize
,
file
storage
.
Data
)
(
storage
.
Hash
,
[]
storage
.
Hash
,
error
)
DecodePiece
(
ctx
context
.
Context
,
sectorSize
abi
.
SectorSize
,
in
io
.
Reader
,
start
storiface
.
UnpaddedByteIndex
,
end
storiface
.
UnpaddedByteIndex
)
(
storage
.
DecodedData
,
error
)
DecodePiece
(
ctx
context
.
Context
,
sectorSize
abi
.
SectorSize
,
in
io
.
Reader
,
start
storiface
.
UnpaddedByteIndex
,
end
storiface
.
UnpaddedByteIndex
)
(
storage
.
DecodedData
,
error
)
GenerateCommit2Proof
(
ctx
context
.
Context
,
sid
storage
.
SectorRef
,
seed
abi
.
InteractiveSealRandomness
,
ticket
abi
.
SealRandomness
,
pieces
[]
abi
.
PieceInfo
,
cids
storage
.
SectorCids
)
(
storage
.
Proof
,
error
)
}
//interface
type
SectorSealer
interface
{
AddPiece
(
ctx
context
.
Context
,
sector
storage
.
SectorRef
,
existingPieceSizes
[]
abi
.
UnpaddedPieceSize
,
pieceSize
abi
.
UnpaddedPieceSize
,
file
storage
.
Data
)
(
abi
.
PieceInfo
,
error
)
// run pre-commit1 and pre-commit2 phase
// generate the sealed sector and sector commitment(commd, commr)
Sealed
(
ctx
context
.
Context
,
sid
storage
.
SectorRef
,
pieces
[]
abi
.
PieceInfo
)
(
storage
.
SectorCids
,
error
)
// run commit1 and commit2 phase
// generate the zk-proof of sealing
GenerateCommitProof
(
ctx
context
.
Context
,
sid
storage
.
SectorRef
,
seed
abi
.
InteractiveSealRandomness
,
pieces
[]
abi
.
PieceInfo
,
cids
storage
.
SectorCids
)
(
spproof
.
Proof
,
error
)
AggregateSealProofs
(
aggregateInfo
spproof
.
AggregateSealVerifyProofAndInfos
,
proofs
[]
spproof
.
Proof
)
(
spproof
.
Proof
,
error
)
UnsealedRange
(
ctx
context
.
Context
,
sid
storage
.
SectorRef
,
sectorSize
abi
.
SectorSize
,
commd
cid
.
Cid
,
out
io
.
Writer
,
offset
storiface
.
UnpaddedByteIndex
,
size
abi
.
UnpaddedPieceSize
)
error
GenerateWindowPoStProofs
(
ctx
context
.
Context
,
minerID
abi
.
ActorID
,
sectorInfo
[]
spproof
.
SectorInfo
,
randomness
abi
.
PoStRandomness
)
([]
spproof
.
PoStProof
,
[]
abi
.
SectorID
,
error
)
GenerateWindowPoStProofs
(
ctx
context
.
Context
,
minerID
abi
.
ActorID
,
sectorInfo
[]
spproof
.
SectorInfo
,
randomness
abi
.
PoStRandomness
)
([]
spproof
.
PoStProof
,
[]
abi
.
SectorID
,
error
)
UnsealedRange
(
ctx
context
.
Context
,
sid
storage
.
SectorRef
,
sectorSize
abi
.
SectorSize
,
ticket
abi
.
SealRandomness
,
commd
cid
.
Cid
,
out
io
.
Writer
,
offset
storiface
.
UnpaddedByteIndex
,
size
abi
.
UnpaddedPieceSize
)
error
AggregateWindowPoStProofs
(
aggregateInfo
spproof
.
AggregateWindowPostInfos
,
proofs
[]
spproof
.
PoStProof
)
(
spproof
.
Proof
,
error
)
AggregateSealProofs
(
aggregateInfo
spproof
.
AggregateSealVerifyProofAndInfos
,
proofs
[][]
byte
)
([]
byte
,
error
)
AggregateWindowPoStProofs
(
aggregateInfo
spproof
.
AggregateWindowPostInfos
,
proofs
[]
spproof
.
PoStProof
)
([]
byte
,
error
)
}
}
type
SectorVerifier
interface
{
type
SectorVerifier
interface
{
VerifySeal
(
info
spproof
.
SealVerifyInfo
)
(
bool
,
error
)
VerifySeal
(
info
spproof
.
SealVerifyInfo
)
(
bool
,
error
)
VerifyAggregateSeals
(
aggregate
spproof
.
AggregateSealVerifyProofAndInfos
)
(
bool
,
error
)
VerifyAggregateSeals
(
aggregate
spproof
.
AggregateSealVerifyProofAndInfos
)
(
bool
,
error
)
VerifyWindowPoSt
(
info
spproof
.
WindowPoStVerifyInfo
)
(
bool
,
error
)
VerifyAggregateWindowPostProofs
(
aggregateInfo
spproof
.
AggregateWindowPostInfos
,
sealedSectors
[][]
spproof
.
SectorInfo
)
(
bool
,
error
)
VerifyWindowPoSt
(
sectors
[]
storage
.
SectorRef
,
randomness
abi
.
PoStRandomness
,
proofs
[]
spproof
.
PoStProof
,
proverID
abi
.
ActorID
)
(
bool
,
error
)
VerifyAggregateWindowPostProofs
(
sectors
[][]
storage
.
SectorRef
,
proof
spproof
.
Proof
,
randomnesses
[]
abi
.
PoStRandomness
,
proverID
abi
.
ActorID
)
(
bool
,
error
)
}
}
type
SectorProvider
interface
{
type
SectorProvider
interface
{
...
...
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