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

fix(drand): add null HistoricalBeaconClient for old beacons #12830

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

- chore: upgrade to the latest go-f3 and allow F3 chain exchange topics ([filecoin-project/lotus#12893](https://github.com/filecoin-project/lotus/pull/12893)

- chore: upgrade drand client, this increases the Go minimum version to v1.22.10.


# UNRELEASED v.1.32.0

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#####################################
FROM golang:1.22.7-bullseye AS lotus-builder
FROM golang:1.22.10-bullseye AS lotus-builder
MAINTAINER Lotus Development Team

RUN apt-get update && apt-get install -y ca-certificates build-essential clang ocl-icd-opencl-dev ocl-icd-libopencl1 jq libhwloc-dev
Expand Down
2 changes: 1 addition & 1 deletion GO_VERSION_MIN
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.22.7
1.22.10
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://github.com/filecoin-project/lotus/actions/workflows/check.yml"><img src="https://github.com/filecoin-project/lotus/actions/workflows/check.yml/badge.svg"></a>
<a href="https://github.com/filecoin-project/lotus/actions/workflows/test.yml"><img src="https://github.com/filecoin-project/lotus/actions/workflows/test.yml/badge.svg"></a>
<a href="https://goreportcard.com/report/github.com/filecoin-project/lotus"><img src="https://goreportcard.com/badge/github.com/filecoin-project/lotus" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.22.7-blue.svg" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.22.10-blue.svg" /></a>
<br>
</p>

Expand Down Expand Up @@ -58,10 +58,10 @@ For other distributions you can find the required dependencies [here.](https://l

#### Go

To build Lotus, you need a working installation of [Go 1.22.7 or higher](https://golang.org/dl/):
To build Lotus, you need a working installation of [Go 1.22.10 or higher](https://golang.org/dl/):

```bash
wget -c https://golang.org/dl/go1.22.7.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
wget -c https://golang.org/dl/go1.22.10.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
```

**TIP:**
Expand Down
41 changes: 23 additions & 18 deletions chain/beacon/drand/drand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
drand "github.com/drand/go-clients/drand"
"github.com/drand/kyber"
lru "github.com/hashicorp/golang-lru/v2"
logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -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 drand.Client

pubkey kyber.Point

Expand Down Expand Up @@ -92,15 +94,14 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
return nil, xerrors.Errorf("unable to unmarshal drand chain info: %w", err)
}

var clients []dclient.Client
var clients []drand.Client
for _, url := range config.Servers {
hc, err := hclient.NewWithInfo(url, drandChain, nil)
hc, err := hclient.NewWithInfo(&logger{&log.SugaredLogger}, 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{
Expand All @@ -112,7 +113,11 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
if ps != nil {
opts = append(opts, gclient.WithPubsub(ps))
} else {
log.Info("drand beacon without pubsub")
if len(clients) == 0 {
// This is necessary to convince a drand beacon to start without any clients. For historical
// beacons we need them to be able to verify old entries but we don't need to fetch new ones.
clients = append(clients, dclient.EmptyClientWithInfo(drandChain))
}
}

client, err := dclient.Wrap(clients, opts...)
Expand All @@ -131,7 +136,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
}
Expand Down Expand Up @@ -165,8 +170,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
Expand All @@ -192,7 +197,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,
Expand Down Expand Up @@ -239,10 +244,10 @@ var _ beacon.RandomBeacon = (*DrandBeacon)(nil)

func BeaconScheduleFromDrandSchedule(dcs dtypes.DrandSchedule, genesisTime uint64, ps *pubsub.PubSub) (beacon.Schedule, error) {
shd := beacon.Schedule{}
for _, dc := range dcs {
for i, dc := range dcs {
bc, err := NewDrandBeacon(genesisTime, buildconstants.BlockDelaySecs, ps, dc.Config)
if err != nil {
return nil, xerrors.Errorf("creating drand beacon: %w", err)
return nil, xerrors.Errorf("creating drand beacon #%d: %w", i, err)
}
shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc})
}
Expand Down
11 changes: 4 additions & 7 deletions chain/beacon/drand/drand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"testing"

dchain "github.com/drand/drand/chain"
hclient "github.com/drand/drand/client/http"
dchain "github.com/drand/drand/v2/common/chain"
hclient "github.com/drand/go-clients/client/http"
"github.com/stretchr/testify/assert"

"github.com/filecoin-project/go-state-types/network"
Expand All @@ -22,13 +22,10 @@ func TestPrintGroupInfo(t *testing.T) {

drandChain, err := dchain.InfoFromJSON(bytes.NewReader([]byte(chainInfo)))
assert.NoError(t, err)
c, err := hclient.NewWithInfo(server, drandChain, nil)
c, err := hclient.NewWithInfo(&logger{&log.SugaredLogger}, server, drandChain, nil)

assert.NoError(t, err)
cg := c.(interface {
FetchChainInfo(ctx context.Context, groupHash []byte) (*dchain.Info, error)
})
chain, err := cg.FetchChainInfo(context.Background(), nil)
chain, err := c.FetchChainInfo(context.Background(), nil)
assert.NoError(t, err)
err = chain.ToJSON(os.Stdout, nil)
assert.NoError(t, err)
Expand Down
Loading
Loading