Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TSC to compare tangle time with time of confirmed message. #2167

Merged
merged 29 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c55372c
Update TSC to compare tangle time with time of confirmed message.
piotrm50 Apr 21, 2022
26c5485
Fix unit tests
piotrm50 Apr 21, 2022
f35a32a
Change TSC threshold to 1 minute
piotrm50 Apr 21, 2022
87b2a84
Return values explicitly.
piotrm50 May 21, 2022
7d9fec4
Merge branch 'develop' into feat/tsc-update
georgysavva May 23, 2022
5c8c286
New time concepts (#2193)
georgysavva May 23, 2022
c231414
Use refactored time manager.
piotrm50 May 24, 2022
46a02b0
Merge branch 'develop' into feat/tsc-update
piotrm50 Jun 1, 2022
991e02a
Fix merge problems
piotrm50 Jun 1, 2022
06f45a8
Activate tests?
piotrm50 Jun 1, 2022
c807905
Merge remote-tracking branch 'origin/develop' into feat/tsc-update
piotrm50 Jun 2, 2022
4074b10
Merge branch 'develop' into feat/tsc-update
piotrm50 Jun 7, 2022
aa4fe56
Fix unit test
piotrm50 Jun 7, 2022
0b7074c
Merge remote-tracking branch 'origin/develop' into feat/tsc-update
piotrm50 Jun 9, 2022
1620093
Add different tangle times to dashboard and update their naming.
piotrm50 Jun 10, 2022
cc7a546
Update pkged.go
piotrm50 Jun 10, 2022
7bfd7b0
Further improve tangle times on dashboard
piotrm50 Jun 10, 2022
f5e08dc
Fix tangle time naming.
piotrm50 Jun 13, 2022
0e1e0ae
Make integration tests more stable.
piotrm50 Jun 15, 2022
363561d
Fix imports
piotrm50 Jun 15, 2022
34a2a37
Merge remote-tracking branch 'origin/develop' into feat/tsc-update
piotrm50 Jun 17, 2022
8927e1a
Add clarifying comment and improve code readability
jonastheis Jun 20, 2022
0ca4f61
Address review comments.
piotrm50 Jun 21, 2022
33c2f6d
Remove tips older than TSC
piotrm50 Jun 21, 2022
ce651a4
Merge remote-tracking branch 'origin/develop' into feat/tsc-update
piotrm50 Jun 21, 2022
77727b1
Update pkged.go
piotrm50 Jun 21, 2022
c234482
Apply suggestions from code review
piotrm50 Jun 21, 2022
0bf67b7
Fix build
piotrm50 Jun 21, 2022
4097ec8
Update activity window for consensus mana
piotrm50 Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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