Commit 9ced0107 authored by 董子豪's avatar 董子豪

aggretion

parent bd2eb1aa
......@@ -117,7 +117,8 @@ func main() {
Version: build.UserVersion(),
Commands: []*cli.Command{
proveCmd,
testCmd,
testSealCmd,
testAggregationCmd,
sealBenchCmd,
},
}
......@@ -128,8 +129,8 @@ func main() {
}
}
var testCmd = &cli.Command{
Name: "interface-test",
var testSealCmd = &cli.Command{
Name: "test-seal",
Usage: "Test interface",
Action: func(c *cli.Context) error {
err := seal.TestSealAndUnseal()
......@@ -140,6 +141,44 @@ var testCmd = &cli.Command{
},
}
var testAggregationCmd = &cli.Command{
Name: "test-aggregation",
Usage: "Test interface",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "sector-size",
Value: "2KiB",
Usage: "size of the sectors in bytes",
},
&cli.IntFlag{
Name: "num-sectors",
Value: 4,
Usage: "How many sectors used in single window post",
},
&cli.IntFlag{
Name: "num-agg",
Value: 4,
Usage: "How many window-post proofs used to aggregate",
},
},
Action: func(c *cli.Context) error {
log.Info("testing")
sectorSizeInt, err := units.RAMInBytes(c.String("sector-size"))
if err != nil {
return err
}
sectorSize := abi.SectorSize(sectorSizeInt)
numSectors := c.Int("num-sectors")
numAggregate := c.Int("num-agg")
err = seal.TestAggregateWindowPoSt(sectorSize, numSectors, numAggregate)
if err != nil {
return err
}
return nil
},
}
var sealBenchCmd = &cli.Command{
Name: "sealing",
Usage: "Benchmark seal and winning post and window post",
......
......@@ -1263,12 +1263,12 @@ func to32ByteCommD(unsealedCID cid.Cid) (generated.Fil32ByteArray, error) {
}
func to32ByteCommR(sealedCID cid.Cid) (generated.Fil32ByteArray, error) {
commD, err := commcid.CIDToReplicaCommitmentV1(sealedCID)
commR, err := commcid.CIDToReplicaCommitmentV1(sealedCID)
if err != nil {
return generated.Fil32ByteArray{}, errors.Wrap(err, "failed to transform sealed CID to CommR")
}
return to32ByteArray(commD), nil
return to32ByteArray(commR), nil
}
func to32ByteCommP(pieceCID cid.Cid) (generated.Fil32ByteArray, error) {
......
......@@ -19,7 +19,7 @@ type AggregateWindowPostInfos struct{
ChallengedSectors []proof5.SectorInfo
Arr []uint
Proofs []proof5.PoStProof
Randomnesses []abi.SealRandomness
Randomnesses []abi.PoStRandomness
SectorCount uint
}
......
......@@ -61,14 +61,14 @@ fn run_agg_proofs<Tree: 'static + MerkleTreeTrait>(
for k in 0..2{
let sector_id = (index * 2 + k) % 2048;
let cache_dir = root_dir.join(format!("cache-{}",sector_id));
let (comm_d, comm_r_last) = {
let (comm_c, comm_r_last) = {
let p_aux_path = cache_dir.join(CacheKey::PAux.to_string());
let p_aux_bytes = fs::read(&p_aux_path)?;
deserialize(&p_aux_bytes)
}?;
let commr: <Tree::Hasher as Hasher>::Domain =
<Tree::Hasher as Hasher>::Function::hash2(&comm_d, &comm_r_last);
<Tree::Hasher as Hasher>::Function::hash2(&comm_c, &comm_r_last);
let comm_r = commitment_from_fr(commr.into());
let sector_id = SectorId::from(sector_id);
......
......@@ -653,30 +653,19 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
api_version,
};
use rayon::prelude::*;
let commit_inputs: Vec<Vec<Fr>> = pub_replica_infos
.par_iter()
.zip(randomnesses.par_iter())
.map(|(replica, randomness)| get_window_post_inputs::<Tree>(&post_config, replica, randomness, PROVER_ID))
.try_reduce(Vec::new, |mut acc, current| {
println!("{:?}", acc);
acc.extend(current);
Ok(acc)
})?;
// let start_time = Instant::now();
// let aggregate_proof = &aggregate_window_post_proofs::<Tree>(&post_config, randomnesses.as_slice(), proofs.as_slice(), 1)?;
// let aggregate_window_post_proofs_time = start_time.elapsed().as_millis();
let start_time = Instant::now();
let aggregate_proof = &aggregate_window_post_proofs::<Tree>(&post_config, randomnesses.as_slice(), proofs.as_slice(), 1)?;
let aggregate_window_post_proofs_time = start_time.elapsed().as_millis();
// let start_time = Instant::now();
// let ok = verify_aggregate_window_post_proofs::<Tree>(&post_config, PROVER_ID, aggregate_proof.to_vec(), randomnesses.as_slice(), pub_replica_infos.as_slice())?;
// let verify_aggregate_proofs_time = start_time.elapsed().as_millis();
let start_time = Instant::now();
let ok = verify_aggregate_window_post_proofs::<Tree>(&post_config, PROVER_ID, aggregate_proof.to_vec(), randomnesses.as_slice(), pub_replica_infos.as_slice())?;
let verify_aggregate_proofs_time = start_time.elapsed().as_millis();
// if ok {
// info!("aggregate proofs is true");
// } else {
// info!("aggregate proofs is false");
// }
if ok {
info!("aggregate proofs is true");
} else {
info!("aggregate proofs is false");
}
// info!("#################################################");
// info!("generate {} window-post using {}", aggregate_count, generate_window_post_time);
......
......@@ -24,6 +24,10 @@ type Provider struct {
waitSector map[sectorFile]chan struct{}
}
func (b *Provider) GetRoot() string {
return b.Root
}
func (b *Provider) AcquireSector(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType, numbers ...int32) (storiface.SectorPaths, func(), error) {
if err := os.Mkdir(filepath.Join(b.Root, storiface.FTUnsealed.String()), 0755); err != nil && !os.IsExist(err) { // nolint
return storiface.SectorPaths{}, nil, err
......
......@@ -10,6 +10,7 @@ import (
"math/bits"
"os"
"runtime"
"path/filepath"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
......@@ -40,7 +41,42 @@ func New(sectors SectorProvider) (*Sealer, error) {
func (sb *Sealer) NewSector(ctx context.Context, sector storage.SectorRef) error {
// TODO: Allocate the sector here instead of in addpiece
return nil
}
func (sb *Sealer) GetCommRFromDir(ctx context.Context, sectorID abi.SectorID) (cid.Cid, error) {
commr := make([]byte, 32)
path := filepath.Join(sb.sectors.GetRoot(), "cache", storiface.SectorName(sectorID), "commr")
out, err := os.OpenFile(path, os.O_RDONLY, 0644)
if err != nil{
return cid.Cid{}, err
}
defer out.Close()
_, err = out.Read(commr[:])
if err != nil{
return cid.Cid{}, err
}
return commcid.ReplicaCommitmentV1ToCID(commr[:])
}
func (sb *Sealer) PutCommRIntoDir(ctx context.Context, sectorID abi.SectorID, sealedCID cid.Cid) error {
commr, err:= commcid.CIDToReplicaCommitmentV1(sealedCID)
if err != nil{
return err
}
path := filepath.Join(sb.sectors.GetRoot(), "cache", storiface.SectorName(sectorID), "commr")
out, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644)
if err != nil{
return err
}
defer out.Close()
_, err = out.Write(commr[:])
if err != nil{
return err
}
return nil
}
......
......@@ -52,6 +52,7 @@ type Prover interface {
type SectorProvider interface {
// * returns storiface.ErrSectorNotFound if a requested existing sector doesn't exist
// * returns an error when allocate is set, and existing isn't, and the sector exists
GetRoot() (string)
AcquireUnsealed(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error)
AcquireSector(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType, numbers ...int32) (storiface.SectorPaths, func(), error)
}
......
......@@ -112,7 +112,7 @@ func ParseSectorID(baseName string) (abi.SectorID, error) {
func SectorName(sid abi.SectorID, numbers ...int32) string {
out := fmt.Sprintf("s-t0%d-%d", sid.Miner, sid.Number)
for _, number := range numbers{
out = fmt.Sprintf("%s-%d", number)
out = fmt.Sprintf("%s-%d", out, number)
}
return out
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment