From 54029ecd40ac724914d320086177fa50fbc4593d Mon Sep 17 00:00:00 2001
From: lovedret <lovedret@6block.com>
Date: Wed, 21 Feb 2024 17:51:07 +0800
Subject: [PATCH] Add priority to genProof func

---
 internal/postrs/proof.go | 3 ++-
 proving/proving.go       | 4 ++--
 proving/proving_test.go  | 4 ++++
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/internal/postrs/proof.go b/internal/postrs/proof.go
index 952d14037..4fa1893c4 100644
--- a/internal/postrs/proof.go
+++ b/internal/postrs/proof.go
@@ -56,7 +56,7 @@ func WithPowCreator(id []byte) PostOptionFunc {
 	}
 }
 
-func GenerateProof(dataDir string, postServer string, challenge []byte, logger *zap.Logger, nonces, threads uint, K1, K2 uint32, powDifficulty [32]byte, powFlags PowFlags, options ...PostOptionFunc) (*shared.Proof, error) {
+func GenerateProof(dataDir string, postServer string, priority uint, challenge []byte, logger *zap.Logger, nonces, threads uint, K1, K2 uint32, powDifficulty [32]byte, powFlags PowFlags, options ...PostOptionFunc) (*shared.Proof, error) {
 	opts := postOptions{}
 	for _, o := range options {
 		if err := o(&opts); err != nil {
@@ -100,6 +100,7 @@ func GenerateProof(dataDir string, postServer string, challenge []byte, logger *
 		powFlags,
 		(*C.uchar)(powCreatorId),
 		postServerPtr,
+		C.size_t(priority),
 	)
 
 	if cProof == nil {
diff --git a/proving/proving.go b/proving/proving.go
index e11d26392..9d27d1ef7 100644
--- a/proving/proving.go
+++ b/proving/proving.go
@@ -14,7 +14,7 @@ import (
 	"github.com/spacemeshos/post/shared"
 )
 
-func Generate(ctx context.Context, ch shared.Challenge, postServer string, cfg config.Config, logger *zap.Logger, opts ...OptionFunc) (*shared.Proof, *shared.ProofMetadata, error) {
+func Generate(ctx context.Context, ch shared.Challenge, postServer string, priority uint, cfg config.Config, logger *zap.Logger, opts ...OptionFunc) (*shared.Proof, *shared.ProofMetadata, error) {
 	options := option{
 		threads:  1,
 		nonces:   16,
@@ -34,7 +34,7 @@ func Generate(ctx context.Context, ch shared.Challenge, postServer string, cfg c
 		provingOpts = append(provingOpts, postrs.WithPowCreator(options.powCreatorId))
 	}
 
-	result, err := postrs.GenerateProof(options.datadir, postServer, ch, logger, options.nonces, options.threads, cfg.K1, cfg.K2, cfg.PowDifficulty, options.powFlags, provingOpts...)
+	result, err := postrs.GenerateProof(options.datadir, postServer, priority, 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)
 	}
diff --git a/proving/proving_test.go b/proving/proving_test.go
index a4dc13ec1..8692bf263 100644
--- a/proving/proving_test.go
+++ b/proving/proving_test.go
@@ -127,6 +127,7 @@ func Test_Generate_DetectInvalidParameters(t *testing.T) {
 			context.Background(),
 			ch,
 			"",
+			1,
 			cfg,
 			zaptest.NewLogger(t, zaptest.Level(zap.DebugLevel)),
 			WithDataSource(cfg, newNodeId, commitmentAtxId, opts.DataDir),
@@ -146,6 +147,7 @@ func Test_Generate_DetectInvalidParameters(t *testing.T) {
 			context.Background(),
 			ch,
 			"",
+			1,
 			cfg,
 			zaptest.NewLogger(t, zaptest.Level(zap.DebugLevel)),
 			WithDataSource(cfg, nodeId, newAtxId, opts.DataDir),
@@ -164,6 +166,7 @@ func Test_Generate_DetectInvalidParameters(t *testing.T) {
 			context.Background(),
 			ch,
 			"",
+			1,
 			newCfg,
 			zaptest.NewLogger(t, zaptest.Level(zap.DebugLevel)),
 			WithDataSource(newCfg, nodeId, commitmentAtxId, opts.DataDir),
@@ -215,6 +218,7 @@ func Test_Generate_TestNetSettings(t *testing.T) {
 		context.Background(),
 		ch,
 		"",
+		1,
 		cfg,
 		log,
 		WithDataSource(cfg, nodeId, commitmentAtxId, opts.DataDir),