mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Change SyncRateWindow to 15 minutes + update sync times on block headers as well (#1331)
* Change SyncRateWindow to 15 minutes + update sync times on block headers as well * Rename result to isSyncRateTooLow * Fix formula for expected blocks
This commit is contained in:
parent
23304a4977
commit
6fa3aa1dca
@ -24,7 +24,7 @@ func (f *FlowContext) OnNewBlock(block *externalapi.DomainBlock,
|
||||
log.Debugf("OnNewBlock start for block %s", hash)
|
||||
defer log.Debugf("OnNewBlock end for block %s", hash)
|
||||
|
||||
f.updateRecentBlockAddedTimesWithLastBlock()
|
||||
f.UpdateRecentBlockAddedTimesWithLastBlock()
|
||||
unorphaningResults, err := f.UnorphanBlocks(block)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -156,7 +156,7 @@ func (f *FlowContext) unorphanBlock(orphanHash externalapi.DomainHash) (*externa
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
f.updateRecentBlockAddedTimesWithLastBlock()
|
||||
f.UpdateRecentBlockAddedTimesWithLastBlock()
|
||||
|
||||
log.Infof("Unorphaned block %s", orphanHash)
|
||||
return blockInsertionResult, true, nil
|
||||
|
@ -3,12 +3,14 @@ package flowcontext
|
||||
import "github.com/kaspanet/kaspad/util/mstime"
|
||||
|
||||
const (
|
||||
syncRateWindowInMilliSeconds = 60_000
|
||||
syncRateWindowInMilliSeconds = 15 * 60 * 1000
|
||||
syncRateMaxDeviation = 0.05
|
||||
maxSelectedParentTimeDiffToAllowMiningInMilliSeconds = 300_000
|
||||
)
|
||||
|
||||
func (f *FlowContext) updateRecentBlockAddedTimesWithLastBlock() {
|
||||
// UpdateRecentBlockAddedTimesWithLastBlock adds current time to list of times when block was added.
|
||||
// We use this list to determine the current sync rate
|
||||
func (f *FlowContext) UpdateRecentBlockAddedTimesWithLastBlock() {
|
||||
f.recentBlockAddedTimesMutex.Lock()
|
||||
defer f.recentBlockAddedTimesMutex.Unlock()
|
||||
|
||||
@ -44,7 +46,14 @@ func (f *FlowContext) isSyncRateBelowMinimum() bool {
|
||||
}
|
||||
|
||||
expectedBlocks := float64(syncRateWindowInMilliSeconds) / float64(f.cfg.NetParams().TargetTimePerBlock.Milliseconds())
|
||||
return 1-float64(len(f.recentBlockAddedTimes))/expectedBlocks > syncRateMaxDeviation
|
||||
isSyncRateTooLow := 1-float64(len(f.recentBlockAddedTimes))/expectedBlocks > syncRateMaxDeviation
|
||||
|
||||
if isSyncRateTooLow {
|
||||
log.Debugf("In the last %d seconds, got %d blocks, while at least %f were expected.",
|
||||
syncRateWindowInMilliSeconds/1000, len(f.recentBlockAddedTimes), expectedBlocks*(1-syncRateMaxDeviation))
|
||||
}
|
||||
|
||||
return isSyncRateTooLow
|
||||
}
|
||||
|
||||
// ShouldMine returns whether it's ok to use block template from this node
|
||||
|
@ -33,6 +33,7 @@ type RelayInvsContext interface {
|
||||
IsIBDRunning() bool
|
||||
TrySetIBDRunning() bool
|
||||
UnsetIBDRunning()
|
||||
UpdateRecentBlockAddedTimesWithLastBlock()
|
||||
}
|
||||
|
||||
type handleRelayInvsFlow struct {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package blockrelay
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kaspanet/kaspad/app/appmessage"
|
||||
"github.com/kaspanet/kaspad/app/protocol/common"
|
||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
||||
@ -8,7 +10,6 @@ import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/ruleerrors"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (flow *handleRelayInvsFlow) runIBDIfNotRunning(highHash *externalapi.DomainHash) error {
|
||||
@ -257,6 +258,9 @@ func (flow *handleRelayInvsFlow) processHeader(msgBlockHeader *appmessage.MsgBlo
|
||||
|
||||
return protocolerrors.Wrapf(true, err, "got invalid block %s during IBD", blockHash)
|
||||
}
|
||||
|
||||
flow.UpdateRecentBlockAddedTimesWithLastBlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user