Skip to content

Commit

Permalink
Getting rid of datastore backed peerstore
Browse files Browse the repository at this point in the history
Using the in-memory one instead
  • Loading branch information
AnomalRoil committed Jul 23, 2024
1 parent dd8a929 commit 30890a0
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 164 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ issues:
linters:
- forbidigo # we use Println in our UX
- goconst # we re-use some strings in our flags
- path: client/http
text: "unexported-return"
run:
skip-dirs:
- demo
Expand Down
8 changes: 7 additions & 1 deletion client/http/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import (
"github.com/drand/drand/v2/crypto"
)

func ExampleHttpNew() {
func Example_http_New() {
chainhash, err := hex.DecodeString("52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971")
if err != nil {
// we recommend to handle errors as you wish rather than panicking
panic(err)
}

client, err := http.New(context.Background(), nil, "http://api.drand.sh", chainhash, nil)
if err != nil {
panic(err)
Expand Down Expand Up @@ -42,5 +47,6 @@ func ExampleHttpNew() {
}

fmt.Printf("got beacon: round=%d; randomness=%x\n", result.GetRound(), result.GetRandomness())

//output: got beacon: round=1234; randomness=9ead58abb451d8f521338c43ba5595610642a0c07d0e9babeaae6a98787629de
}
2 changes: 1 addition & 1 deletion client/lp2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func PubSubTopic(h string) string {
// NewWithPubsub creates a gossip randomness client. If the logger l is nil, it will default to
// a default Logger,
//
//nolint:funlen,lll // This is a long line
//nolint:funlen,lll,gocyclo // This is a long line
func NewWithPubsub(l log.Logger, ps *pubsub.PubSub, info *chain.Info, cache client2.Cache, clk clock.Clock, bufferSize int) (*Client, error) {
if info == nil {
return nil, fmt.Errorf("no chain supplied for joining")
Expand Down
15 changes: 2 additions & 13 deletions client/lp2p/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/hashicorp/consul/sdk/freeport"
bds "github.com/ipfs/go-ds-badger2"
clock "github.com/jonboulle/clockwork"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -180,24 +179,14 @@ func TestHTTPClientTestFunc(t *testing.T) {
}

func newTestClient(t *testing.T, relayMultiaddr []ma.Multiaddr, info *chain2.Info, clk clock.Clock) (*Client, error) {
dataDir := t.TempDir()
identityDir := t.TempDir()
ds, err := bds.NewDatastore(dataDir, nil)
if err != nil {
return nil, err
}

lg := log.New(nil, log.DebugLevel, true)
priv, err := lp2p.LoadOrCreatePrivKey(path.Join(identityDir, "identity.key"), lg)
if err != nil {
return nil, err
}
h, ps, err := lp2p.ConstructHost(
ds,
priv,
"/ip4/0.0.0.0/tcp/"+strconv.Itoa(freeport.GetOne(t)),
relayMultiaddr,
lg,
)
h, ps, err := lp2p.ConstructHost(priv, "/ip4/0.0.0.0/tcp/"+strconv.Itoa(freeport.GetOne(t)), relayMultiaddr, lg)
if err != nil {
return nil, err
}
Expand Down
14 changes: 2 additions & 12 deletions client/lp2p/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"fmt"
"time"

clock "github.com/jonboulle/clockwork"

gclient "github.com/drand/drand-cli/client/lp2p"
"github.com/drand/drand/v2/common"
"github.com/drand/drand/v2/common/chain"
"github.com/drand/drand/v2/common/log"
clock "github.com/jonboulle/clockwork"
)

const (
Expand All @@ -19,17 +20,6 @@ const (
relayP2PAddr2 = "/dnsaddr/api2.drand.sh"
relayP2PAddr3 = "/dnsaddr/api3.drand.sh"

jsonDefaultInfo = `{
"genesis_time": 1595431050,
"groupHash": "176f93498eac9ca337150b46d21dd58673ea4e3581185f869672e59fa4cb390a",
"hash": "8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce",
"metadata": {
"beaconID": "default"
},
"period": 30,
"public_key": "868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31",
"schemeID": "pedersen-bls-chained"
}`
// jsonQuicknetInfo, can be hardcoded since these don't change over time
jsonQuicknetInfo = `{
"genesis_time": 1692803367,
Expand Down
4 changes: 2 additions & 2 deletions client/lp2p/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ func randomnessValidator(info *chain2.Info, cache client.Cache, c *Client, clk c
if info != nil {
scheme, _ = crypto.GetSchemeByID(info.Scheme)
}
return func(ctx context.Context, p peer.ID, m *pubsub.Message) pubsub.ValidationResult {
return func(_ context.Context, p peer.ID, m *pubsub.Message) pubsub.ValidationResult {
rand := &drand.PublicRandResponse{}
err := proto.Unmarshal(m.Data, rand)
if err != nil {
c.log.Warnw("", "gossip validator", "Not validating received randomness due to proto.Unmarshal error", "err", err)
return pubsub.ValidationReject
}

c.log.Debugw("", "gossip validator", "Received new round", "round", rand.GetRound())
c.log.Debugw("", "gossip validator", "Received new round", "round", rand.GetRound(), "fromPeerID", p.String())

if info == nil {
c.log.Warnw("", "gossip validator", "Not validating received randomness due to lack of trust root.")
Expand Down
2 changes: 1 addition & 1 deletion client/optimizing.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ LOOP:
stats = append(stats, rr.stat)
res = rr.result
if rr.err != nil && !errors.Is(rr.err, common.ErrEmptyClientUnsupportedGet) {
err = fmt.Errorf("%v - %w", err, rr.err)
err = errors.Join(err, rr.err)
} else if rr.err == nil {
err = nil
}
Expand Down
16 changes: 2 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ require (
github.com/hashicorp/consul/sdk v0.16.1
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru v1.0.2
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-ds-badger2 v0.1.3
github.com/jonboulle/clockwork v0.4.0
github.com/libp2p/go-libp2p v0.35.4
github.com/libp2p/go-libp2p-pubsub v0.11.0
Expand All @@ -32,20 +30,15 @@ require (
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/drand/kyber-bls12381 v0.3.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/elastic/gosigar v0.14.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/flynn/noise v1.1.0 // indirect
Expand All @@ -56,23 +49,18 @@ require (
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20240722153945-304e4f0156b8 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/arc/v2 v2.0.7 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
Expand Down Expand Up @@ -157,8 +145,8 @@ require (
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240722135656-d784300faade // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240723171418-e6d459c13d2a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)
Loading

0 comments on commit 30890a0

Please sign in to comment.