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 1 commit
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
Prev Previous commit
Next Next commit
Fix merge problems
  • Loading branch information
piotrm50 committed Jun 1, 2022
commit 991e02aeac8db266ed1cceb75b947a5fe3f2d15f
19 changes: 9 additions & 10 deletions packages/tangle/timemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (t *TimeManager) Start() {
func (t *TimeManager) Setup() {
t.tangle.ConfirmationOracle.Events().MessageConfirmed.Attach(event.NewClosure(func(event *MessageConfirmedEvent) {
t.updateTime(event.Message)
t.updateSyncedState()
}))
t.Start()
}
Expand Down Expand Up @@ -167,16 +168,14 @@ func (t *TimeManager) updateTime(message *Message) {
t.lastConfirmedMutex.Lock()
defer t.lastConfirmedMutex.Unlock()

if t.lastConfirmedMessage.MessageTime.After(message.IssuingTime()) {
return
}
t.lastConfirmedMessage = LastConfirmedMessage{
MessageID: message.ID(),
MessageTime: message.IssuingTime(),
ConfirmedTime: time.Now(),
}
})
t.updateSyncedState()
if t.lastConfirmedMessage.MessageTime.After(message.IssuingTime()) {
return
}
t.lastConfirmedMessage = LastConfirmedMessage{
MessageID: message.ID(),
MessageTime: message.IssuingTime(),
ConfirmedTime: time.Now(),
}
}

// RCTT return relative confirmed tangle time.
Expand Down
21 changes: 14 additions & 7 deletions packages/tangle/tipmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ func TestTipManager_DataMessageTips(t *testing.T) {
assert.Len(t, parents, 1)
assert.Contains(t, parents, EmptyMessageID)
}

fmt.Println("send genesis")
// without any count -> 1 tip, in this case genesis
{
parents, err := tipManager.Tips(nil, 0)
assert.NoError(t, err)
assert.Len(t, parents, 1)
assert.Contains(t, parents, EmptyMessageID)
}

fmt.Println("send msg1")
// Message 1
{
messages["1"] = createAndStoreParentsDataMessageInMasterBranch(tangle, NewMessageIDs(EmptyMessageID), NewMessageIDs())
tipManager.AddTip(messages["1"])
tangle.TimeManager.updateTime(messages["1"])
tangle.TimeManager.updateSyncedState()

assert.Equal(t, 1, tipManager.TipCount())
assert.Contains(t, tipManager.tips.Keys(), messages["1"].ID())
Expand All @@ -54,7 +55,7 @@ func TestTipManager_DataMessageTips(t *testing.T) {
assert.Len(t, parents, 1)
assert.Contains(t, parents, messages["1"].ID())
}

fmt.Println("send msg2")
// Message 2
{
messages["2"] = createAndStoreParentsDataMessageInMasterBranch(tangle, NewMessageIDs(EmptyMessageID), NewMessageIDs())
Expand All @@ -68,7 +69,7 @@ func TestTipManager_DataMessageTips(t *testing.T) {
assert.Len(t, parents, 2)
assert.Contains(t, parents, messages["1"].ID(), messages["2"].ID())
}

fmt.Println("send msg3")
// Message 3
{
messages["3"] = createAndStoreParentsDataMessageInMasterBranch(tangle, NewMessageIDs(messages["1"].ID(), messages["2"].ID()), NewMessageIDs())
Expand All @@ -82,7 +83,7 @@ func TestTipManager_DataMessageTips(t *testing.T) {
assert.Len(t, parents, 1)
assert.Contains(t, parents, messages["3"].ID())
}

fmt.Println("send msg3")
// Add Message 4-8
{
tips := NewMessageIDs()
Expand All @@ -96,6 +97,7 @@ func TestTipManager_DataMessageTips(t *testing.T) {
assert.Equalf(t, count+2, tipManager.TipCount(), "TipCount does not match after adding Message %d", n)
assert.ElementsMatchf(t, tipManager.tips.Keys(), tips.Slice(), "Elements in strongTips do not match after adding Message %d", n)
assert.Contains(t, tipManager.tips.Keys(), messages["3"].ID())
fmt.Println("send msg", n)
}
}

Expand All @@ -106,18 +108,21 @@ func TestTipManager_DataMessageTips(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, parents, 4)
}
fmt.Println("select tip1")
// Tips(8) -> 6
{
parents, err := tipManager.Tips(nil, 8)
assert.NoError(t, err)
assert.Len(t, parents, 6)
}
fmt.Println("select tip2")
// Tips(0) -> 1
{
parents, err := tipManager.Tips(nil, 0)
assert.NoError(t, err)
assert.Len(t, parents, 1)
}
fmt.Println("select tip3")
}

// TODO: FIX
Expand Down Expand Up @@ -439,6 +444,7 @@ func TestTipManager_TimeSinceConfirmation_Unconfirmed(t *testing.T) {

tangle.ConfirmationOracle = &MockConfirmationOracleTipManagerTest{confirmedMessageIDs: confirmedMessageIDs, confirmedMarkers: confirmedMarkers}
tangle.TimeManager.updateTime(testFramework.Message("Marker-2/3"))
tangle.TimeManager.updateSyncedState()

// Even without any confirmations, it should be possible to attach to genesis.
assert.True(t, tipManager.isPastConeTimestampCorrect(EmptyMessageID))
Expand Down Expand Up @@ -501,6 +507,7 @@ func TestTipManager_TimeSinceConfirmation_Confirmed(t *testing.T) {

tangle.ConfirmationOracle = &MockConfirmationOracleTipManagerTest{confirmedMessageIDs: confirmedMessageIDs, confirmedMarkers: confirmedMarkers}
tangle.TimeManager.updateTime(testFramework.Message("Marker-2/3"))
tangle.TimeManager.updateSyncedState()

// Even without any confirmations, it should be possible to attach to genesis.
assert.True(t, tipManager.isPastConeTimestampCorrect(EmptyMessageID))
Expand Down Expand Up @@ -570,7 +577,7 @@ func createTestTangleTSC(t *testing.T, testFramework *MessageTestFramework) {

// issue message for test case #16
testFramework.CreateMessage("0/1-postTSC-direct_0", WithStrongParents("Marker-0/1"))
testFramework.IssueMessages("0/1-postTSC-direct_0").WaitMessagesBooked()
testFramework.IssueMessages("0/1-postTSC-direct_0").WaitUntilAllTasksProcessed()

checkMarkers(t, testFramework, map[string]*markers.Markers{
"Marker-0/1": markers.NewMarkers(markers.NewMarker(0, 1)),
Expand Down Expand Up @@ -772,7 +779,7 @@ func createTestTangleTSC(t *testing.T, testFramework *MessageTestFramework) {
lastMsgAlias = issueMessages(testFramework, "0/1-postTSCSeq6", 6, []string{"0/1-preTSCSeq2_2"}, 0)
testFramework.PreventNewMarkers(false)
testFramework.CreateMessage("Marker-6/2", WithStrongParents(lastMsgAlias))
testFramework.IssueMessages("Marker-6/2").WaitMessagesBooked()
testFramework.IssueMessages("Marker-6/2").WaitUntilAllTasksProcessed()
testFramework.PreventNewMarkers(true)
_ = issueMessages(testFramework, "6/2", 5, []string{"Marker-6/2"}, 0)
testFramework.PreventNewMarkers(false)
Expand Down
14 changes: 13 additions & 1 deletion packages/tangle/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ func TestUtils_AllTransactionsApprovedByMessages(t *testing.T) {
mtf := NewMessageTestFramework(tangle, WithGenesisOutput("Genesis1", 5), WithGenesisOutput("Genesis2", 8))

mtf.CreateMessage("Message1", WithStrongParents("Genesis"))
mtf.IssueMessages("Message1").WaitUntilAllTasksProcessed()

mtf.CreateMessage("Message2", WithInputs("Genesis1"), WithOutput("A", 5), WithStrongParents("Message1"))
mtf.IssueMessages("Message2").WaitUntilAllTasksProcessed()

mtf.CreateMessage("Message3", WithStrongParents("Message2"))
mtf.IssueMessages("Message3").WaitUntilAllTasksProcessed()

mtf.CreateMessage("Message4", WithStrongParents("Genesis"))
mtf.IssueMessages("Message4").WaitUntilAllTasksProcessed()

mtf.CreateMessage("Message5", WithInputs("Genesis2"), WithOutput("B", 4), WithOutput("C", 4), WithStrongParents("Message4"))
mtf.IssueMessages("Message5").WaitUntilAllTasksProcessed()

mtf.CreateMessage("Message6", WithStrongParents("Message5"))
mtf.IssueMessages("Message6").WaitUntilAllTasksProcessed()

mtf.CreateMessage("Message7", WithInputs("A", "B", "C"), WithOutput("D", 13), WithStrongParents("Message3", "Message6"))

mtf.IssueMessages("Message1", "Message2", "Message3", "Message4", "Message5", "Message6", "Message7").WaitUntilAllTasksProcessed()
mtf.IssueMessages("Message7").WaitUntilAllTasksProcessed()

for messageAlias, expectedMarkers := range map[string]*markers.Markers{
"Message1": markers.NewMarkers(markers.NewMarker(0, 1)),
Expand Down