Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Goshimmer_without_tipselection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLET Ismael
Goshimmer_without_tipselection
Commits
32f8ddda
Unverified
Commit
32f8ddda
authored
4 years ago
by
Levente Pap
Browse files
Options
Downloads
Patches
Plain Diff
Add client lib tool for past cone exist verification
parent
34eaedc7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/tools.go
+59
-0
59 additions, 0 deletions
client/tools.go
with
59 additions
and
0 deletions
client/tools.go
0 → 100644
+
59
−
0
View file @
32f8ddda
package
client
import
(
"container/list"
"errors"
"fmt"
)
// genesisID is the ID of the genesis message
var
genesisID
=
"1111111111111111111111111111111111111111111111111111111111111111"
// PastConeExist checks that all of the messages in the the past cone of a message are existing on the node
// down to the genesis. Returns the number of messages in the past cone as well.
func
(
api
*
GoShimmerAPI
)
PastConeExist
(
messageID
string
)
(
bool
,
int
,
error
)
{
// create a new stack that hold messages to check
stack
:=
list
.
New
()
stack
.
PushBack
(
messageID
)
// keep track of submitted checks (to not re-add something to the stack that is already in it)
// searching in double-linked list is quite expensive, but not in a map
submitted
:=
make
(
map
[
string
]
bool
)
var
checkedMessageCount
int
// process messages, try to request parents until we end up at the genesis
for
stack
.
Len
()
>
0
{
checkedMessageCount
++
// pop the first element from stack
currentMsgElement
:=
stack
.
Front
()
currentMsgID
:=
currentMsgElement
.
Value
.
(
string
)
stack
.
Remove
(
currentMsgElement
)
// ask node if it has it
response
,
err
:=
api
.
FindMessageByID
([]
string
{
currentMsgID
})
if
err
!=
nil
{
return
false
,
checkedMessageCount
,
errors
.
New
(
fmt
.
Sprintf
(
"error while requesting %s message: %s"
,
currentMsgID
,
err
.
Error
()))
}
currentMsg
:=
response
.
Messages
[
0
]
// the first element in response.Messages is Messages{}, so its ID is empty if message doesn't exist on node
if
currentMsg
.
ID
==
""
{
return
false
,
checkedMessageCount
,
errors
.
New
(
fmt
.
Sprintf
(
"message %s doesn't exist on node"
,
currentMsgID
))
}
// is it the genesis?
if
currentMsg
.
BranchID
==
genesisID
&&
currentMsg
.
TrunkID
==
genesisID
{
continue
}
else
{
if
!
submitted
[
currentMsg
.
BranchID
]
{
stack
.
PushBack
(
currentMsg
.
BranchID
)
submitted
[
currentMsg
.
BranchID
]
=
true
}
if
!
submitted
[
currentMsg
.
TrunkID
]
{
stack
.
PushBack
(
currentMsg
.
TrunkID
)
submitted
[
currentMsg
.
TrunkID
]
=
true
}
}
}
return
true
,
checkedMessageCount
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment