Skip to content

Commit 62f625f

Browse files
committed
tapcfg: use CPSRNG for runtime ID
Fixes #573 by using the cryptographic pseudo number generator for generating the runtime ID. Apparently when starting two nodes at the very same time the math/rand library can generate the same ID on different processes.
1 parent e695071 commit 62f625f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tapcfg/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package tapcfg
22

33
import (
44
"context"
5+
"crypto/rand"
56
"database/sql"
7+
"encoding/binary"
68
"fmt"
7-
prand "math/rand"
89

910
"github.com/btcsuite/btclog"
1011
"github.com/lightninglabs/lndclient"
@@ -275,7 +276,13 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
275276
SyncBatchSize: defaultUniverseSyncBatchSize,
276277
})
277278

278-
runtimeID := prand.Int63() // nolint:gosec
279+
var runtimeIDBytes [8]byte
280+
_, err = rand.Read(runtimeIDBytes[:])
281+
if err != nil {
282+
return nil, fmt.Errorf("unable to generate runtime ID: %v", err)
283+
}
284+
285+
runtimeID := int64(binary.BigEndian.Uint64(runtimeIDBytes[:]))
279286
universeFederation := universe.NewFederationEnvoy(
280287
universe.FederationConfig{
281288
FederationDB: federationDB,

0 commit comments

Comments
 (0)