Skip to content

Commit

Permalink
Base repmis (#112)
Browse files Browse the repository at this point in the history
* update inspector

* update sdk to v0.0.73
  • Loading branch information
AstaFrode committed Jun 18, 2023
1 parent e5f4f8c commit eda0d27
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CESSProject/cess-bucket
go 1.19

require (
github.com/CESSProject/cess-go-sdk v0.0.72
github.com/CESSProject/cess-go-sdk v0.0.73
github.com/CESSProject/p2p-go v0.0.33
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CESSProject/cess-go-sdk v0.0.72 h1:+KWBzqXZLPkgCCeQKyeltVZ5+g9cgbt7aTEYhzC1v78=
github.com/CESSProject/cess-go-sdk v0.0.72/go.mod h1:9paiKgRhMr/oPL7TmviK38Y9zwuUu5UOtoSo0XuZl30=
github.com/CESSProject/cess-go-sdk v0.0.73 h1:AEIebIbnpnDUoPjSDfOsxRn0CJrC/8lnKfn7L8785dg=
github.com/CESSProject/cess-go-sdk v0.0.73/go.mod h1:9paiKgRhMr/oPL7TmviK38Y9zwuUu5UOtoSo0XuZl30=
github.com/CESSProject/p2p-go v0.0.33 h1:2EXMEa1RAFHWfRTd5O6pyKQMBIbpsedIJvlYAFX/Qp0=
github.com/CESSProject/p2p-go v0.0.33/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw=
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
Expand Down
40 changes: 35 additions & 5 deletions node/restoreMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/CESSProject/cess-bucket/pkg/utils"
"github.com/CESSProject/cess-go-sdk/core/erasure"
"github.com/CESSProject/cess-go-sdk/core/pattern"
sutils "github.com/CESSProject/cess-go-sdk/core/utils"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -69,9 +70,18 @@ func (n *Node) inspector() error {
if sutils.CompareSlice(fragment.Miner[:], n.GetStakingPublickey()) {
_, err = os.Stat(filepath.Join(n.GetDirs().FileDir, roothash, string(fragment.Hash[:])))
if err != nil {
ok := n.fetchFile(v, string(fragment.Hash[:]), filepath.Join(n.GetDirs().FileDir, v, string(fragment.Hash[:])))
if !ok {
// report miss
// ok := n.fetchFile(v, string(fragment.Hash[:]), filepath.Join(n.GetDirs().FileDir, v, string(fragment.Hash[:])))
// if !ok {
// // report miss
// }
err = n.restoreFragment(roothashes, roothash, string(fragment.Hash[:]), segment)
if err != nil {
n.Restore("err", fmt.Sprintf("[restoreFragment %v] %v", roothash, err))
_, err = n.GenerateRestoralOrder(roothash, string(fragment.Hash[:]))
if err != nil {
n.Restore("err", fmt.Sprintf("[GenerateRestoralOrder %v] %v", roothash, err))
}
continue
}
}
}
Expand All @@ -96,6 +106,7 @@ func (n *Node) restoreFragment(roothashes []string, roothash, framentHash string
}
}
var canRestore int
var recoverList []string
for _, v := range segement.FragmentList {
if string(v.Hash[:]) == framentHash {
continue
Expand All @@ -113,19 +124,38 @@ func (n *Node) restoreFragment(roothashes []string, roothash, framentHash string
n.Restore("err", fmt.Sprintf("[ReadFileAction] %v", err))
continue
}
recoverList = append(recoverList, filepath.Join(n.GetDirs().FileDir, roothash, framentHash))
canRestore++
if canRestore >= int(len(segement.FragmentList)*2/3) {
break
}
}

segmentpath := filepath.Join(n.GetDirs().TmpDir, roothash, string(segement.Hash[:]))
if canRestore >= int(len(segement.FragmentList)*2/3) {

err = n.RedundancyRecovery(segmentpath, recoverList)
if err != nil {
os.Remove(segmentpath)
return err
}
_, err = erasure.ReedSolomon(segmentpath)
if err != nil {
return err
}
_, err = os.Stat(filepath.Join(n.GetDirs().FileDir, roothash, framentHash))
if err != nil {
return errors.New("recpvery failed")
}
} else {
return errors.New("recpvery failed")
}

return nil
}

func (n *Node) claimRestoreOrder() error {
return nil
}

func (n *Node) fetchFile(roothash, fragmentHash, path string) bool {
var err error
var ok bool
Expand Down
2 changes: 1 addition & 1 deletion node/taskMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (n *Node) TaskMgt() {
go n.challengeMgt(ch_challengeMgt)
go n.stagMgt(ch_stagMgt)
// go n.subscribeMgt(ch_subscribeMgt)
// go n.restoreMgt(ch_restoreMgt)
go n.restoreMgt(ch_restoreMgt)

for {
select {
Expand Down

0 comments on commit eda0d27

Please sign in to comment.