Skip to content
Snippets Groups Projects
Unverified Commit 82fc88d1 authored by Luca Moser's avatar Luca Moser Committed by GitHub
Browse files

Fixes some small bugs in the sync plugin (#571)

* fix incorrect usage of timer instead of ticker

* only add anchor points with newer issuance times

* adds before time boundary
parent cd341c70
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,12 @@ const ( ...@@ -39,6 +39,12 @@ const (
// CfgSyncDesyncedIfNoMessageAfterSec defines the time period in which new messages must be received and if not // CfgSyncDesyncedIfNoMessageAfterSec defines the time period in which new messages must be received and if not
// the node is marked as desynced. // the node is marked as desynced.
CfgSyncDesyncedIfNoMessageAfterSec = "sync.desyncedIfNoMessagesAfterSec" CfgSyncDesyncedIfNoMessageAfterSec = "sync.desyncedIfNoMessagesAfterSec"
// defines the max. divergence a potential new anchor point's issuance time can have
// from the current issuance threshold. say the current threshold is at 1000, the boundary at 10,
// we allow a new potential anchor point's issuance time to be within >=990 / 10 seconds older
// than the current threshold.
issuanceThresholdBeforeTimeBoundary = 20 * time.Second
) )
func init() { func init() {
...@@ -218,7 +224,7 @@ func monitorForSynchronization() { ...@@ -218,7 +224,7 @@ func monitorForSynchronization() {
defer messagelayer.Tangle().Events.MessageSolid.Detach(checkAnchorPointSolidityClosure) defer messagelayer.Tangle().Events.MessageSolid.Detach(checkAnchorPointSolidityClosure)
cleanupDelta := config.Node().GetDuration(CfgSyncAnchorPointsCleanupAfterSec) * time.Second cleanupDelta := config.Node().GetDuration(CfgSyncAnchorPointsCleanupAfterSec) * time.Second
ticker := time.NewTimer(config.Node().GetDuration(CfgSyncAnchorPointsCleanupIntervalSec) * time.Second) ticker := time.NewTicker(config.Node().GetDuration(CfgSyncAnchorPointsCleanupIntervalSec) * time.Second)
defer ticker.Stop() defer ticker.Stop()
for { for {
select { select {
...@@ -263,9 +269,11 @@ func initAnchorPoint(anchorPoints *anchorpoints, msg *message.Message) *message. ...@@ -263,9 +269,11 @@ func initAnchorPoint(anchorPoints *anchorpoints, msg *message.Message) *message.
return nil return nil
} }
// add a new anchor point // add a new anchor point if its issuance time is newer than any other anchor point
id := msg.Id() id := msg.Id()
anchorPoints.add(id) if !anchorPoints.add(id, msg.IssuingTime()) {
return nil
}
return &id return &id
} }
...@@ -312,11 +320,22 @@ type anchorpoints struct { ...@@ -312,11 +320,22 @@ type anchorpoints struct {
wanted int wanted int
// how many anchor points have been solidified. // how many anchor points have been solidified.
solidified int solidified int
// holds the highest issuance time of any message which was an anchor point.
// this is used to determine whether further attached messages should become an
// anchor point by matching their issuance time against this time.
issuanceTimeThreshold time.Time
} }
// adds the given message to the anchor points set. // adds the given message to the anchor points set if its issuance time is newer than
func (ap *anchorpoints) add(id message.Id) { // any other existing anchor point's.
func (ap *anchorpoints) add(id message.Id, issuanceTime time.Time) bool {
if !ap.issuanceTimeThreshold.IsZero() &&
ap.issuanceTimeThreshold.Add(-issuanceThresholdBeforeTimeBoundary).After(issuanceTime) {
return false
}
ap.ids[id] = time.Now() ap.ids[id] = time.Now()
ap.issuanceTimeThreshold = issuanceTime
return true
} }
func (ap *anchorpoints) has(id message.Id) bool { func (ap *anchorpoints) has(id message.Id) bool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment