Merge pull request #8045 from gammazero/feat/cid-to-piece-idx

Add indexer pubsub message authentication and rate limiting
This commit is contained in:
Will
2022-02-10 13:49:58 -08:00
committed by GitHub
7 changed files with 402 additions and 13 deletions
+19
View File
@@ -114,6 +114,22 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
InvalidMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour),
}
ingestTopicParams := &pubsub.TopicScoreParams{
// expected ~0.5 confirmed deals / min. sampled
TopicWeight: 0.1,
TimeInMeshWeight: 0.00027, // ~1/3600
TimeInMeshQuantum: time.Second,
TimeInMeshCap: 1,
FirstMessageDeliveriesWeight: 0.5,
FirstMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour),
FirstMessageDeliveriesCap: 100, // allowing for burstiness
InvalidMessageDeliveriesWeight: -1000,
InvalidMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour),
}
topicParams := map[string]*pubsub.TopicScoreParams{
build.BlocksTopic(in.Nn): {
// expected 10 blocks/min
@@ -208,6 +224,9 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
drandTopics = append(drandTopics, topic)
}
// Index ingestion whitelist
topicParams[build.IndexerIngestTopic(in.Nn)] = ingestTopicParams
// IP colocation whitelist
var ipcoloWhitelist []*net.IPNet
for _, cidr := range in.Cfg.IPColocationWhitelist {
+3 -2
View File
@@ -35,6 +35,7 @@ import (
"github.com/filecoin-project/lotus/lib/peermgr"
marketevents "github.com/filecoin-project/lotus/markets/loggers"
"github.com/filecoin-project/lotus/node/hello"
"github.com/filecoin-project/lotus/node/impl/full"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/filecoin-project/lotus/node/repo"
@@ -198,10 +199,10 @@ func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub
waitForSync(stmgr, pubsubMsgsSyncEpochs, subscribe)
}
func RelayIndexerMessages(lc fx.Lifecycle, ps *pubsub.PubSub, nn dtypes.NetworkName, h host.Host) error {
func RelayIndexerMessages(lc fx.Lifecycle, ps *pubsub.PubSub, nn dtypes.NetworkName, h host.Host, chainModule full.ChainModuleAPI, stateModule full.StateModuleAPI) error {
topicName := build.IndexerIngestTopic(nn)
v := sub.NewIndexerMessageValidator(h.ID())
v := sub.NewIndexerMessageValidator(h.ID(), chainModule, stateModule)
if err := ps.RegisterTopicValidator(topicName, v.Validate); err != nil {
return xerrors.Errorf("failed to register validator for topic %s, err: %w", topicName, err)