Skip to content

Commit

Permalink
Base idle (#47)
Browse files Browse the repository at this point in the history
* update SubmitIdleMetadata

* update p2p to v0.0.20
  • Loading branch information
AstaFrode committed May 15, 2023
1 parent df5fa39 commit 4ecca75
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion core/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type Chain interface {
UploadDeclaration(roothash string, dealinfo []SegmentList, user UserBrief) (string, error)

// SubmitIdleMetadata Submit idle file metadata.
SubmitIdleMetadata(idlefiles []IdleMetadata) (string, error)
SubmitIdleMetadata(teeAcc []byte, idlefiles []IdleMetadata) (string, error)

// SubmitFileReport submits a stored file report.
SubmitFileReport(roothash []FileHash) (string, []FileHash, error)
Expand Down
14 changes: 12 additions & 2 deletions core/chain/fileBank.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (c *chainClient) QueryPendingReplacements(puk []byte) (uint32, error) {
return uint32(data), nil
}

func (c *chainClient) SubmitIdleMetadata(idlefiles []IdleMetadata) (string, error) {
func (c *chainClient) SubmitIdleMetadata(teeAcc []byte, idlefiles []IdleMetadata) (string, error) {
c.lock.Lock()
defer func() {
c.lock.Unlock()
Expand All @@ -236,7 +236,17 @@ func (c *chainClient) SubmitIdleMetadata(idlefiles []IdleMetadata) (string, erro
return txhash, ERR_RPC_CONNECTION
}

call, err := types.NewCall(c.metadata, TX_FILEBANK_ADDIDLESPACE, idlefiles)
acc, err := types.NewAccountID(teeAcc)
if err != nil {
return txhash, errors.Wrap(err, "[NewAccountID]")
}

owner, err := codec.Encode(*acc)
if err != nil {
return txhash, errors.Wrap(err, "[EncodeToBytes]")
}

call, err := types.NewCall(c.metadata, TX_FILEBANK_UPLOADFILLER, owner, idlefiles)
if err != nil {
return txhash, errors.Wrap(err, "[NewCall]")
}
Expand Down
2 changes: 1 addition & 1 deletion core/chain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const (
TX_FILEBANK_DELBUCKET = FILEBANK + DOT + "delete_bucket"
TX_FILEBANK_DELFILE = FILEBANK + DOT + "delete_file"
TX_FILEBANK_UPLOADDEC = FILEBANK + DOT + "upload_declaration"
TX_FILEBANK_ADDIDLESPACE = FILEBANK + DOT + "test_add_idle_space"
TX_FILEBANK_UPLOADFILLER = FILEBANK + DOT + "upload_filler"
TX_FILEBANK_FILEREPORT = FILEBANK + DOT + "transfer_report"
TX_FILEBANK_REPLACEFILE = FILEBANK + DOT + "replace_file_report"
TX_FILEBANK_MINEREXITPREP = FILEBANK + DOT + "miner_exit_prep"
Expand Down
9 changes: 2 additions & 7 deletions core/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Client interface {
GetFile(roothash, dir string) (string, error)
UpdateRoleAddress(name string) (string, error)
UpdateIncomeAccount(income string) (string, error)
SubmitIdleFile(size uint64, blockNum, blocksize, scansize uint32, pubkey []byte, hash string) (string, error)
SubmitIdleFile(teeAcc []byte, idlefiles []IdleFileMeta) (string, error)
ReportFiles(roothash []string) (string, []string, error)
ReplaceFile(roothash []string) (string, []string, error)
IncreaseSminerStakes(token string) (string, error)
Expand Down Expand Up @@ -106,12 +106,7 @@ func NewBasicCli(rpc []string, name, phase, workspace, addr string, port int, ti
cli.Protocol.CustomDataTagProtocol = protocol.NewCustomDataTagProtocol(p2pnode)
cli.Protocol.IdleDataTagProtocol = protocol.NewIdleDataTagProtocol(p2pnode)
cli.Protocol.FileProtocol = protocol.NewFileProtocol(p2pnode)

//
os.MkdirAll(filepath.Join(workspaceActual, rule.FileDir), rule.DirMode)
os.MkdirAll(filepath.Join(workspaceActual, rule.TempDir), rule.DirMode)
os.MkdirAll(filepath.Join(workspaceActual, rule.TagDir), rule.DirMode)
os.MkdirAll(filepath.Join(workspaceActual, rule.MusDir), rule.DirMode)
cli.Protocol.PushTagProtocol = protocol.NewPushTagProtocol(p2pnode)

return cli, nil
}
Expand Down
59 changes: 37 additions & 22 deletions core/client/idlefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,49 @@
package client

import (
"fmt"

"github.com/CESSProject/sdk-go/core/chain"
"github.com/CESSProject/sdk-go/core/rule"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)

func (c *Cli) SubmitIdleFile(size uint64, blockNum, blocksize, scansize uint32, pubkey []byte, hash string) (string, error) {
acc, err := types.NewAccountID(pubkey)
if err != nil {
return "", err
}
if len(hash) != len(chain.FileHash{}) {
return "", fmt.Errorf("Invalid file hash: %s", hash)
}
var filehash chain.FileHash
type IdleFileMeta struct {
Size uint64
BlockNum uint32
BlockSize uint32
ScanSize uint32
minerAcc []byte
Hash string
}

for i := 0; i < len(hash); i++ {
filehash[i] = types.U8(hash[i])
}
var idlefiles = []chain.IdleMetadata{
{
Size: types.NewU64(size),
BlockNum: types.NewU32(blockNum),
BlockSize: types.NewU32(blocksize),
ScanSize: types.NewU32(scansize),
func (c *Cli) SubmitIdleFile(teeAcc []byte, idlefiles []IdleFileMeta) (string, error) {
var submit = make([]chain.IdleMetadata, 0)
for i := 0; i < len(idlefiles); i++ {
var filehash chain.FileHash
acc, err := types.NewAccountID(idlefiles[i].minerAcc)
if err != nil {
continue
}

if len(idlefiles[i].Hash) != len(chain.FileHash{}) {
continue
}

for j := 0; j < len(idlefiles[i].Hash); j++ {
filehash[j] = types.U8(idlefiles[i].Hash[j])
}

var ele = chain.IdleMetadata{
Size: types.NewU64(idlefiles[i].Size),
BlockNum: types.NewU32(idlefiles[i].BlockNum),
BlockSize: types.NewU32(idlefiles[i].BlockSize),
ScanSize: types.NewU32(idlefiles[i].ScanSize),
Acc: *acc,
Hash: filehash,
},
}
submit = append(submit, ele)
if len(submit) >= rule.MaxSubmitedIdleFileMeta {
break
}
}
return c.Chain.SubmitIdleMetadata(idlefiles)
return c.Chain.SubmitIdleMetadata(teeAcc, submit)
}
2 changes: 2 additions & 0 deletions core/rule/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ const BlockInterval = time.Second * time.Duration(6)

// CESSTokenSymbol is the symbol of the CESS token
const CESSTokenSymbol = "TCESS"

const MaxSubmitedIdleFileMeta = 30
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/sdk-go
go 1.19

require (
github.com/CESSProject/p2p-go v0.0.19
github.com/CESSProject/p2p-go v0.0.20
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cbergoon/merkletree v0.2.0
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 @@ -47,8 +47,8 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSu
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo=
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/p2p-go v0.0.19 h1:cwIyB0Iht1nErTBo7X0mdReHUICEvdEadsHDNVXJH0k=
github.com/CESSProject/p2p-go v0.0.19/go.mod h1:Ur2x/oD/oxteLGrEQ1hK3ZZwEZ3H8ta3cLP2zFxB96Y=
github.com/CESSProject/p2p-go v0.0.20 h1:lu8QXaDtWssOkfcu7rF33LOFgGCZ01bnNIYSEdP9w8c=
github.com/CESSProject/p2p-go v0.0.20/go.mod h1:Ur2x/oD/oxteLGrEQ1hK3ZZwEZ3H8ta3cLP2zFxB96Y=
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
Expand Down

0 comments on commit 4ecca75

Please sign in to comment.