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

Add -threads and -nonces arguments to be used with -genproof #222

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion cmd/postcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ var (
commitmentAtxId []byte
reset bool

nonces uint
threads uint

logLevel zapcore.Level

ErrKeyFileExists = errors.New("key file already exists")
Expand Down Expand Up @@ -74,6 +77,9 @@ func parseFlags() {
flag.StringVar(&commitmentAtxIdHex, "commitmentAtxId", "", "commitment atx id, in hex (required)")
numUnits := flag.Uint64("numUnits", uint64(opts.NumUnits), "number of units")

flag.UintVar(&nonces, "nonces", 16, "number of nonces for -genproof")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of nonces must be a multiple of 16 (a nonce group). How about changing this argument into "number of nonce groups" to avoid setting an invalid value? Also, 16 is unrealistic, perhaps a more typical value like 288 would be better?

Suggested change
flag.UintVar(&nonces, "nonces", 16, "number of nonces for -genproof")
flag.UintVar(&noncesGroups, "nonceGroups", 18, "number of nonce groups for -genproof. Each group consists of 16 nonces.")

And multiply it by 16 later in the code.

OR at least inform the user that it must be a multiple of 16:

Suggested change
flag.UintVar(&nonces, "nonces", 16, "number of nonces for -genproof")
flag.UintVar(&nonces, "nonces", 16, "number of nonces for -genproof. Must be a multiple of 16.")

flag.UintVar(&threads, "threads", 1, "number of threads for -genproof")

flag.IntVar(&opts.FromFileIdx, "fromFile", 0, "index of the first file to init (inclusive)")
var to int
flag.IntVar(&to, "toFile", math.MaxInt, "index of the last file to init (inclusive). Will init to the end of declared space if not provided.")
Expand Down Expand Up @@ -246,7 +252,7 @@ func main() {
if genProof {
log.Println("cli: generating proof as a sanity test")

proof, proofMetadata, err := proving.Generate(ctx, shared.ZeroChallenge, cfg, logger, proving.WithDataSource(cfg, id, commitmentAtxId, opts.DataDir))
proof, proofMetadata, err := proving.Generate(ctx, shared.ZeroChallenge, cfg, logger, proving.WithDataSource(cfg, id, commitmentAtxId, opts.DataDir), proving.WithNonces(nonces), proving.WithThreads(threads))
if err != nil {
log.Fatalln("proof generation error", err)
}
Expand Down
3 changes: 3 additions & 0 deletions proving/proving.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/hex"
"fmt"
"log"

"go.uber.org/zap"

Expand Down Expand Up @@ -34,6 +35,8 @@ func Generate(ctx context.Context, ch shared.Challenge, cfg config.Config, logge
provingOpts = append(provingOpts, postrs.WithPowCreator(options.powCreatorId))
}

log.Printf("Generating proof with: %d nonces and %d threads.\n", options.nonces, options.threads)
logger.Info("proving: start generating proof")
Comment on lines +38 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonces and threads can be added directly into the second log.

Suggested change
log.Printf("Generating proof with: %d nonces and %d threads.\n", options.nonces, options.threads)
logger.Info("proving: start generating proof")
logger.Info("proving: start generating proof", zap.Uint("nonces", options.nonces), zap.Uint("threads", options.threads))

result, err := postrs.GenerateProof(options.datadir, ch, logger, options.nonces, options.threads, cfg.K1, cfg.K2, cfg.PowDifficulty, options.powFlags, provingOpts...)
if err != nil {
return nil, nil, fmt.Errorf("generating proof: %w", err)
Expand Down