Skip to content

Commit

Permalink
Upgrading the Proof of Generation Process
Browse files Browse the repository at this point in the history
  • Loading branch information
ted-tech committed Jun 20, 2022
1 parent 32dc8db commit 0263a0c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion configs/sys.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package configs

// type and version
const Version = "CESS-Bucket v0.4.0"
const Version = "CESS-Bucket v0.4.1"

// rpc service and method
const (
Expand Down
8 changes: 8 additions & 0 deletions internal/chain/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ type UserSpaceInfo struct {
UsedSpace types.U128
RemainingSpace types.U128
}

type ProveInfo struct {
FileId types.Bytes
MinerId types.U64
Cinfo ChallengesInfo
Mu []types.Bytes
Sigma types.Bytes
}
14 changes: 7 additions & 7 deletions internal/chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func GetAddressFromPrk(prk string, prefix []byte) (string, error) {
}

//
func PutProofToChain(signaturePrk string, id uint64, fid, sigma []byte, mu [][]byte) (int, error) {
func PutProofToChain(signaturePrk string, id uint64, data []ProveInfo) (int, error) {
var (
err error
accountInfo types.AccountInfo
Expand Down Expand Up @@ -549,13 +549,13 @@ func PutProofToChain(signaturePrk string, id uint64, fid, sigma []byte, mu [][]b
// return configs.Code_400, errors.Wrap(err, "[EncodeToBytes]")
// }

var mus []types.Bytes = make([]types.Bytes, len(mu))
for i := 0; i < len(mu); i++ {
mus[i] = make(types.Bytes, 0)
mus[i] = append(mus[i], mu[i]...)
}
// var mus []types.Bytes = make([]types.Bytes, len(mu))
// for i := 0; i < len(mu); i++ {
// mus[i] = make(types.Bytes, 0)
// mus[i] = append(mus[i], mu[i]...)
// }

c, err := types.NewCall(meta, SegmentBook_SubmitProve, types.U64(id), types.Bytes(fid), mus, types.Bytes(sigma))
c, err := types.NewCall(meta, SegmentBook_SubmitProve, types.U64(id), data)
if err != nil {
return configs.Code_500, errors.Wrap(err, "[NewCall]")
}
Expand Down
52 changes: 35 additions & 17 deletions internal/proof/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,15 @@ func task_HandlingChallenges(ch chan bool) {
continue
}

fmt.Printf("---> Prepare to generate challenges [%v]\n", len(chlng))
Out.Sugar().Infof("---> Prepare to generate challenges [%v]\n", len(chlng))
for x := 0; x < len(chlng); x++ {
fmt.Printf(" %v: %s\n", x, string(chlng[x].File_id))
Out.Sugar().Infof(" %v: %s\n", x, string(chlng[x].File_id))
}

var proveInfos = make([]chain.ProveInfo, 0)
for i := 0; i < len(chlng); i++ {
if len(proveInfos) > 50 {
break
}
if chlng[i].File_type == 1 {
//space file
filedir = filepath.Join(configs.SpaceDir, string(chlng[i].File_id))
Expand Down Expand Up @@ -450,22 +453,37 @@ func task_HandlingChallenges(ch chan bool) {
continue
}

// proof up chain
ts := time.Now().Unix()
code = 0
for code != int(configs.Code_200) && code != int(configs.Code_600) {
code, err = chain.PutProofToChain(configs.C.SignaturePrk, configs.MinerId_I, []byte(chlng[i].File_id), proveResponse.Sigma, proveResponse.MU)
if err == nil {
Out.Sugar().Infof("[%v] Proof submitted successfully", fileid)
break
}
if time.Since(time.Unix(ts, 0)).Minutes() > 10.0 {
Err.Sugar().Errorf("[%v] %v", filename, err)
break
}
time.Sleep(time.Second * time.Duration(tools.RandomInRange(5, 20)))
proveInfoTemp := chain.ProveInfo{}
proveInfoTemp.Cinfo = chlng[i]
proveInfoTemp.FileId = chlng[i].File_id

var mus []types.Bytes = make([]types.Bytes, len(proveResponse.MU))
for i := 0; i < len(proveResponse.MU); i++ {
mus[i] = make(types.Bytes, 0)
mus[i] = append(mus[i], proveResponse.MU[i]...)
}
proveInfoTemp.Mu = mus
proveInfoTemp.Sigma = types.Bytes(proveResponse.Sigma)
proveInfoTemp.MinerId = types.U64(configs.MinerId_I)
proveInfos = append(proveInfos, proveInfoTemp)
}
// proof up chain
ts := time.Now().Unix()
code = 0
for code != int(configs.Code_200) && code != int(configs.Code_600) {
code, err = chain.PutProofToChain(configs.C.SignaturePrk, configs.MinerId_I, proveInfos)
if err == nil {
Out.Sugar().Infof("Proofs submitted successfully")
break
}
if time.Since(time.Unix(ts, 0)).Minutes() > 2.0 {
Err.Sugar().Errorf("[%v] %v", filename, err)
break
}
time.Sleep(time.Second * time.Duration(tools.RandomInRange(5, 20)))
}
proveInfos = proveInfos[:0]
time.Sleep(time.Second * time.Duration(tools.RandomInRange(30, 60)))
}
}

Expand Down

0 comments on commit 0263a0c

Please sign in to comment.