@@ -5,12 +5,14 @@ import (
5
5
"context"
6
6
"time"
7
7
8
- dchain "github.com/drand/drand/chain"
9
- dclient "github.com/drand/drand/client"
10
- hclient "github.com/drand/drand/client/http"
11
- dcrypto "github.com/drand/drand/crypto"
12
- dlog "github.com/drand/drand/log"
13
- gclient "github.com/drand/drand/lp2p/client"
8
+ dcommon "github.com/drand/drand/v2/common"
9
+ dchain "github.com/drand/drand/v2/common/chain"
10
+ dlog "github.com/drand/drand/v2/common/log"
11
+ dcrypto "github.com/drand/drand/v2/crypto"
12
+ dclient "github.com/drand/go-clients/client"
13
+ hclient "github.com/drand/go-clients/client/http"
14
+ gclient "github.com/drand/go-clients/client/lp2p"
15
+ drand "github.com/drand/go-clients/drand"
14
16
"github.com/drand/kyber"
15
17
lru "github.com/hashicorp/golang-lru/v2"
16
18
logging "github.com/ipfs/go-log/v2"
@@ -39,7 +41,7 @@ var log = logging.Logger("drand")
39
41
// The root trust for the Drand chain is configured from buildconstants.DrandConfigs
40
42
type DrandBeacon struct {
41
43
isChained bool
42
- client dclient .Client
44
+ client drand .Client
43
45
44
46
pubkey kyber.Point
45
47
@@ -92,13 +94,13 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
92
94
return nil , xerrors .Errorf ("unable to unmarshal drand chain info: %w" , err )
93
95
}
94
96
95
- var clients []dclient .Client
97
+ var clients []drand .Client
96
98
for _ , url := range config .Servers {
97
- hc , err := hclient .NewWithInfo (url , drandChain , nil )
99
+ hc , err := hclient .NewWithInfo (& logger { & log . SugaredLogger }, url , drandChain , nil )
98
100
if err != nil {
99
101
return nil , xerrors .Errorf ("could not create http drand client: %w" , err )
100
102
}
101
- hc .( DrandHTTPClient ). SetUserAgent ("drand-client-lotus/" + build .NodeBuildVersion )
103
+ hc .SetUserAgent ("drand-client-lotus/" + build .NodeBuildVersion )
102
104
clients = append (clients , hc )
103
105
}
104
106
@@ -111,18 +113,10 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
111
113
if ps != nil {
112
114
opts = append (opts , gclient .WithPubsub (ps ))
113
115
} else {
114
- log .Info ("drand beacon without pubsub" )
115
116
if len (clients ) == 0 {
116
- // This hack is necessary to convince a drand beacon to start without any clients. For
117
- // historical becaons we need them to be able to verify old entries but we don't need to fetch
118
- // new ones. With pubsub enabled, it acts as a client so drand is happy, but if we don't have
119
- // pubsub then drand will complain about old beacons withotu clients. So we make one that
120
- // it'll think is a valid client and that it won't speed test (hence the need to mark it as
121
- // as "watcher").
122
- historicalClient := & historicalBeaconClient {}
123
- opts = append (opts , dclient .WithWatcher (func (chainInfo * dchain.Info , cache dclient.Cache ) (dclient.Watcher , error ) {
124
- return historicalClient , nil
125
- }))
117
+ // This is necessary to convince a drand beacon to start without any clients. For historical
118
+ // beacons we need them to be able to verify old entries but we don't need to fetch new ones.
119
+ clients = append (clients , dclient .EmptyClientWithInfo (drandChain ))
126
120
}
127
121
}
128
122
@@ -142,7 +136,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
142
136
localCache : lc ,
143
137
}
144
138
145
- sch , err := dcrypto .GetSchemeByIDWithDefault (drandChain .Scheme )
139
+ sch , err := dcrypto .GetSchemeByID (drandChain .Scheme )
146
140
if err != nil {
147
141
return nil , err
148
142
}
@@ -176,8 +170,8 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Re
176
170
if err != nil {
177
171
br .Err = xerrors .Errorf ("drand failed Get request: %w" , err )
178
172
} else {
179
- br .Entry .Round = resp .Round ()
180
- br .Entry .Data = resp .Signature ()
173
+ br .Entry .Round = resp .GetRound ()
174
+ br .Entry .Data = resp .GetSignature ()
181
175
}
182
176
log .Debugw ("done fetching randomness" , "round" , round , "took" , build .Clock .Since (start ))
183
177
out <- br
@@ -203,7 +197,7 @@ func (db *DrandBeacon) VerifyEntry(entry types.BeaconEntry, prevEntrySig []byte)
203
197
// return no error if the value is in the cache already
204
198
return nil
205
199
}
206
- b := & dchain .Beacon {
200
+ b := & dcommon .Beacon {
207
201
PreviousSig : prevEntrySig ,
208
202
Round : entry .Round ,
209
203
Signature : entry .Data ,
@@ -253,38 +247,10 @@ func BeaconScheduleFromDrandSchedule(dcs dtypes.DrandSchedule, genesisTime uint6
253
247
for i , dc := range dcs {
254
248
bc , err := NewDrandBeacon (genesisTime , buildconstants .BlockDelaySecs , ps , dc .Config )
255
249
if err != nil {
256
- return nil , xerrors .Errorf ("%d creating drand beacon: %w" , i , err )
250
+ return nil , xerrors .Errorf ("creating drand beacon #%d : %w" , i , err )
257
251
}
258
252
shd = append (shd , beacon.BeaconPoint {Start : dc .Start , Beacon : bc })
259
253
}
260
254
261
255
return shd , nil
262
256
}
263
-
264
- var _ dclient.Client = historicalBeaconClient {}
265
-
266
- // historicalBeaconClient is a drand client that doesn't actually do anything. It's used when
267
- // we don't have a drand network to connect to but still need to provide a beacon client.
268
- // We don't expect calls through to the client to be made since we should only be verifying old
269
- // randomness, not fetching it.
270
- type historicalBeaconClient struct {}
271
-
272
- func (h historicalBeaconClient ) Get (ctx context.Context , round uint64 ) (dclient.Result , error ) {
273
- return nil , xerrors .Errorf ("no historical randomness available" )
274
- }
275
-
276
- func (h historicalBeaconClient ) Watch (ctx context.Context ) <- chan dclient.Result {
277
- return nil
278
- }
279
-
280
- func (h historicalBeaconClient ) Info (ctx context.Context ) (* dchain.Info , error ) {
281
- return nil , xerrors .Errorf ("no historical randomness available" )
282
- }
283
-
284
- func (h historicalBeaconClient ) RoundAt (time.Time ) uint64 {
285
- return 0
286
- }
287
-
288
- func (h historicalBeaconClient ) Close () error {
289
- return nil
290
- }
0 commit comments