Add DNSSEEDER environment flag in order to ignore blocks and transactions

This commit is contained in:
Ori Newman 2022-09-23 09:31:30 +03:00
parent 6c774c966b
commit 5ae0dfdf50
4 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package common
import ( import (
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer" peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
routerpkg "github.com/kaspanet/kaspad/infrastructure/network/netadapter/router" routerpkg "github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
"os"
"sync"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -25,3 +27,18 @@ type Flow struct {
// FlowInitializeFunc is a function that is used in order to initialize a flow // FlowInitializeFunc is a function that is used in order to initialize a flow
type FlowInitializeFunc func(route *routerpkg.Route, peer *peerpkg.Peer) error type FlowInitializeFunc func(route *routerpkg.Route, peer *peerpkg.Peer) error
var isDNSSeeder bool
var isDNSSeederOnce sync.Once
// IsDNSSeeder returns whether this node supports a DNS seeder. If this is the case, the node
// doesn't need to actually stay synced, and is mainly used for scanning the p2p network.
func IsDNSSeeder() bool {
isDNSSeederOnce.Do(func() {
isDNSSeederEnv := os.Getenv("DNSSEEDER")
if isDNSSeederEnv != "" {
isDNSSeeder = true
}
})
return isDNSSeeder
}

View File

@ -77,6 +77,11 @@ func (flow *handleRelayInvsFlow) start() error {
return err return err
} }
if common.IsDNSSeeder() {
log.Debugf("IsDNSSeeder=true so skipping block inv")
continue
}
log.Debugf("Got relay inv for block %s", inv.Hash) log.Debugf("Got relay inv for block %s", inv.Hash)
blockInfo, err := flow.Domain().Consensus().GetBlockInfo(inv.Hash) blockInfo, err := flow.Domain().Consensus().GetBlockInfo(inv.Hash)

View File

@ -50,6 +50,11 @@ func (flow *handleRelayedTransactionsFlow) start() error {
return err return err
} }
if common.IsDNSSeeder() {
log.Debugf("IsDNSSeeder=true so skipping tx inv")
continue
}
isNearlySynced, err := flow.IsNearlySynced() isNearlySynced, err := flow.IsNearlySynced()
if err != nil { if err != nil {
return err return err

View File

@ -0,0 +1,9 @@
package transactionrelay
import (
"github.com/kaspanet/kaspad/infrastructure/logger"
"github.com/kaspanet/kaspad/util/panics"
)
var log = logger.RegisterSubSystem("TXRL")
var spawn = panics.GoroutineWrapperFunc(log)