Merge pull request #1869 from filecoin-project/feat/drand-pubsub

Add pubsub support to drand beacon
This commit is contained in:
Jakub Sztandera
2020-05-29 18:06:38 +02:00
committed by GitHub
7 changed files with 54 additions and 28 deletions
+1
View File
@@ -38,6 +38,7 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
options := []pubsub.Option{
// Gossipsubv1.1 configuration
pubsub.WithFloodPublish(true),
pubsub.WithMessageIdFn(HashMsgId),
pubsub.WithPeerScore(
&pubsub.PeerScoreParams{
AppSpecificScore: func(p peer.ID) float64 {
+10 -3
View File
@@ -123,12 +123,19 @@ func RetrievalResolver(l *discovery.Local) retrievalmarket.PeerResolver {
return discovery.Multi(l)
}
func RandomBeacon(cs *store.ChainStore, _ dtypes.AfterGenesisSet) (beacon.RandomBeacon, error) {
gen, err := cs.GetGenesis()
type RandomBeaconParams struct {
fx.In
PubSub *pubsub.PubSub `optional:"true"`
Cs *store.ChainStore
}
func RandomBeacon(p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.RandomBeacon, error) {
gen, err := p.Cs.GetGenesis()
if err != nil {
return nil, err
}
//return beacon.NewMockBeacon(build.BlockDelay * time.Second)
return drand.NewDrandBeacon(gen.Timestamp, build.BlockDelay)
return drand.NewDrandBeacon(gen.Timestamp, build.BlockDelay, p.PubSub)
}
-11
View File
@@ -43,8 +43,6 @@ import (
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/beacon/drand"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/markets/retrievaladapter"
@@ -360,12 +358,3 @@ func StorageAuth(ctx helpers.MetricsCtx, ca lapi.Common) (sectorstorage.StorageA
headers.Add("Authorization", "Bearer "+string(token))
return sectorstorage.StorageAuth(headers), nil
}
func MinerRandomBeacon(api lapi.FullNode) (beacon.RandomBeacon, error) {
gents, err := api.ChainGetGenesis(context.TODO())
if err != nil {
return nil, err
}
return drand.NewDrandBeacon(gents.Blocks()[0].Timestamp, build.BlockDelay)
}