Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
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
iota-imt
goshimmer
Commits
c57d358b
Unverified
Commit
c57d358b
authored
4 years ago
by
Levente Pap
Browse files
Options
Downloads
Patches
Plain Diff
Filter parents before counting
parent
11d12d0e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/tangle/message.go
+8
-4
8 additions, 4 deletions
packages/tangle/message.go
packages/tangle/message_test.go
+18
-0
18 additions, 0 deletions
packages/tangle/message_test.go
with
26 additions
and
4 deletions
packages/tangle/message.go
+
8
−
4
View file @
c57d358b
...
...
@@ -167,20 +167,24 @@ type Message struct {
// NewMessage creates a new message with the details provided by the issuer.
func
NewMessage
(
strongParents
[]
MessageID
,
weakParents
[]
MessageID
,
issuingTime
time
.
Time
,
issuerPublicKey
ed25519
.
PublicKey
,
sequenceNumber
uint64
,
payload
payload
.
Payload
,
nonce
uint64
,
signature
ed25519
.
Signature
)
(
result
*
Message
)
{
// remove duplicates, sort in ASC
sortedStrongParents
:=
sortParents
(
strongParents
)
sortedWeakParents
:=
sortParents
(
weakParents
)
// syntactical validation
parentsCount
:=
len
(
strongParents
)
+
len
(
w
eakParents
)
parentsCount
:=
len
(
s
ortedS
trongParents
)
+
len
(
sortedW
eakParents
)
if
parentsCount
<
MinParentsCount
||
parentsCount
>
MaxParentsCount
{
panic
(
fmt
.
Sprintf
(
"amount of parents (%d) not in valid range (%d-%d)"
,
parentsCount
,
MinParentsCount
,
MaxParentsCount
))
}
if
len
(
strongParents
)
<
MinStrongParentsCount
{
if
len
(
s
ortedS
trongParents
)
<
MinStrongParentsCount
{
panic
(
fmt
.
Sprintf
(
"amount of strong parents (%d) failed to reach MinStrongParentsCount (%d)"
,
len
(
strongParents
),
MinStrongParentsCount
))
}
return
&
Message
{
version
:
MessageVersion
,
strongParents
:
sort
Parents
(
s
trongParents
)
,
weakParents
:
sort
Parents
(
w
eakParents
)
,
strongParents
:
sort
edS
trongParents
,
weakParents
:
sort
edW
eakParents
,
issuerPublicKey
:
issuerPublicKey
,
issuingTime
:
issuingTime
,
sequenceNumber
:
sequenceNumber
,
...
...
This diff is collapsed.
Click to expand it.
packages/tangle/message_test.go
+
18
−
0
View file @
c57d358b
...
...
@@ -343,6 +343,24 @@ func TestMessage_NewMessage(t *testing.T) {
})
})
t
.
Run
(
"CASE: Too many parents, but okay without duplicates"
,
func
(
t
*
testing
.
T
)
{
strongParents
:=
randomParents
(
MaxParentsCount
)
// MaxParentsCount + 1 parents, but there is one duplicate
strongParents
=
append
(
strongParents
,
strongParents
[
MaxParentsCount
-
1
])
assert
.
NotPanics
(
t
,
func
()
{
_
=
NewMessage
(
strongParents
,
nil
,
time
.
Now
(),
ed25519
.
PublicKey
{},
0
,
payload
.
NewGenericDataPayload
([]
byte
(
""
)),
0
,
ed25519
.
Signature
{},
)
})
})
t
.
Run
(
"CASE: Strong parents are sorted"
,
func
(
t
*
testing
.
T
)
{
// max number of parents supplied (only strong)
strongParents
:=
randomParents
(
MaxParentsCount
)
...
...
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