From 5ed9f6c71b0584f7ee46a4d12e22c3437fde86ad Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Tue, 21 Jan 2025 09:45:39 +1100 Subject: [PATCH] fixup! fix(drand): add null HistoricalBeaconClient for old beacons --- chain/beacon/drand/drand.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index 6cef9d163e..39d0b515f0 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -102,9 +102,6 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion) clients = append(clients, hc) } - if len(clients) == 0 { - clients = append(clients, HistoricalBeaconClient{}) - } opts := []dclient.Option{ dclient.WithChainInfo(drandChain), @@ -116,6 +113,13 @@ 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 { + historicalClient := &historicalBeaconClient{} + clients = append(clients, historicalClient) + opts = append(opts, dclient.WithWatcher(func(chainInfo *dchain.Info, cache dclient.Cache) (dclient.Watcher, error) { + return historicalClient, nil + })) + } } client, err := dclient.Wrap(clients, opts...) @@ -254,30 +258,30 @@ func BeaconScheduleFromDrandSchedule(dcs dtypes.DrandSchedule, genesisTime uint6 return shd, nil } -var _ dclient.Client = HistoricalBeaconClient{} +var _ dclient.Client = historicalBeaconClient{} -// HistoricalBeaconClient is a drand client that doesn't actually do anything. It's used when +// 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{} +type historicalBeaconClient struct{} -func (h HistoricalBeaconClient) Get(ctx context.Context, round uint64) (dclient.Result, error) { +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 { +func (h historicalBeaconClient) Watch(ctx context.Context) <-chan dclient.Result { return nil } -func (h HistoricalBeaconClient) Info(ctx context.Context) (*dchain.Info, error) { +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 { +func (h historicalBeaconClient) RoundAt(time.Time) uint64 { return 0 } -func (h HistoricalBeaconClient) Close() error { +func (h historicalBeaconClient) Close() error { return nil }