mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +00:00
Add --delay to kaspad
This commit is contained in:
parent
54fbfadf84
commit
635b793e14
@ -1,6 +1,8 @@
|
|||||||
package blockrelay
|
package blockrelay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/common"
|
"github.com/kaspanet/kaspad/app/protocol/common"
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
@ -11,6 +13,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
|
"github.com/kaspanet/kaspad/util/mstime"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -109,6 +112,8 @@ func (flow *handleRelayInvsFlow) start() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
msTime := mstime.UnixMilliseconds(block.Header.TimeInMilliseconds())
|
||||||
|
time.Sleep(time.Until(msTime.ToNativeTime().Add(config.DelayDuration)))
|
||||||
|
|
||||||
log.Debugf("Processing block %s", inv.Hash)
|
log.Debugf("Processing block %s", inv.Hash)
|
||||||
missingParents, blockInsertionResult, err := flow.processBlock(block)
|
missingParents, blockInsertionResult, err := flow.processBlock(block)
|
||||||
|
|||||||
@ -25,6 +25,9 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DelayDuration a duration for the delay, global for testing
|
||||||
|
var DelayDuration time.Duration
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultConfigFilename = "kaspad.conf"
|
defaultConfigFilename = "kaspad.conf"
|
||||||
defaultDataDirname = "data"
|
defaultDataDirname = "data"
|
||||||
@ -117,6 +120,7 @@ type Flags struct {
|
|||||||
MaxUTXOCacheSize uint64 `long:"maxutxocachesize" description:"Max size of loaded UTXO into ram from the disk in bytes"`
|
MaxUTXOCacheSize uint64 `long:"maxutxocachesize" description:"Max size of loaded UTXO into ram from the disk in bytes"`
|
||||||
UTXOIndex bool `long:"utxoindex" description:"Enable the UTXO index"`
|
UTXOIndex bool `long:"utxoindex" description:"Enable the UTXO index"`
|
||||||
IsArchivalNode bool `long:"archival" description:"Run as an archival node: don't delete old block data when moving the pruning point (Warning: heavy disk usage)'"`
|
IsArchivalNode bool `long:"archival" description:"Run as an archival node: don't delete old block data when moving the pruning point (Warning: heavy disk usage)'"`
|
||||||
|
Delay float32 `long:"delay" description:"Provide a delay in seconds as a floating point"`
|
||||||
NetworkFlags
|
NetworkFlags
|
||||||
ServiceOptions *ServiceOptions
|
ServiceOptions *ServiceOptions
|
||||||
}
|
}
|
||||||
@ -574,6 +578,7 @@ func LoadConfig() (*Config, error) {
|
|||||||
log.Warnf("%s", configFileError)
|
log.Warnf("%s", configFileError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DelayDuration = time.Duration(cfg.Delay * float32(time.Second))
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package netadapter
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
||||||
@ -175,9 +176,10 @@ func (na *NetAdapter) ID() *id.ID {
|
|||||||
// P2PBroadcast sends the given `message` to every peer corresponding
|
// P2PBroadcast sends the given `message` to every peer corresponding
|
||||||
// to each NetConnection in the given netConnections
|
// to each NetConnection in the given netConnections
|
||||||
func (na *NetAdapter) P2PBroadcast(netConnections []*NetConnection, message appmessage.Message) error {
|
func (na *NetAdapter) P2PBroadcast(netConnections []*NetConnection, message appmessage.Message) error {
|
||||||
|
go func() {
|
||||||
|
time.Sleep(config.DelayDuration)
|
||||||
na.p2pConnectionsLock.RLock()
|
na.p2pConnectionsLock.RLock()
|
||||||
defer na.p2pConnectionsLock.RUnlock()
|
defer na.p2pConnectionsLock.RUnlock()
|
||||||
|
|
||||||
for _, netConnection := range netConnections {
|
for _, netConnection := range netConnections {
|
||||||
err := netConnection.router.OutgoingRoute().Enqueue(message)
|
err := netConnection.router.OutgoingRoute().Enqueue(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -185,8 +187,9 @@ func (na *NetAdapter) P2PBroadcast(netConnections []*NetConnection, message appm
|
|||||||
log.Debugf("Cannot enqueue message to %s: router is closed", netConnection)
|
log.Debugf("Cannot enqueue message to %s: router is closed", netConnection)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user