Skip to content

Commit

Permalink
Sbxx (#287)
Browse files Browse the repository at this point in the history
* update increaseStakingCmd_Runfunc

* update Fix the problem of not using the configured tee, and reduce the number of retries when the challenge fails.

* update version
  • Loading branch information
AstaFrode authored Aug 23, 2024
1 parent ea72840 commit 2adab16
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 91 deletions.
14 changes: 10 additions & 4 deletions cmd/console/increase.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const increase_cmd_short = "increase [staking | space]"

const increaseStaking_cmd = "staking"
const increaseStaking_cmd_use = increaseStaking_cmd
const increaseStaking_cmd_short = "increase staking"
const increaseStaking_cmd_short = "increase staking, the unit is TCESS"

const increaseSpace_cmd = "space"
const increaseSpace_cmd_use = increaseSpace_cmd
const increaseSpace_cmd_short = "increase space"
const increaseSpace_cmd_short = "increase space, the unit is TiB"

var increaseCmd = &cobra.Command{
Use: increase_cmd_use,
Expand Down Expand Up @@ -71,6 +71,12 @@ func increaseStakingCmd_Runfunc(cmd *cobra.Command, args []string) {
os.Exit(1)
}

_, err := strconv.ParseUint(os.Args[3], 10, 64)
if err != nil {
out.Err(err.Error())
os.Exit(1)
}

cfg, err := buildAuthenticationConfig(cmd)
if err != nil {
out.Err(err.Error())
Expand All @@ -95,8 +101,8 @@ func increaseStakingCmd_Runfunc(cmd *cobra.Command, args []string) {
out.Err("The rpc address does not match the software version, please check the rpc address.")
os.Exit(1)
}

txhash, err := cli.IncreaseCollateral(cli.GetSignatureAccPulickey(), os.Args[3])
addStaking := os.Args[3] + chain.TokenPrecision_CESS
txhash, err := cli.IncreaseCollateral(cli.GetSignatureAccPulickey(), addStaking)
if err != nil {
if txhash == "" {
out.Err(err.Error())
Expand Down
8 changes: 4 additions & 4 deletions cmd/console/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,16 @@ func runCmd(cmd *cobra.Command, args []string) {

if len(attestationIdleCh) > 0 {
<-attestationIdleCh
go node.AttestationIdle(cli, peernode, p, runtime, minerPoisInfo, teeRecord, l, attestationIdleCh)
go node.AttestationIdle(cli, peernode, p, runtime, minerPoisInfo, teeRecord, l, cfg, attestationIdleCh)
}

if len(calcTagCh) > 0 {
<-calcTagCh
go node.CalcTag(cli, cace, l, runtime, teeRecord, wspace.GetFileDir(), calcTagCh)
go node.CalcTag(cli, cace, l, runtime, teeRecord, cfg, wspace.GetFileDir(), calcTagCh)
}

if len(idleChallCh) > 0 || len(serviceChallCh) > 0 {
go node.ChallengeMgt(cli, l, wspace, runtime, teeRecord, peernode, minerPoisInfo, rsakey, p, cace, idleChallCh, serviceChallCh)
go node.ChallengeMgt(cli, l, wspace, runtime, teeRecord, peernode, minerPoisInfo, rsakey, p, cfg, cace, idleChallCh, serviceChallCh)
time.Sleep(chain.BlockInterval)
}

Expand Down Expand Up @@ -1144,7 +1144,7 @@ func registerPoisKey(
responseMinerInitParam *pb.ResponseMinerInitParam
rsakey *node.RSAKeyPair
chainPublickey = make([]byte, chain.WorkerPublicKeyLen)
teeEndPointList = make([]string, len(priorityTeeList))
teeEndPointList = make([]string, 0)
)
copy(teeEndPointList, priorityTeeList)
for {
Expand Down
2 changes: 1 addition & 1 deletion configs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// Name is the name of the program
Name = "miner"
// version
Version = "v0.7.12"
Version = "v0.7.13"
// Description is the description of the program
Description = "Storage miner implementation in CESS networks"
// NameSpace is the cached namespace
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.21
toolchain go1.21.12

require (
github.com/CESSProject/cess-go-sdk v0.6.2-0.20240805070224-ca5be6963b49
github.com/CESSProject/cess-go-sdk v0.6.2-0.20240822075251-93843c2a4017
github.com/CESSProject/cess_pois v0.5.16
github.com/CESSProject/p2p-go v0.4.1-0.20240809013702-e989d204843e
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
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.6.2-0.20240805070224-ca5be6963b49 h1:6a58IgBudMSK0YsRvdxDsNgAPqyowfrrgKCXfQ5IP6I=
github.com/CESSProject/cess-go-sdk v0.6.2-0.20240805070224-ca5be6963b49/go.mod h1:L5IDeS2ydsdgtdybzhWk9fIdBsDkU2XrQyo5mrWHkdQ=
github.com/CESSProject/cess-go-sdk v0.6.2-0.20240822075251-93843c2a4017 h1:q488VDsCSykpJ1v+QmOxPVolkCBHvSxEP8dW3/+/MH0=
github.com/CESSProject/cess-go-sdk v0.6.2-0.20240822075251-93843c2a4017/go.mod h1:L5IDeS2ydsdgtdybzhWk9fIdBsDkU2XrQyo5mrWHkdQ=
github.com/CESSProject/cess_pois v0.5.16 h1:OYPmmuvGH9ikTyDS2BlmcNw3ZBX8udew+gNnIBTJSa8=
github.com/CESSProject/cess_pois v0.5.16/go.mod h1:rztEZjjG+MbKzVgh5WtQcZc/7ZDkBvDNABc7Em8BKPc=
github.com/CESSProject/p2p-go v0.4.1-0.20240809013702-e989d204843e h1:jaU/Pqsyu2BQL0ewamgsYmbfrTKLCqRBHh7RL0+bv6Q=
Expand Down
15 changes: 10 additions & 5 deletions node/attestation_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/CESSProject/cess-go-sdk/chain"
"github.com/CESSProject/cess-miner/configs"
"github.com/CESSProject/cess-miner/pkg/confile"
"github.com/CESSProject/cess-miner/pkg/logger"
"github.com/CESSProject/cess-miner/pkg/utils"
"github.com/CESSProject/cess_pois/acc"
Expand All @@ -26,15 +27,15 @@ import (
"google.golang.org/protobuf/proto"
)

func AttestationIdle(cli *chain.ChainClient, peernode *core.PeerNode, p *Pois, r *RunningState, m *pb.MinerPoisInfo, teeRecord *TeeRecord, l *logger.Lg, ch chan<- bool) {
func AttestationIdle(cli *chain.ChainClient, peernode *core.PeerNode, p *Pois, r *RunningState, m *pb.MinerPoisInfo, teeRecord *TeeRecord, l *logger.Lg, cfg *confile.Confile, ch chan<- bool) {
defer func() {
ch <- true
if err := recover(); err != nil {
l.Pnc(utils.RecoverError(err))
}
}()
for {
err := attestation_idle(cli, peernode, p, r, teeRecord, m, l)
err := attestation_idle(cli, peernode, p, r, teeRecord, m, l, cfg)
if err != nil {
l.Space("err", err.Error())
time.Sleep(time.Minute)
Expand All @@ -43,7 +44,7 @@ func AttestationIdle(cli *chain.ChainClient, peernode *core.PeerNode, p *Pois, r
}
}

func attestation_idle(cli *chain.ChainClient, peernode *core.PeerNode, p *Pois, r *RunningState, teeRecord *TeeRecord, m *pb.MinerPoisInfo, l logger.Logger) error {
func attestation_idle(cli *chain.ChainClient, peernode *core.PeerNode, p *Pois, r *RunningState, teeRecord *TeeRecord, m *pb.MinerPoisInfo, l *logger.Lg, cfg *confile.Confile) error {
defer func() {
if err := recover(); err != nil {
l.Pnc(utils.RecoverError(err))
Expand Down Expand Up @@ -114,8 +115,12 @@ func attestation_idle(cli *chain.ChainClient, peernode *core.PeerNode, p *Pois,
}

l.Space("info", fmt.Sprintf("front: %v rear: %v", p.Prover.GetFront(), p.Prover.GetRear()))

teeEndPoints := teeRecord.GetAllMarkerTeeEndpoint()
var teeEndPoints = cfg.ReadPriorityTeeList()
if len(teeEndPoints) > 0 {
teeEndPoints = append(teeEndPoints, cfg.ReadPriorityTeeList()...)
teeEndPoints = append(teeEndPoints, cfg.ReadPriorityTeeList()...)
}
teeEndPoints = append(teeEndPoints, teeRecord.GetAllMarkerTeeEndpoint()...)

var usedTeeEndPoint string
var usedTeeWorkAccount string
Expand Down
22 changes: 14 additions & 8 deletions node/calculate_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
sutils "github.com/CESSProject/cess-go-sdk/utils"
"github.com/CESSProject/cess-miner/configs"
"github.com/CESSProject/cess-miner/pkg/cache"
"github.com/CESSProject/cess-miner/pkg/confile"
"github.com/CESSProject/cess-miner/pkg/logger"
"github.com/CESSProject/cess-miner/pkg/utils"
"github.com/CESSProject/p2p-go/pb"
Expand All @@ -39,7 +40,7 @@ type TagfileType struct {
Index uint16 `protobuf:"bytes,6,opt,name=index,json=index,proto3" json:"index,omitempty"`
}

func CalcTag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, r *RunningState, teeRecord *TeeRecord, fileDir string, ch chan<- bool) {
func CalcTag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, r *RunningState, teeRecord *TeeRecord, cfg *confile.Confile, fileDir string, ch chan<- bool) {
r.SetCalcTagFlag(true)
defer func() {
ch <- true
Expand All @@ -58,15 +59,15 @@ func CalcTag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, r *Runni
l.Stag("info", fmt.Sprintf("[roothashs] %v", roothashs))

for _, fileDir := range roothashs {
err = calc_tag(cli, cace, l, teeRecord, fileDir)
err = calc_tag(cli, cace, l, teeRecord, cfg, fileDir)
if err != nil {
l.Stag("err", fmt.Sprintf("[%s] [calc_tag] %v", filepath.Base(fileDir), roothashs))
}
time.Sleep(time.Minute)
}
}

func calc_tag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, teeRecord *TeeRecord, file string) error {
func calc_tag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, teeRecord *TeeRecord, cfg *confile.Confile, file string) error {
var ok bool
var isReportTag bool
var err error
Expand Down Expand Up @@ -146,7 +147,7 @@ func calc_tag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, teeReco
l.Stag("err", fmt.Sprintf("[%s] The file's tag stat err: %v", fid, err))
}

isreport, err := calcTheFragmentTag(l, teeRecord, cli.GetSignatureAccPulickey(), fid, fragments[i], maxIndex, latestSig, digest)
isreport, err := calcTheFragmentTag(l, teeRecord, cfg, cli.GetSignatureAccPulickey(), fid, fragments[i], maxIndex, latestSig, digest)
if err != nil {
l.Stag("err", fmt.Sprintf("[%s] [calcFragmentTag] %v", fid, err))
return nil
Expand Down Expand Up @@ -208,15 +209,15 @@ func calc_tag(cli *chain.ChainClient, cace cache.Cache, l logger.Logger, teeReco
return nil
}

func calcTheFragmentTag(l logger.Logger, teeRecord *TeeRecord, signPublicKey []byte, fid, fragmentFile string, maxIndex uint16, lastSign []byte, digest []*pb.DigestInfo) (bool, error) {
func calcTheFragmentTag(l logger.Logger, teeRecord *TeeRecord, cfg *confile.Confile, signPublicKey []byte, fid, fragmentFile string, maxIndex uint16, lastSign []byte, digest []*pb.DigestInfo) (bool, error) {
var err error
var isReportTag bool
//var teeSign chain.TeeSig
var genTag pb.GenTagMsg
var teePubkey string
var fragmentHash = filepath.Base(fragmentFile)

genTag, teePubkey, err = requestTeeTag(l, teeRecord, signPublicKey, fid, fragmentFile, lastSign, digest)
genTag, teePubkey, err = requestTeeTag(l, teeRecord, cfg, signPublicKey, fid, fragmentFile, lastSign, digest)
if err != nil {
return false, fmt.Errorf("requestTeeTag: %v", err)
}
Expand Down Expand Up @@ -263,11 +264,16 @@ func calcTheFragmentTag(l logger.Logger, teeRecord *TeeRecord, signPublicKey []b
return isReportTag, nil
}

func requestTeeTag(l logger.Logger, teeRecord *TeeRecord, signPubkey []byte, fid, fragmentFile string, lastSign []byte, digest []*pb.DigestInfo) (pb.GenTagMsg, string, error) {
func requestTeeTag(l logger.Logger, teeRecord *TeeRecord, cfg *confile.Confile, signPubkey []byte, fid, fragmentFile string, lastSign []byte, digest []*pb.DigestInfo) (pb.GenTagMsg, string, error) {
var err error
var teePubkey string
var tagInfo pb.GenTagMsg
teeEndPoints := teeRecord.GetAllMarkerTeeEndpoint()
var teeEndPoints = cfg.ReadPriorityTeeList()
if len(teeEndPoints) > 0 {
teeEndPoints = append(teeEndPoints, cfg.ReadPriorityTeeList()...)
teeEndPoints = append(teeEndPoints, cfg.ReadPriorityTeeList()...)
}
teeEndPoints = append(teeEndPoints, teeRecord.GetAllMarkerTeeEndpoint()...)

l.Stag("info", fmt.Sprintf("[%s] To calc the fragment tag: %v", fid, filepath.Base(fragmentFile)))
for j := 0; j < len(teeEndPoints); j++ {
Expand Down
6 changes: 4 additions & 2 deletions node/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/CESSProject/cess-go-sdk/chain"
"github.com/CESSProject/cess-miner/pkg/cache"
"github.com/CESSProject/cess-miner/pkg/confile"
"github.com/CESSProject/cess-miner/pkg/logger"
"github.com/CESSProject/p2p-go/core"
"github.com/CESSProject/p2p-go/pb"
Expand All @@ -27,6 +28,7 @@ func ChallengeMgt(
m *pb.MinerPoisInfo,
rsa *RSAKeyPair,
p *Pois,
cfg *confile.Confile,
cace cache.Cache,
idleChallTaskCh chan bool,
serviceChallTaskCh chan bool,
Expand Down Expand Up @@ -118,7 +120,7 @@ func ChallengeMgt(
if len(serviceChallTaskCh) > 0 {
<-serviceChallTaskCh
go serviceChallenge(
cli, r, l, teeRecord, peernode, ws, cace, rsa,
cli, r, l, teeRecord, peernode, ws, cace, rsa, cfg,
serviceChallTaskCh,
true,
latestBlock,
Expand All @@ -140,7 +142,7 @@ func ChallengeMgt(
<-serviceChallTaskCh
r.SetServiceChallengeFlag(true)
go serviceChallenge(
cli, r, l, teeRecord, peernode, ws, cace, rsa,
cli, r, l, teeRecord, peernode, ws, cace, rsa, cfg,
serviceChallTaskCh,
false,
latestBlock,
Expand Down
83 changes: 57 additions & 26 deletions node/challenge_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type idleProofInfo struct {
ChainFront int64 `json:"chainFront"`
ChainRear int64 `json:"chainRear"`
IdleResult bool `json:"idleResult"`
SubmintProof bool `json:"submintProof"`
SubmintResult bool `json:"submintResult"`
AllocatedTeeWorkpuk chain.WorkerPublicKey `json:"allocatedTeeWorkpuk"`
IdleProof []byte `json:"idleProof"`
Acc []byte `json:"acc"`
Expand Down Expand Up @@ -104,6 +106,8 @@ func idleChallenge(
idleProofRecord.Start = challStart
idleProofRecord.ChainFront = minerChallFront
idleProofRecord.ChainRear = minerChallRear
idleProofRecord.SubmintProof = true
idleProofRecord.SubmintResult = true

var acc = make([]byte, len(chain.Accumulator{}))
for i := 0; i < len(acc); i++ {
Expand Down Expand Up @@ -253,13 +257,22 @@ func idleChallenge(
}

ws.SaveIdleProve(idleProofRecord)
l.Ichal("info", fmt.Sprintf("[start sub] %v", time.Now()))
txhash, err := n.SubmitIdleProof(idleProve)
if err != nil {
l.Ichal("err", fmt.Sprintf("[SubmitIdleProof] %v", err))
return

txhash := ""
for i := 0; i < 5; i++ {
l.Ichal("info", fmt.Sprintf("[start sub] %v", time.Now()))
txhash, err = n.SubmitIdleProof(idleProve)
l.Ichal("info", fmt.Sprintf("SubmitIdleProof: %s", txhash))
if err != nil {
l.Ichal("err", fmt.Sprintf("[SubmitIdleProof] %v", err))
time.Sleep(time.Minute)
continue
}
break
}
l.Ichal("info", fmt.Sprintf("SubmitIdleProof: %s", txhash))
idleProofRecord.SubmintProof = false
ws.SaveIdleProve(idleProofRecord)

//

time.Sleep(chain.BlockInterval * 2)
Expand Down Expand Up @@ -394,28 +407,39 @@ func idleChallenge(
for j := 0; j < len(teeSig); j++ {
teeSignBytes[j] = byte(teeSig[j])
}
txHash, err := n.SubmitVerifyIdleResult(
idleProve,
types.U64(idleProofRecord.ChainFront),
types.U64(idleProofRecord.ChainRear),
minerAccumulator,
types.Bool(spaceProofVerifyTotal.IdleResult),
teeSignBytes,
idleProofRecord.AllocatedTeeWorkpuk,
)
if err != nil {
l.Ichal("err", fmt.Sprintf("[SubmitIdleProofResult] hash: %s, err: %v", txHash, err))
return
for i := 0; i < 5; i++ {
txHash, err := n.SubmitVerifyIdleResult(
idleProve,
types.U64(idleProofRecord.ChainFront),
types.U64(idleProofRecord.ChainRear),
minerAccumulator,
types.Bool(spaceProofVerifyTotal.IdleResult),
teeSignBytes,
idleProofRecord.AllocatedTeeWorkpuk,
)
if err != nil {
l.Ichal("err", fmt.Sprintf("[SubmitIdleProofResult] hash: %s, err: %v", txHash, err))
time.Sleep(time.Minute)
continue
}
l.Ichal("info", fmt.Sprintf("submit idle proof result suc: %s", txHash))
break
}

l.Ichal("info", fmt.Sprintf("submit idle proof result suc: %s", txHash))
idleProofRecord.SubmintResult = false
ws.SaveIdleProve(idleProofRecord)
} else {
txhash, err := n.SubmitIdleProof([]types.U8{})
if err != nil {
l.Ichal("err", fmt.Sprintf("[SubmitIdleProof] %v", err))
return
for i := 0; i < 5; i++ {
txhash, err := n.SubmitIdleProof([]types.U8{})
if err != nil {
l.Ichal("err", fmt.Sprintf("[SubmitIdleProof] %v", err))
time.Sleep(time.Minute)
continue
}
l.Ichal("info", fmt.Sprintf("SubmitIdleProof: %s", txhash))
break
}
l.Ichal("info", fmt.Sprintf("SubmitIdleProof: %s", txhash))
idleProofRecord.SubmintResult = false
ws.SaveIdleProve(idleProofRecord)
}
}

Expand Down Expand Up @@ -454,7 +478,14 @@ func checkIdleProofRecord(

l.Ichal("info", fmt.Sprintf("local idle proof file challenge: %v", idleProofRecord.Start))
if !idleProofSubmited {
return errors.New("Idle proof not submited")
if idleProofRecord.SubmintProof {
return errors.New("Idle proof not submited")
}
return nil
}

if !idleProofRecord.SubmintResult {
return nil
}

if chain.IsWorkerPublicKeyAllZero(teePubkey) {
Expand Down
Loading

0 comments on commit 2adab16

Please sign in to comment.