summaryrefslogtreecommitdiff
path: root/srv/pow/pow.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-08-03 15:20:32 -0600
committerBrian Picciano <mediocregopher@gmail.com>2021-08-03 15:20:32 -0600
commitec4aac24abc35fcf192c13a3fc9b2b65875c3444 (patch)
tree47fc25a28925459c2f4df9affea24559ca9b7a91 /srv/pow/pow.go
parent20b92130106007585cbdde73f6622428d9cf68c8 (diff)
got pow working on the subscribe endpoint
Diffstat (limited to 'srv/pow/pow.go')
-rw-r--r--srv/pow/pow.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/srv/pow/pow.go b/srv/pow/pow.go
index 3de1450..8075103 100644
--- a/srv/pow/pow.go
+++ b/srv/pow/pow.go
@@ -141,7 +141,7 @@ type Challenge struct {
// Errors which may be produced by a Manager.
var (
ErrInvalidSolution = errors.New("invalid solution")
- ErrExpiredSolution = errors.New("expired solution")
+ ErrExpiredSeed = errors.New("expired seed")
)
// Manager is used to both produce proof-of-work challenges and check their
@@ -150,7 +150,7 @@ type Manager interface {
NewChallenge() Challenge
// Will produce ErrInvalidSolution if the solution is invalid, or
- // ErrExpiredSolution if the solution has expired.
+ // ErrExpiredSeed if the seed has expired.
CheckSolution(seed, solution []byte) error
}
@@ -193,6 +193,7 @@ type manager struct {
// NewManager initializes and returns a Manager instance using the given
// parameters.
func NewManager(params ManagerParams) Manager {
+ params = params.withDefaults()
return &manager{
params: params,
}
@@ -252,8 +253,8 @@ func (m *manager) CheckSolution(seed, solution []byte) error {
if err != nil {
return fmt.Errorf("parsing challenge parameters from seed: %w", err)
- } else if c.ExpiresAt <= m.params.Clock.Now().Unix() {
- return ErrExpiredSolution
+ } else if now := m.params.Clock.Now().Unix(); c.ExpiresAt <= now {
+ return ErrExpiredSeed
}
ok := (SolutionChecker{}).Check(