Skip to content

Commit

Permalink
Update TSC to compare tangle time with time of confirmed message. (#2167
Browse files Browse the repository at this point in the history
)

* Update TSC to compare tangle time with time of confirmed message.

* Fix unit tests

* Change TSC threshold to 1 minute

* Return values explicitly.

* New time concepts (#2193)

* Add CTT, FTT. Rename Synced to Bootstrapped

* Add RCTT and RFTT to time manager

* Change sync logic to bootstrap

* Add new time types to the API responses

* Use RCTT for activity window

* Review fixes

* Review fixes

* Use to distinct states for bootstrapped and synced

* Add bootstrapped check

* Change RCTT calculation

* Issue metrics only when node is synced.

Co-authored-by: Daria Dziubałtowska <daria.dziubaltowska@iota.org>
Co-authored-by: Piotr Macek <piotr.macek@iota.org>

* Use refactored time manager.

* Fix merge problems

* Activate tests?

* Fix unit test

* Add different tangle times to dashboard and update their naming.

* Update pkged.go

* Further improve tangle times on dashboard

* Fix tangle time naming.

* Make integration tests more stable.

* Fix imports

* Add clarifying comment and improve code readability

* Address review comments.

* Remove tips older than TSC

* Update pkged.go

* Apply suggestions from code review

Co-authored-by: Jonas Theis <4181434+jonastheis@users.noreply.github.com>

* Fix build

* Update activity window for consensus mana

Co-authored-by: Georgy Savva <georgysavva@pm.me>
Co-authored-by: Daria Dziubałtowska <daria.dziubaltowska@iota.org>
Co-authored-by: jonastheis <4181434+jonastheis@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 21, 2022
1 parent 0e5e057 commit f22b3f2
Show file tree
Hide file tree
Showing 34 changed files with 552 additions and 261 deletions.
9 changes: 6 additions & 3 deletions packages/jsonmodels/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ type InfoResponse struct {

// TangleTime contains the TangleTime sync detailed status.
type TangleTime struct {
MessageID string `json:"messageID"`
Time int64 `json:"time"`
Synced bool `json:"synced"`
AcceptedMessageID string `json:"messageID"`
ATT int64 `json:"ATT"`
RATT int64 `json:"RATT"`
CTT int64 `json:"CTT"`
RCTT int64 `json:"RCTT"`
Synced bool `json:"synced"`
}

// Mana contains the different mana values of the node.
Expand Down
12 changes: 9 additions & 3 deletions packages/remotemetrics/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CollectionLogEvents struct {
SchedulerQuery *event.Event[*SchedulerQueryEvent]
}

func newCollectionLogEvents() (newEvents *CollectionLogEvents) {
func newCollectionLogEvents() *CollectionLogEvents {
return &CollectionLogEvents{
TangleTimeSyncChanged: event.New[*TangleTimeSyncChangedEvent](),
SchedulerQuery: event.New[*SchedulerQueryEvent](),
Expand All @@ -34,8 +34,14 @@ type TangleTimeSyncChangedEvent struct {
CurrentStatus bool `json:"currentStatus" bson:"currentStatus"`
// PreviousStatus contains previous sync status
PreviousStatus bool `json:"previousStatus" bson:"previousStatus"`
// LastConfirmedMessageTime contains time of the last confirmed message
LastConfirmedMessageTime time.Time `json:"lastConfirmedMessageTime" bson:"lastConfirmedMessageTime"`
// ATT contains time of the last accepted message
ATT time.Time `json:"acceptanceTangleTime" bson:"acceptanceTangleTime"`
// RATT contains relative time of the last accepted message
RATT time.Time `json:"relativeAcceptanceTangleTime" bson:"relativeAcceptanceTangleTime"`
// CTT contains time of the last confirmed message
CTT time.Time `json:"confirmedTangleTime" bson:"confirmedTangleTime"`
// RCTT contains relative time of the last confirmed message
RCTT time.Time `json:"relativeConfirmedTangleTime" bson:"relativeConfirmedTangleTime"`
}

// SchedulerQueryEvent is used to trigger scheduler metric collection for remote metric monitoring.
Expand Down
2 changes: 1 addition & 1 deletion packages/spammer/spammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Spammer) run(rate int, timeUnit time.Duration, imif string) {
defer s.goroutinesCount.Add(-1)
// we don't care about errors or the actual issued message
_, err := s.issuePayloadFunc(payload.NewGenericDataPayload([]byte("SPAM")))
if errors.Is(err, tangle.ErrNotSynced) {
if errors.Is(err, tangle.ErrNotBootstrapped) {
s.log.Info("Stopped spamming messages because node lost sync")
s.signalShutdown()
return
Expand Down
2 changes: 1 addition & 1 deletion packages/tangle/cmanaweightprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
}

const (
activeTimeThreshold = 30 * time.Minute
activeTimeThreshold = 5 * time.Minute
minimumManaThreshold = 0
activeNodesKey = "WeightProviderActiveNodes"
)
Expand Down
12 changes: 6 additions & 6 deletions packages/tangle/cmanaweightprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ func TestCManaWeightProvider(t *testing.T) {

// Add node2 and node3 activity at tangleTime+20 -> only node1 is active.
{
weightProvider.Update(tangleTime.Add(20*time.Minute), nodes["2"])
weightProvider.Update(tangleTime.Add(20*time.Minute), nodes["3"])
weightProvider.Update(tangleTime.Add(3*time.Minute), nodes["2"])
weightProvider.Update(tangleTime.Add(3*time.Minute), nodes["3"])
assertWeightsOfRelevantVoters(t, weightProvider, nodes, map[string]float64{
"1": 20,
})
}

// Advance TangleTime by 25min -> all nodes are active.
// Advance TangleTime by 4min -> all nodes are active.
{
tangleTime = tangleTime.Add(25 * time.Minute)
tangleTime = tangleTime.Add(4 * time.Minute)
assertWeightsOfRelevantVoters(t, weightProvider, nodes, map[string]float64{
"1": 20,
"2": 50,
Expand All @@ -85,7 +85,7 @@ func TestCManaWeightProvider(t *testing.T) {

// Advance TangleTime by 10min -> node1 and node2 are active.
{
tangleTime = tangleTime.Add(25 * time.Minute)
tangleTime = tangleTime.Add(2 * time.Minute)
assertWeightsOfRelevantVoters(t, weightProvider, nodes, map[string]float64{
"2": 50,
"3": 30,
Expand All @@ -94,7 +94,7 @@ func TestCManaWeightProvider(t *testing.T) {

// Advance tangleTime by 25min -> no node is active anymore.
{
tangleTime = tangleTime.Add(25 * time.Minute)
tangleTime = tangleTime.Add(4 * time.Minute)
assertWeightsOfRelevantVoters(t, weightProvider, nodes, map[string]float64{})
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/tangle/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tangle
import "github.com/cockroachdb/errors"

var (
// ErrNotSynced is triggered when somebody tries to issue a Payload before the Tangle is fully synced.
ErrNotSynced = errors.New("tangle not synced")
// ErrNotBootstrapped is triggered when somebody tries to issue a Payload before the Tangle is fully bootstrapped.
ErrNotBootstrapped = errors.New("tangle not bootstrapped")
// ErrParentsInvalid is returned when one or more parents of a message is invalid.
ErrParentsInvalid = errors.New("one or more parents is invalid")
)
15 changes: 13 additions & 2 deletions packages/tangle/events.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tangle

import (
"time"

"github.com/iotaledger/hive.go/autopeering/peer"
"github.com/iotaledger/hive.go/generics/event"
"github.com/iotaledger/hive.go/identity"
Expand Down Expand Up @@ -382,12 +384,16 @@ type RequestFailedEvent struct {
// TimeManagerEvents represents events happening in the TimeManager.
type TimeManagerEvents struct {
// Fired when the nodes sync status changes.
SyncChanged *event.Event[*SyncChangedEvent]
SyncChanged *event.Event[*SyncChangedEvent]
AcceptanceTimeUpdated *event.Event[*TimeUpdate]
ConfirmedTimeUpdated *event.Event[*TimeUpdate]
}

func newTimeManagerEvents() (new *TimeManagerEvents) {
return &TimeManagerEvents{
SyncChanged: event.New[*SyncChangedEvent](),
SyncChanged: event.New[*SyncChangedEvent](),
AcceptanceTimeUpdated: event.New[*TimeUpdate](),
ConfirmedTimeUpdated: event.New[*TimeUpdate](),
}
}

Expand All @@ -396,6 +402,11 @@ type SyncChangedEvent struct {
Synced bool
}

// TimeUpdate represents an update in Tangle Time.
type TimeUpdate struct {
NewTime time.Time
}

// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////

// region TipManagerEvents /////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Binary file modified packages/tangle/images/TSC_test_scenario.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions packages/tangle/tangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,21 @@ func (t *Tangle) ProcessGossipMessage(messageBytes []byte, peer *peer.Peer) {

// IssuePayload allows to attach a payload (i.e. a Transaction) to the Tangle.
func (t *Tangle) IssuePayload(p payload.Payload, parentsCount ...int) (message *Message, err error) {
if !t.Synced() {
err = errors.Errorf("can't issue payload: %w", ErrNotSynced)
if !t.Bootstrapped() {
err = errors.Errorf("can't issue payload: %w", ErrNotBootstrapped)
return
}

return t.MessageFactory.IssuePayload(p, parentsCount...)
}

// Synced returns a boolean value that indicates if the node is fully synced and the Tangle has solidified all messages
// Bootstrapped returns a boolean value that indicates if the node has bootstrapped and the Tangle has solidified all messages
// until the genesis.
func (t *Tangle) Synced() (synced bool) {
func (t *Tangle) Bootstrapped() bool {
return t.TimeManager.Bootstrapped()
}

// Synced returns a boolean value that indicates if the node is in sync at this moment.
func (t *Tangle) Synced() bool {
return t.TimeManager.Synced()
}

Expand Down
Loading

0 comments on commit f22b3f2

Please sign in to comment.