Skip to content
Merged
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 ocp/worker/nonce/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nonce
import (
"context"
"fmt"
"sync"
"time"

"go.uber.org/zap"
Expand All @@ -13,6 +14,10 @@ import (
"github.com/code-payments/ocp-server/retry"
)

var (
globalKeyLock sync.Mutex
)

func (p *runtime) generateKey(ctx context.Context) (*vault.Record, error) {
// todo: audit whether we should be creating keys on the same server.
// Perhaps this should be done outside this box.
Expand Down Expand Up @@ -83,7 +88,8 @@ func (p *runtime) generateKeys(runtimeCtx context.Context) error {
}

func (p *runtime) reserveExistingKey(ctx context.Context) (*vault.Record, error) {
// todo: add distributed locking here.
globalKeyLock.Lock()
defer globalKeyLock.Unlock()

keys, err := p.data.GetAllKeysByState(ctx, vault.StateAvailable,
query.WithLimit(1),
Expand Down
Loading