-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating drand interfaces into drand-cli codebase #5
Conversation
@@ -3,36 +3,6 @@ Package client provides transport-agnostic logic to retrieve and verify | |||
randomness from drand, including retry, validation, caching and | |||
optimization features. | |||
|
|||
Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should link to the new lib here?
Mostly lgtm. Perhaps some advisory in the readme about where to find the client and how to migrated would be good |
Co-authored-by: PM <3749956+CluEleSsUK@users.noreply.github.com>
Okay, looking at migration in Lotus from old v1 to new client, here are next steps:
Document:
|
The metrics and the WithPrometheus option currently are no-op since this isn't being handled properly anymore
For reference, here is the changelog for Lotus to move to this new repo: diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go
index a44aa2862..348533f8d 100644
--- a/chain/beacon/drand/drand.go
+++ b/chain/beacon/drand/drand.go
@@ -5,12 +5,14 @@ import (
"context"
"time"
- dchain "github.com/drand/drand/chain"
- dclient "github.com/drand/drand/client"
- hclient "github.com/drand/drand/client/http"
- dcrypto "github.com/drand/drand/crypto"
- dlog "github.com/drand/drand/log"
- gclient "github.com/drand/drand/lp2p/client"
+ dcommon "github.com/drand/drand/v2/common"
+ dchain "github.com/drand/drand/v2/common/chain"
+ dlog "github.com/drand/drand/v2/common/log"
+ dcrypto "github.com/drand/drand/v2/crypto"
+ dclient "github.com/drand/go-clients/client"
+ hclient "github.com/drand/go-clients/client/http"
+ gclient "github.com/drand/go-clients/client/lp2p"
+ ddrand "github.com/drand/go-clients/drand"
"github.com/drand/kyber"
lru "github.com/hashicorp/golang-lru/v2"
logging "github.com/ipfs/go-log/v2"
@@ -39,7 +41,7 @@ var log = logging.Logger("drand")
// The root trust for the Drand chain is configured from buildconstants.DrandConfigs
type DrandBeacon struct {
isChained bool
- client dclient.Client
+ client ddrand.Client
pubkey kyber.Point
@@ -92,21 +94,22 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
return nil, xerrors.Errorf("unable to unmarshal drand chain info: %w", err)
}
+
+ dlog := &logger{&log.SugaredLogger}
- var clients []dclient.Client
+ var clients []ddrand.Client
for _, url := range config.Servers {
- hc, err := hclient.NewWithInfo(url, drandChain, nil)
+ hc, err := hclient.NewWithInfo(dlog, url, drandChain, nil)
if err != nil {
return nil, xerrors.Errorf("could not create http drand client: %w", err)
}
- hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion)
+ hc.SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion)
clients = append(clients, hc)
-
}
opts := []dclient.Option{
dclient.WithChainInfo(drandChain),
dclient.WithCacheSize(1024),
- dclient.WithLogger(&logger{&log.SugaredLogger}),
+ dclient.WithLogger(dlog),
}
if ps != nil {
@@ -131,7 +134,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
localCache: lc,
}
- sch, err := dcrypto.GetSchemeByIDWithDefault(drandChain.Scheme)
+ sch, err := dcrypto.GetSchemeByID(drandChain.Scheme)
if err != nil {
return nil, err
}
@@ -165,8 +168,8 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Re
if err != nil {
br.Err = xerrors.Errorf("drand failed Get request: %w", err)
} else {
- br.Entry.Round = resp.Round()
- br.Entry.Data = resp.Signature()
+ br.Entry.Round = resp.GetRound()
+ br.Entry.Data = resp.GetSignature()
}
log.Debugw("done fetching randomness", "round", round, "took", build.Clock.Since(start))
out <- br
@@ -192,7 +195,7 @@ func (db *DrandBeacon) VerifyEntry(entry types.BeaconEntry, prevEntrySig []byte)
// return no error if the value is in the cache already
return nil
}
- b := &dchain.Beacon{
+ b := &dcommon.Beacon{
PreviousSig: prevEntrySig,
Round: entry.Round,
Signature: entry.Data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some minor readme changes, otherwise lgtm
Co-authored-by: PM <3749956+CluEleSsUK@users.noreply.github.com>
This allows the drand-cli repo to be more independent from the drand/drand one.