Skip to content

Commit

Permalink
Moving around protobuf (#1292)
Browse files Browse the repository at this point in the history
* Moving around protobuf
* code review comment and removing unnecessary duplicate check
  • Loading branch information
AnomalRoil authored and CluEleSsUK committed Jan 9, 2024
1 parent 56e07bd commit 81e40d5
Show file tree
Hide file tree
Showing 73 changed files with 1,865 additions and 1,954 deletions.
10 changes: 5 additions & 5 deletions common/chain/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

json "github.com/nikkolasg/hexjson"

"github.com/drand/drand/crypto"
"github.com/drand/drand/protobuf/common"
"github.com/drand/drand/protobuf/drand"

"github.com/drand/drand/crypto"
)

// InfoFromProto returns a Info from the protocol description
Expand All @@ -34,13 +34,13 @@ func InfoFromProto(p *drand.ChainInfoPacket) (*Info, error) {
}

// ToProto returns the protobuf description of the chain info
func (c *Info) ToProto(metadata *common.Metadata) *drand.ChainInfoPacket {
func (c *Info) ToProto(metadata *drand.Metadata) *drand.ChainInfoPacket {
buff, _ := c.PublicKey.MarshalBinary()

if metadata != nil {
metadata.BeaconID = c.ID
} else {
metadata = &common.Metadata{BeaconID: c.ID}
metadata = &drand.Metadata{BeaconID: c.ID}
}

return &drand.ChainInfoPacket{
Expand Down Expand Up @@ -70,7 +70,7 @@ func InfoFromJSON(buff io.Reader) (*Info, error) {
}

// ToJSON provides a json serialization of an info packet
func (c *Info) ToJSON(w io.Writer, metadata *common.Metadata) error {
func (c *Info) ToJSON(w io.Writer, metadata *drand.Metadata) error {
info := c.ToProto(metadata)
return json.NewEncoder(w).Encode(info)
}
5 changes: 3 additions & 2 deletions common/chain/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (

"github.com/stretchr/testify/require"

"github.com/drand/drand/protobuf/drand"

"github.com/drand/drand/common/key"
"github.com/drand/drand/crypto"
"github.com/drand/drand/internal/test"
"github.com/drand/drand/protobuf/common"
)

//nolint:funlen
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestChainInfo(t *testing.T) {
require.ErrorContains(t, err, "point is not on")

// testing ToProto
packet := c1.ToProto(&common.Metadata{
packet := c1.ToProto(&drand.Metadata{
BeaconID: "differentfrom" + beaconID,
})
require.Equal(t, beaconID, packet.Metadata.BeaconID)
Expand Down
3 changes: 1 addition & 2 deletions common/key/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

common2 "github.com/drand/drand/common"
"github.com/drand/drand/crypto"
"github.com/drand/drand/protobuf/common"
proto "github.com/drand/drand/protobuf/drand"
"github.com/drand/kyber"
"github.com/drand/kyber/share/dkg"
Expand Down Expand Up @@ -459,7 +458,7 @@ func (g *Group) ToProto(version common2.Version) *proto.GroupPacket {
out.GenesisSeed = g.GetGenesisSeed()
out.SchemeID = g.Scheme.Name

out.Metadata = common.NewMetadata(version.ToProto())
out.Metadata = proto.NewMetadata(version.ToProto())
out.Metadata.BeaconID = common2.GetCanonicalBeaconID(g.ID)

if g.PublicKey != nil {
Expand Down
3 changes: 2 additions & 1 deletion common/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
oteltrace "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)

var myAppName string
Expand Down Expand Up @@ -86,7 +87,7 @@ func NewSpanFromContext(ctx, sctx context.Context, spanName string, opts ...otel

//nolint:gocritic
func noopTracer(appName string) (oteltrace.Tracer, func(context.Context)) {
traceProvider := oteltrace.NewNoopTracerProvider()
traceProvider := noop.NewTracerProvider()
otel.SetTracerProvider(traceProvider)

return traceProvider.Tracer(appName), func(context.Context) {}
Expand Down
2 changes: 1 addition & 1 deletion common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

pbcommon "github.com/drand/drand/protobuf/common"
pbcommon "github.com/drand/drand/protobuf/drand"
)

// Must be manually updated!
Expand Down
9 changes: 5 additions & 4 deletions demo/lib/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

pdkg "github.com/drand/drand/protobuf/dkg"
json "github.com/nikkolasg/hexjson"

"github.com/drand/drand/common"
Expand Down Expand Up @@ -145,7 +146,7 @@ func (e *Orchestrator) RunDKG(timeout time.Duration) error {
leader := e.nodes[0]

fmt.Printf("\t- Running DKG for leader node %s\n", leader.PrivateAddr())
joiners := make([]*drand.Participant, len(e.nodes))
joiners := make([]*pdkg.Participant, len(e.nodes))
for i, n := range e.nodes {
identity, err := n.Identity()
if err != nil {
Expand Down Expand Up @@ -416,9 +417,9 @@ func (e *Orchestrator) UpdateGlobalBinary(binary string, isCandidate bool) {
}

type ResharingGroup struct {
leaving []*drand.Participant
joining []*drand.Participant
remaining []*drand.Participant
leaving []*pdkg.Participant
joining []*pdkg.Participant
remaining []*pdkg.Participant
}

func (e *Orchestrator) CreateResharingGroup(oldToRemove, threshold int) (*ResharingGroup, error) {
Expand Down
7 changes: 4 additions & 3 deletions demo/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/drand/drand/common/key"
"github.com/drand/drand/internal/chain"
pdkg "github.com/drand/drand/protobuf/dkg"
"github.com/drand/drand/protobuf/drand"
)

Expand All @@ -14,8 +15,8 @@ type Node interface {
CtrlAddr() string
PublicAddr() string
Index() int
StartLeaderDKG(thr int, catchupPeriod int, joiners []*drand.Participant) error
StartLeaderReshare(thr int, transitionTime time.Time, catchupPeriod int, joiners []*drand.Participant, remainers []*drand.Participant, leavers []*drand.Participant) error
StartLeaderDKG(thr int, catchupPeriod int, joiners []*pdkg.Participant) error
StartLeaderReshare(thr int, transitionTime time.Time, catchupPeriod int, joiners []*pdkg.Participant, remainers []*pdkg.Participant, leavers []*pdkg.Participant) error
ExecuteLeaderDKG() error
ExecuteLeaderReshare() error
JoinDKG() error
Expand All @@ -27,7 +28,7 @@ type Node interface {
Ping() bool
GetBeacon(groupPath string, round uint64) (*drand.PublicRandResponse, string)
WritePublic(path string)
Identity() (*drand.Participant, error)
Identity() (*pdkg.Participant, error)
Stop()
PrintLog()
}
10 changes: 5 additions & 5 deletions demo/node/node_inprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"time"

pdkg "github.com/drand/drand/protobuf/dkg"
clock "github.com/jonboulle/clockwork"

common2 "github.com/drand/drand/common"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/drand/drand/internal/net"
"github.com/drand/drand/internal/test"
"github.com/drand/drand/internal/util"
"github.com/drand/drand/protobuf/common"
"github.com/drand/drand/protobuf/drand"
)

Expand Down Expand Up @@ -202,7 +202,7 @@ func (l *LocalNode) ctrl() *net.ControlClient {
return cl
}

func (l *LocalNode) StartLeaderDKG(thr int, catchupPeriod int, joiners []*drand.Participant) error {
func (l *LocalNode) StartLeaderDKG(thr int, catchupPeriod int, joiners []*pdkg.Participant) error {
p, err := time.ParseDuration(l.period)
if err != nil {
return err
Expand All @@ -221,7 +221,7 @@ func (l *LocalNode) WaitDKGComplete(epoch uint32, timeout time.Duration) (*key.G
return nil, err
}

groupPacket, err := l.daemon.GroupFile(context.Background(), &drand.GroupRequest{Metadata: &common.Metadata{
groupPacket, err := l.daemon.GroupFile(context.Background(), &drand.GroupRequest{Metadata: &drand.Metadata{
BeaconID: l.beaconID,
}})
if err != nil {
Expand Down Expand Up @@ -254,7 +254,7 @@ func (l *LocalNode) GetGroup() *key.Group {
return group
}

func (l *LocalNode) StartLeaderReshare(thr int, transitionTime time.Time, catchupPeriod int, joiners []*drand.Participant, remainers []*drand.Participant, leavers []*drand.Participant) error {
func (l *LocalNode) StartLeaderReshare(thr int, transitionTime time.Time, catchupPeriod int, joiners []*pdkg.Participant, remainers []*pdkg.Participant, leavers []*pdkg.Participant) error {
err := l.dkgRunner.StartProposal(thr, transitionTime, catchupPeriod, joiners, remainers, leavers)
if err != nil {
l.log.Errorw("", "drand", "dkg run failed", "err", err)
Expand Down Expand Up @@ -349,7 +349,7 @@ func (l *LocalNode) PrintLog() {
fmt.Printf("%s\n", string(buff))
}

func (l *LocalNode) Identity() (*drand.Participant, error) {
func (l *LocalNode) Identity() (*pdkg.Participant, error) {
keypair, err := l.daemon.KeypairFor(l.beaconID)
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions demo/node/node_subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/BurntSushi/toml"
pdkg "github.com/drand/drand/protobuf/dkg"
clock "github.com/jonboulle/clockwork"
json "github.com/nikkolasg/hexjson"

Expand Down Expand Up @@ -203,7 +204,7 @@ func (n *NodeProc) Index() int {
return n.i
}

func (n *NodeProc) StartLeaderDKG(thr int, _ int, joiners []*drand.Participant) error {
func (n *NodeProc) StartLeaderDKG(thr int, _ int, joiners []*pdkg.Participant) error {
proposal := ProposalFile{
Joining: joiners,
}
Expand Down Expand Up @@ -276,7 +277,7 @@ func (n *NodeProc) JoinReshare(oldGroup key.Group) error {
return nil
}

func (n *NodeProc) StartLeaderReshare(thr int, transitionTime time.Time, catchupPeriod int, joiners []*drand.Participant, remainers []*drand.Participant, leavers []*drand.Participant) error {
func (n *NodeProc) StartLeaderReshare(thr int, transitionTime time.Time, catchupPeriod int, joiners []*pdkg.Participant, remainers []*pdkg.Participant, leavers []*pdkg.Participant) error {
proposalFileName := "proposal.toml"
proposal := ProposalFile{
Joining: joiners,
Expand Down Expand Up @@ -435,7 +436,7 @@ func (n *NodeProc) PrintLog() {
fmt.Printf("%s\n", string(buff))
}

func (n *NodeProc) Identity() (*drand.Participant, error) {
func (n *NodeProc) Identity() (*pdkg.Participant, error) {
keypair, err := n.store.LoadKeyPair()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion demo/node/proposal_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/BurntSushi/toml"

cli "github.com/drand/drand/internal/drand-cli"
"github.com/drand/drand/protobuf/drand"
drand "github.com/drand/drand/protobuf/dkg"
)

type ProposalFile struct {
Expand Down
95 changes: 46 additions & 49 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ require (
github.com/briandowns/spinner v1.23.0
github.com/drand/kyber v1.2.0
github.com/drand/kyber-bls12381 v0.3.1
github.com/go-chi/chi v1.5.4
github.com/go-chi/chi v1.5.5
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/jedib0t/go-pretty/v6 v6.4.9
github.com/jmoiron/sqlx v1.3.5
github.com/jonboulle/clockwork v0.4.0
github.com/lib/pq v1.10.9
github.com/nikkolasg/hexjson v0.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_golang v1.17.0
github.com/rogpeppe/go-internal v1.11.0
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.7
github.com/urfave/cli/v2 v2.26.0
github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5
go.etcd.io/bbolt v1.3.7
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
go.uber.org/zap v1.25.0
golang.org/x/crypto v0.14.0
golang.org/x/net v0.17.0
golang.org/x/sys v0.13.0
go.etcd.io/bbolt v1.3.8
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.43.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.17.0
go.opentelemetry.io/otel/sdk v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.16.0
golang.org/x/net v0.19.0
golang.org/x/sys v0.15.0
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
)
Expand All @@ -44,57 +44,54 @@ require (
replace github.com/urfave/cli/v2 => github.com/urfave/cli/v2 v2.19.3

require (
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/googleapis v1.1.0 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/status v1.0.3 // indirect
github.com/golang/glog v1.1.1 // indirect
github.com/gogo/status v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/mux v1.7.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02 // indirect
github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e // indirect
github.com/opentracing-contrib/go-stdlib v1.0.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sercand/kuberesolver/v4 v4.0.0 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/uber/jaeger-client-go v2.28.0+incompatible // indirect
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/weaveworks/promrus v1.2.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230807174057-1744710a1577 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 81e40d5

Please sign in to comment.