mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-07-09 06:12:32 +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)
|
log.Debugf("OnNewBlock start for block %s", hash)
|
||||||
defer log.Debugf("OnNewBlock end for block %s", hash)
|
defer log.Debugf("OnNewBlock end for block %s", hash)
|
||||||
|
|
||||||
f.updateRecentBlockAddedTimesWithLastBlock()
|
f.UpdateRecentBlockAddedTimesWithLastBlock()
|
||||||
unorphaningResults, err := f.UnorphanBlocks(block)
|
unorphaningResults, err := f.UnorphanBlocks(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -156,7 +156,7 @@ func (f *FlowContext) unorphanBlock(orphanHash externalapi.DomainHash) (*externa
|
|||||||
}
|
}
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
f.updateRecentBlockAddedTimesWithLastBlock()
|
f.UpdateRecentBlockAddedTimesWithLastBlock()
|
||||||
|
|
||||||
log.Infof("Unorphaned block %s", orphanHash)
|
log.Infof("Unorphaned block %s", orphanHash)
|
||||||
return blockInsertionResult, true, nil
|
return blockInsertionResult, true, nil
|
||||||
|
@ -3,12 +3,14 @@ package flowcontext
|
|||||||
import "github.com/kaspanet/kaspad/util/mstime"
|
import "github.com/kaspanet/kaspad/util/mstime"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
syncRateWindowInMilliSeconds = 60_000
|
syncRateWindowInMilliSeconds = 15 * 60 * 1000
|
||||||
syncRateMaxDeviation = 0.05
|
syncRateMaxDeviation = 0.05
|
||||||
maxSelectedParentTimeDiffToAllowMiningInMilliSeconds = 300_000
|
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()
|
f.recentBlockAddedTimesMutex.Lock()
|
||||||
defer f.recentBlockAddedTimesMutex.Unlock()
|
defer f.recentBlockAddedTimesMutex.Unlock()
|
||||||
|
|
||||||
@ -44,7 +46,14 @@ func (f *FlowContext) isSyncRateBelowMinimum() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedBlocks := float64(syncRateWindowInMilliSeconds) / float64(f.cfg.NetParams().TargetTimePerBlock.Milliseconds())
|
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
|
// ShouldMine returns whether it's ok to use block template from this node
|
||||||
|
@ -33,6 +33,7 @@ type RelayInvsContext interface {
|
|||||||
IsIBDRunning() bool
|
IsIBDRunning() bool
|
||||||
TrySetIBDRunning() bool
|
TrySetIBDRunning() bool
|
||||||
UnsetIBDRunning()
|
UnsetIBDRunning()
|
||||||
|
UpdateRecentBlockAddedTimesWithLastBlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
type handleRelayInvsFlow struct {
|
type handleRelayInvsFlow struct {
|
||||||
|
@ -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"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors"
|
"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/ruleerrors"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (flow *handleRelayInvsFlow) runIBDIfNotRunning(highHash *externalapi.DomainHash) error {
|
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)
|
return protocolerrors.Wrapf(true, err, "got invalid block %s during IBD", blockHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flow.UpdateRecentBlockAddedTimesWithLastBlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user