Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pois lib upgrade #248

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/db
/test
/cache
/work

## nohup print and log files
*.out
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/AstaFrode/go-libp2p v0.26.4-0.20231113143058-912296254d44
github.com/CESSProject/cess-go-sdk v0.5.0
github.com/CESSProject/cess_pois v0.4.22
github.com/CESSProject/cess_pois v0.5.10
github.com/CESSProject/p2p-go v0.3.2
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/CESSProject/cess-go-sdk v0.5.0 h1:N87Trs+Btt3mftpRxMt7ZeI7va4v/SaT4OiZxi00KA4=
github.com/CESSProject/cess-go-sdk v0.5.0/go.mod h1:IamF02Ng+FQvThFbQRtpEpPzmlPOXqQzgaF9YDE0YhY=
github.com/CESSProject/cess_pois v0.4.22 h1:RxQRg8A3z79mt19Jb5yd39lIjBSWKBih1KLIqN1WnIY=
github.com/CESSProject/cess_pois v0.4.22/go.mod h1:rztEZjjG+MbKzVgh5WtQcZc/7ZDkBvDNABc7Em8BKPc=
github.com/CESSProject/cess_pois v0.5.10 h1:ebgwQiJYg9NpPq+i8Ke+xmvi+zQmeNw2KAGD4II+Wyg=
github.com/CESSProject/cess_pois v0.5.10/go.mod h1:rztEZjjG+MbKzVgh5WtQcZc/7ZDkBvDNABc7Em8BKPc=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde h1:5MDRjjtg6PEhqyVjupwaapN96cOZiddOGAYwKQeaTu0=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde/go.mod h1:RUXBd3ROP98MYepEEa0Y0l/T0vQlIKqFJxI/ocdnRLM=
github.com/CESSProject/p2p-go v0.3.2 h1:l0x/TneDZfirKqFZev+9zRFFQ29RHgbc4GNX2VpLWwM=
Expand Down
29 changes: 13 additions & 16 deletions node/chall_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (n *Node) idleChallenge(
}

idleProofRecord.ChallRandom = challRandom

var rear int64
var blocksProof = make([]*pb.BlocksProof, 0)
var teeEndPoint string
n.Ichal("info", "start calc challenge...")
Expand All @@ -135,17 +133,20 @@ func (n *Node) idleChallenge(
var requestSpaceProofVerifyTotal *pb.RequestSpaceProofVerifyTotal
var spaceProofVerify *pb.ResponseSpaceProofVerify
var spaceProofVerifyTotal *pb.ResponseSpaceProofVerifyTotal

teeID := make([]byte, 32)
challengeHandle := n.Prover.NewChallengeHandle(teeID, challRandom)
var previousHash []byte
if minerChallFront != minerChallRear {
for front := (minerChallFront + 1); front <= (minerChallRear + 1); {
for {
var fileBlockProofInfoEle fileBlockProofInfo
if (front + poisSignalBlockNum) > (minerChallRear + 1) {
rear = int64(minerChallRear + 1)
} else {
rear = int64(front + poisSignalBlockNum)
left, right := challengeHandle(previousHash)
if left == right {
break
}
fileBlockProofInfoEle.FileBlockFront = int64(front)
fileBlockProofInfoEle.FileBlockRear = rear
spaceProof, err := n.Prover.ProveSpace(challRandom, int64(front), rear)
fileBlockProofInfoEle.FileBlockFront = left
fileBlockProofInfoEle.FileBlockRear = right
spaceProof, err := n.Prover.ProveSpace(challRandom, left, right)
if err != nil {
n.Ichal("err", fmt.Sprintf("[ProveSpace] %v", err))
return
Expand Down Expand Up @@ -211,6 +212,8 @@ func (n *Node) idleChallenge(
}
proofHash := h.Sum(nil)

previousHash = proofHash

fileBlockProofInfoEle.ProofHashSignOrigin = proofHash
idleproof = append(idleproof, proofHash...)
sign, err := n.Sign(proofHash)
Expand All @@ -221,20 +224,14 @@ func (n *Node) idleChallenge(

fileBlockProofInfoEle.ProofHashSign = sign
idleProofRecord.FileBlockProofInfo = append(idleProofRecord.FileBlockProofInfo, fileBlockProofInfoEle)
if rear >= (minerChallRear + 1) {
break
}
front += poisSignalBlockNum
}

h := sha256.New()
_, err = h.Write(idleproof)
if err != nil {
n.Ichal("err", fmt.Sprintf("[h.Write] %v", err))
return
}
idleProofRecord.IdleProof = h.Sum(nil)

var idleProve = make([]types.U8, len(idleProofRecord.IdleProof))
for i := 0; i < len(idleProofRecord.IdleProof); i++ {
idleProve[i] = types.U8(idleProofRecord.IdleProof[i])
Expand Down
23 changes: 20 additions & 3 deletions node/pois.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package node

import (
"fmt"
"log"
"math/big"
"runtime"
"strings"
"time"

Expand All @@ -36,7 +38,7 @@ type Pois struct {
rear int64
}

const poisSignalBlockNum = 1024
const poisSignalBlockNum = 256

var minSpace = uint64(pois.FileSize * pattern.SIZE_1MiB * acc.DEFAULT_ELEMS_NUM * 2)

Expand Down Expand Up @@ -114,7 +116,6 @@ func (n *Node) InitPois(firstflag bool, front, rear, freeSpace, count int64, key
if err != nil {
return err
}

if firstflag {
//Please initialize prover for the first time
err = n.Prover.Init(*n.Pois.RsaKey, cfg)
Expand All @@ -126,14 +127,30 @@ func (n *Node) InitPois(firstflag bool, front, rear, freeSpace, count int64, key
err = n.Prover.Recovery(*n.Pois.RsaKey, front, rear, cfg)
if err != nil {
if strings.Contains(err.Error(), "read element data") {
err = n.Prover.CheckAndRestoreSubAccFiles(front, rear)
num := 2
m, err := utils.GetSysMemAvailable()
cpuNum := runtime.NumCPU()
if err == nil {
m = m * 7 / 10 / (2 * 1024 * 1024 * 1024)
if int(m) < cpuNum {
cpuNum = int(m)
}
if cpuNum > num {
num = cpuNum
}
}
log.Println("check and restore idle data, use", num, "threads")
err = n.Prover.CheckAndRestoreIdleData(front, rear, num)
//err = n.Prover.CheckAndRestoreSubAccFiles(front, rear)
if err != nil {
return err
}
log.Println("info", "restore idle data done.")
err = n.Prover.Recovery(*n.Pois.RsaKey, front, rear, cfg)
if err != nil {
return err
}
log.Println("info", "recovery PoIS status done.")
} else {
return err
}
Expand Down
Loading