Skip to content

Commit

Permalink
Merge pull request #117 from spacemeshos/bump-postrs-v0.1.4
Browse files Browse the repository at this point in the history
Bump post-rs to v0.1.4
  • Loading branch information
poszu authored Mar 27, 2023
2 parents 290894f + 72b9622 commit 31b3813
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile.Inc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ else
endif
endif

POSTRS_SETUP_REV = 0.1.3
POSTRS_SETUP_REV = 0.1.4
POSTRS_SETUP_ZIP = libpost-$(platform)-v$(POSTRS_SETUP_REV).zip
POSTRS_SETUP_URL_ZIP ?= https://github.com/spacemeshos/post-rs/releases/download/v$(POSTRS_SETUP_REV)/$(POSTRS_SETUP_ZIP)

Expand Down
4 changes: 2 additions & 2 deletions postrs/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func translateScryptParams(params config.ScryptParams) C.ScryptParams {
}
}

func GenerateProof(datadir string, challenge []byte, cfg config.Config, nonces uint, powScrypt config.ScryptParams) (*shared.Proof, error) {
func GenerateProof(datadir string, challenge []byte, cfg config.Config, nonces uint, threads uint, powScrypt config.ScryptParams) (*shared.Proof, error) {
datadirPtr := C.CString(datadir)
defer C.free(unsafe.Pointer(datadirPtr))

Expand All @@ -48,9 +48,9 @@ func GenerateProof(datadir string, challenge []byte, cfg config.Config, nonces u
cProof := C.generate_proof(
datadirPtr,
(*C.uchar)(challengePtr),
C.size_t(len(challenge)),
config,
C.size_t(nonces),
C.size_t(threads),
)

if cProof == nil {
Expand Down
3 changes: 2 additions & 1 deletion proving/proving.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
// TODO (mafa): replace Logger with zap.
func Generate(ctx context.Context, ch shared.Challenge, cfg config.Config, logger shared.Logger, opts ...OptionFunc) (*shared.Proof, *shared.ProofMetadata, error) {
options := option{
threads: 1,
nonces: 20,
powScrypt: config.DefaultPowParams(),
}
Expand All @@ -33,7 +34,7 @@ func Generate(ctx context.Context, ch shared.Challenge, cfg config.Config, logge
return nil, nil, err
}

result, err := postrs.GenerateProof(options.datadir, ch, cfg, options.nonces, options.powScrypt)
result, err := postrs.GenerateProof(options.datadir, ch, cfg, options.nonces, options.threads, options.powScrypt)
if err != nil {
return nil, nil, fmt.Errorf("generating proof: %w", err)
}
Expand Down
10 changes: 10 additions & 0 deletions proving/proving_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type option struct {
powScrypt config.ScryptParams
// How many nonces to try in parallel.
nonces uint
// How many threads to use to generate a proof.
// 0 - automatically detect
threads uint
}

func (o *option) validate() error {
Expand Down Expand Up @@ -75,3 +78,10 @@ func WithNonces(nonces uint) OptionFunc {
return nil
}
}

func WithThreads(threads uint) OptionFunc {
return func(o *option) error {
o.threads = threads
return nil
}
}
1 change: 1 addition & 0 deletions proving/proving_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func Test_Generate(t *testing.T) {
cfg,
log,
WithDataSource(cfg, nodeId, commitmentAtxId, opts.DataDir),
WithThreads(2),
)
r.NoError(err, "numUnits: %d", opts.NumUnits)
r.NotNil(proof)
Expand Down

0 comments on commit 31b3813

Please sign in to comment.