Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
More adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Jun 5, 2021
1 parent 8f96acc commit c3d85d5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 52 deletions.
9 changes: 7 additions & 2 deletions client/smesher_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

// IsSmeshing returns true iff the node is currently setup to smesh
func (c *gRPCClient) SmeshingStatus() (*apitypes.SmeshingStatusResponse, error) {
func (c *gRPCClient) IsSmeshing() (*apitypes.IsSmeshingResponse, error) {
s := c.getSmesherServiceClient()
return s.SmeshingStatus(context.Background(), &empty.Empty{})
return s.IsSmeshing(context.Background(), &empty.Empty{})
}

// StartSmeshing instructs the node to start smeshing using user's provider params
Expand Down Expand Up @@ -80,6 +80,11 @@ func (c *gRPCClient) Config() (*apitypes.ConfigResponse, error) {
return s.Config(context.Background(), &empty.Empty{})
}

func (c *gRPCClient) PostStatus() (*apitypes.PostStatusResponse, error) {
s := c.getSmesherServiceClient()
return s.PostStatus(context.Background(), &empty.Empty{})
}

func (c *gRPCClient) PostDataCreationProgressStream() (apitypes.SmesherService_PostDataCreationProgressStreamClient, error) {
s := c.getSmesherServiceClient()
return s.PostDataCreationProgressStream(context.Background(), &empty.Empty{})
Expand Down
5 changes: 3 additions & 2 deletions common/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"io/ioutil"
"os"
"path"
)
Expand Down Expand Up @@ -35,14 +36,14 @@ func ValidatePath(dataDir string) bool {
tempFilePath := path.Join(dataDir, "temp.bin")

// check write file perms
err = os.WriteFile(tempFilePath, []byte{0xff}, 0644)
err = ioutil.WriteFile(tempFilePath, []byte{0xff}, 0644)
if err != nil {
println("You don't have write permissions for this directory. Please enter a directory you have permissions to write to")
return false
}

// check read file perms
_, err = os.ReadFile(tempFilePath)
_, err = ioutil.ReadFile(tempFilePath)
if err != nil {
println("You don't have read permissions to read from this directory. Please enter a directory you have permissions to read from.")
return false
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/uuid v1.1.1
github.com/mattn/go-tty v0.0.0-20190424173100-523744f04859 // indirect
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 // indirect
github.com/spacemeshos/api/release/go v0.0.0-20210524031015-2dbd0d369b5b
github.com/spacemeshos/api/release/go v0.0.0-20210605150702-81ae866b0342
github.com/spacemeshos/ed25519 v0.0.0-20200604074309-d72da3b5f487
github.com/spacemeshos/go-spacemesh v0.1.17
github.com/spf13/viper v1.4.0
Expand All @@ -21,7 +21,7 @@ require (
go.uber.org/zap v1.16.0 // indirect
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0
golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f // indirect
golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f
google.golang.org/genproto v0.0.0-20201007142714-5c0e72c5e71e
google.golang.org/grpc v1.32.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/spacemeshos/amcl v0.0.2/go.mod h1:6/boG2CTNCJ3HBfuyU29Eg1fJxMrXUctpvBiJj1Q69o=
github.com/spacemeshos/api/release/go v0.0.0-20201103002846-7d0dfed55cc1 h1:7GoyccHS/hWGM2wryRzNi5LEymBy5FbGvfRSx3wXjd8=
github.com/spacemeshos/api/release/go v0.0.0-20201103002846-7d0dfed55cc1/go.mod h1:kNY4cuAimIxpUbMLPZSgU8jl7Zbv5ohQrLn87ybl0QI=
github.com/spacemeshos/api/release/go v0.0.0-20210524031015-2dbd0d369b5b h1:92oJOyeKHSi1a0D6ln0S2MoHlL27g8kruj2vCojmvjU=
github.com/spacemeshos/api/release/go v0.0.0-20210524031015-2dbd0d369b5b/go.mod h1:kNY4cuAimIxpUbMLPZSgU8jl7Zbv5ohQrLn87ybl0QI=
github.com/spacemeshos/api/release/go v0.0.0-20210605150702-81ae866b0342 h1:3fupkCsghRFysDc3OSdmSLXfS7xiOj7tuBZvrlYkI7U=
github.com/spacemeshos/api/release/go v0.0.0-20210605150702-81ae866b0342/go.mod h1:kNY4cuAimIxpUbMLPZSgU8jl7Zbv5ohQrLn87ybl0QI=
github.com/spacemeshos/ed25519 v0.0.0-20190530014421-e235766d15a1 h1:INBIhbR/39yXEN8WVNfiGZehiKvkML+yrJfFuIwrmbU=
github.com/spacemeshos/ed25519 v0.0.0-20190530014421-e235766d15a1/go.mod h1:lyZLUyZXvd7gp6KHwGS5ZgtS2ZvV++lBjdE4MLqmLnU=
github.com/spacemeshos/ed25519 v0.0.0-20200604074309-d72da3b5f487 h1:2WH45FeS7+jruksH6TPjv9dqDFJ0h2dmTaWx9qhn8F8=
Expand Down
4 changes: 3 additions & 1 deletion repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ type Client interface {
TransactionState(txId []byte, includeTx bool) (*apitypes.TransactionState, *apitypes.Transaction, error)

// Smesher service
SmeshingStatus() (*apitypes.SmeshingStatusResponse, error)
IsSmeshing() (*apitypes.IsSmeshingResponse, error)
StartSmeshing(request *apitypes.StartSmeshingRequest) (*status.Status, error)
StopSmeshing(deleteFiles bool) (*status.Status, error)
GetPostComputeProviders(benchmark bool) ([]*apitypes.PostComputeProvider, error)
GetSmesherId() ([]byte, error)
GetRewardsAddress() (*gosmtypes.Address, error)
SetRewardsAddress(coinbase gosmtypes.Address) (*status.Status, error)
Config() (*apitypes.ConfigResponse, error)
PostStatus() (*apitypes.PostStatusResponse, error)
PostDataCreationProgressStream() (apitypes.SmesherService_PostDataCreationProgressStreamClient, error)

// debug service
Expand Down Expand Up @@ -146,6 +147,7 @@ func (r *repl) initializeCommands() {
{"smesher-stop", "Stop smeshing", r.stopSmeshing},

// proof of space methods
{"pos-status", "Display proof of space status", r.printPostStatus},
{"pos-providers", "Display the available proof of space providers", r.printPosProviders},
{"pos-setup", "Set up (or change) smesher proof of space data", r.setupPos},
{"pos-stream-progress", "Stream data creation progress", r.printPostDataCreationProgress},
Expand Down
91 changes: 48 additions & 43 deletions repl/smesher_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,35 @@ const gib uint64 = 1073741824
const posDataFileName = "pos-data.json"

func (r *repl) printSmeshingStatus() {
res, err := r.client.SmeshingStatus()
res, err := r.client.IsSmeshing()
if err != nil {
log.Error("failed to get smeshing status: %v", err)
return
}

fmt.Printf("IsSmeshing: %v\n", res.IsSmeshing)
}

func (r *repl) printPostStatus() {
res, err := r.client.PostStatus()
if err != nil {
log.Error("failed to get proof of space status: %v", err)
return
}

switch res.Status {
case apitypes.SmeshingStatusResponse_SMESHING_STATUS_IDLE:
switch res.Status.InitStatus {
case apitypes.PostStatus_INIT_STATUS_NOT_STARTED:
fmt.Println("Proof of space data is not setup. Enter `pos-setup` to set it up.")
return
case apitypes.SmeshingStatusResponse_SMESHING_STATUS_CREATING_POST_DATA:
case apitypes.PostStatus_INIT_STATUS_IN_PROGRESS:
fmt.Println("⏱ Proof of space data creation is in progress.")
case apitypes.SmeshingStatusResponse_SMESHING_STATUS_ACTIVE:
case apitypes.PostStatus_INIT_STATUS_COMPLETE:
fmt.Println("👍 Proof of space data was created and is used for smeshing.")
case apitypes.PostStatus_INIT_STATUS_ERROR:
fmt.Printf("⚠️ Proof of space data creation error: %v", res.Status.ErrorMessage)
default:
fmt.Println("printPrefix", "Unexpected api result.")
return
}

cfg, err := r.client.Config()
Expand All @@ -46,32 +59,21 @@ func (r *repl) printSmeshingStatus() {
return
}

data, err := ioutil.ReadFile(posDataFileName)
if err != nil {
log.Error("failed to read proof of space from data file %s. %v", posDataFileName, err)
} else {
var posInitOps apitypes.PostInitOpts
err = json.Unmarshal(data, &posInitOps)
if err != nil {
log.Error("failed to parse data from %s. %v", posDataFileName, err)
return
}

unitSizeBytes := uint64(cfg.BitsPerLabel) * cfg.LabelsPerUnit / 8
unitSizeInGiB := float32(unitSizeBytes) / float32(gib)

fmt.Println("Proof of space info:")
fmt.Println("Data dir (relative to node or absolute):", posInitOps.DataDir)
fmt.Println("Date files:", posInitOps.NumFiles)
fmt.Println("Compute provider id:", posInitOps.ComputeProviderId)
fmt.Println("Throttle when computer is busy:", posInitOps.Throttle)
fmt.Println("Bits per label:", cfg.BitsPerLabel)
fmt.Println("Units:", posInitOps.NumUnits)
fmt.Println("Labels:", uint64(posInitOps.NumUnits)*cfg.LabelsPerUnit)
fmt.Println("Size (GiB):", unitSizeInGiB*float32(posInitOps.NumUnits))
fmt.Println("Size (Bytes):", unitSizeBytes*uint64(posInitOps.NumUnits))

}
unitSizeBytes := uint64(cfg.BitsPerLabel) * cfg.LabelsPerUnit / 8
unitSizeInGiB := float32(unitSizeBytes) / float32(gib)
opts := res.Status.InitOpts

println()
fmt.Println("Proof of space info:")
fmt.Println(" Data dir (relative to node or absolute):", opts.DataDir)
fmt.Println(" Date files:", opts.NumFiles)
fmt.Println(" Compute provider id:", opts.ComputeProviderId)
fmt.Println(" Throttle when computer is busy:", opts.Throttle)
fmt.Println(" Bits per label:", cfg.BitsPerLabel)
fmt.Println(" Units:", opts.NumUnits)
fmt.Println(" Labels:", uint64(opts.NumUnits)*cfg.LabelsPerUnit)
fmt.Println(" Size (GiB):", unitSizeInGiB*float32(opts.NumUnits))
fmt.Println(" Size (Bytes):", unitSizeBytes*uint64(opts.NumUnits))
}

/// setupPos start an interactive proof of space data creation process
Expand All @@ -83,7 +85,7 @@ func (r *repl) setupPos() {
}

// check if user needs to stop smeshing before changing pos data
res, err := r.client.SmeshingStatus()
res, err := r.client.IsSmeshing()
if err != nil {
log.Error("failed to get proof of space status: %v", err)
return
Expand All @@ -100,9 +102,8 @@ func (r *repl) setupPos() {
return
}

// check if idle - if not idle then pos is in progress or pos is active....
// in both cases we need to call StopSmeshing(false) before pos size can be adjusted
if res.Status != apitypes.SmeshingStatusResponse_SMESHING_STATUS_IDLE {
// If smeshing already started, StopSmeshing(false) should be called before init size could be adjusted.
if res.IsSmeshing {
stopSmeshing := yesOrNoQuestion("Your node is currently smeshing. To change your proof of space setup, you must first stop smeshing. Would you like to stop smeshing? (y/n)") == "y"
if stopSmeshing {
// stop smeshing without deleting the data
Expand Down Expand Up @@ -276,14 +277,15 @@ func (r *repl) printPostDataCreationProgress() {
return
}

numLabels := uint64(e.Status.SessionOpts.NumUnits) * cfg.LabelsPerUnit
numLabels := uint64(e.Status.InitOpts.NumUnits) * cfg.LabelsPerUnit
numLabelsWrittenPct := uint64(float64(e.Status.NumLabelsWritten) / float64(numLabels) * 100)
PosSizeBytes := uint64(cfg.BitsPerLabel) * numLabels / 8

if !initial {
fmt.Printf("Data directory: %s\n", e.Status.SessionOpts.DataDir)
fmt.Printf("Units: %d\n", e.Status.SessionOpts.NumUnits)
fmt.Printf("Files: %d\n", e.Status.SessionOpts.NumFiles)
// TODO: use the same printing of cfg/opts as in r.printPostStatus.
fmt.Printf("Data directory: %s\n", e.Status.InitOpts.DataDir)
fmt.Printf("Units: %d\n", e.Status.InitOpts.NumUnits)
fmt.Printf("Files: %d\n", e.Status.InitOpts.NumFiles)
fmt.Printf("Bits per label: %d\n", cfg.BitsPerLabel)
fmt.Printf("Labels per unit: %d\n", cfg.LabelsPerUnit)
fmt.Printf("Labels: %+v\n", numLabels)
Expand All @@ -292,21 +294,24 @@ func (r *repl) printPostDataCreationProgress() {
}

bytesWritten := uint64(cfg.BitsPerLabel) * e.Status.NumLabelsWritten / 8

fmt.Printf("Bytes written: %d (%d Labels) - %d%%\n",
bytesWritten, e.Status.NumLabelsWritten, numLabelsWrittenPct)

if e.Status.ErrorMessage != "" {
fmt.Printf("Error: %v\n", e.Status.ErrorMessage)
return
}
}
}

func (r *repl) stopSmeshing() {

res, err := r.client.SmeshingStatus()
res, err := r.client.IsSmeshing()
if err != nil {
log.Error("failed to get proof of space status: %v", err)
return
}

if res.Status == apitypes.SmeshingStatusResponse_SMESHING_STATUS_IDLE {
if !res.IsSmeshing {
fmt.Println("Can't stop smeshing because it has not started")
return
}
Expand Down

0 comments on commit c3d85d5

Please sign in to comment.