-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -100,7 +100,6 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes | |||||
} | ||||||
hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion) | ||||||
clients = append(clients, hc) | ||||||
|
||||||
} | ||||||
|
||||||
opts := []dclient.Option{ | ||||||
|
@@ -113,6 +112,18 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes | |||||
opts = append(opts, gclient.WithPubsub(ps)) | ||||||
} else { | ||||||
log.Info("drand beacon without pubsub") | ||||||
if len(clients) == 0 { | ||||||
// This hack is necessary to convince a drand beacon to start without any clients. For | ||||||
// historical becaons we need them to be able to verify old entries but we don't need to fetch | ||||||
// new ones. With pubsub enabled, it acts as a client so drand is happy, but if we don't have | ||||||
// pubsub then drand will complain about old beacons withotu clients. So we make one that | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// it'll think is a valid client and that it won't speed test (hence the need to mark it as | ||||||
// as "watcher"). | ||||||
historicalClient := &historicalBeaconClient{} | ||||||
opts = append(opts, dclient.WithWatcher(func(chainInfo *dchain.Info, cache dclient.Cache) (dclient.Watcher, error) { | ||||||
return historicalClient, nil | ||||||
Comment on lines
+123
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the trick is to have your client's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking into this, it's possible we're not properly "supporting" that special error in the I could change it if it'd help, so that we're not reporting the
log line when it sees that error. |
||||||
})) | ||||||
} | ||||||
} | ||||||
|
||||||
client, err := dclient.Wrap(clients, opts...) | ||||||
|
@@ -239,13 +250,41 @@ 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("%d creating drand beacon: %w", i, err) | ||||||
} | ||||||
shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc}) | ||||||
} | ||||||
|
||||||
return shd, nil | ||||||
} | ||||||
|
||||||
var _ dclient.Client = historicalBeaconClient{} | ||||||
|
||||||
// historicalBeaconClient is a drand client that doesn't actually do anything. It's used when | ||||||
// we don't have a drand network to connect to but still need to provide a beacon client. | ||||||
// We don't expect calls through to the client to be made since we should only be verifying old | ||||||
// randomness, not fetching it. | ||||||
type historicalBeaconClient struct{} | ||||||
|
||||||
func (h historicalBeaconClient) Get(ctx context.Context, round uint64) (dclient.Result, error) { | ||||||
return nil, xerrors.Errorf("no historical randomness available") | ||||||
} | ||||||
|
||||||
func (h historicalBeaconClient) Watch(ctx context.Context) <-chan dclient.Result { | ||||||
return nil | ||||||
} | ||||||
|
||||||
func (h historicalBeaconClient) Info(ctx context.Context) (*dchain.Info, error) { | ||||||
return nil, xerrors.Errorf("no historical randomness available") | ||||||
} | ||||||
|
||||||
func (h historicalBeaconClient) RoundAt(time.Time) uint64 { | ||||||
return 0 | ||||||
} | ||||||
|
||||||
func (h historicalBeaconClient) Close() error { | ||||||
return nil | ||||||
} | ||||||
Comment on lines
+264
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm very surprised the |
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.