Skip to content
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

Merged
merged 12 commits into from
Aug 13, 2024
Merged

Conversation

AnomalRoil
Copy link
Member

This allows the drand-cli repo to be more independent from the drand/drand one.

@@ -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:
Copy link
Contributor

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?

client/optimizing.go Outdated Show resolved Hide resolved
@CluEleSsUK
Copy link
Contributor

Mostly lgtm. Perhaps some advisory in the readme about where to find the client and how to migrated would be good

@AnomalRoil
Copy link
Member Author

AnomalRoil commented Aug 6, 2024

Okay, looking at migration in Lotus from old v1 to new client, here are next steps:

  • Fix WithLogger to be a valid Option
  • Fix Wrap to not take a Logger and a Context and have both be Options that get passed to it or maybe have logger be in the individual clients directly
  • Discuss design around logger and clients, should clients have their own logger?
  • Fix the WithPrometheus option: make sure metrics for the clients do work

Document:

  • drand/crypto.GetSchemeByIDWithDefault -> drand/v2/crypto.GetSchemeByID
  • Result.Round -> Result.GetRound()
  • Result.Signature -> Result.GetSignature()
  • chain.Beacon -> common.Beacon
  • the HTTP client now returns a concrete type and doesn't need to be cast to a HTTP client to use SetUserAgent
  • WithVerifigedResult -> WithTrustedResult

The metrics and the WithPrometheus option currently are no-op since this isn't being handled properly anymore
@AnomalRoil
Copy link
Member Author

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,

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@CluEleSsUK CluEleSsUK left a 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

@AnomalRoil AnomalRoil merged commit 5c1e30c into master Aug 13, 2024
1 check passed
@AnomalRoil AnomalRoil deleted the refactor branch August 13, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants