From 46dc2e97736e304fa5398289566c0d281d02cf8e Mon Sep 17 00:00:00 2001 From: tal Date: Mon, 30 Nov 2020 17:15:20 +0200 Subject: [PATCH] [NOD - 1143] Cosmetics changes. --- .../processes/ghostdag2/ghostdagimpl.go | 13 +- domain/consensus/testdata/dags/dag30.json | 252 ++++++++++++++++++ 2 files changed, 258 insertions(+), 7 deletions(-) create mode 100644 domain/consensus/testdata/dags/dag30.json diff --git a/domain/consensus/processes/ghostdag2/ghostdagimpl.go b/domain/consensus/processes/ghostdag2/ghostdagimpl.go index 34b3008e2..5a161ad40 100644 --- a/domain/consensus/processes/ghostdag2/ghostdagimpl.go +++ b/domain/consensus/processes/ghostdag2/ghostdagimpl.go @@ -354,15 +354,14 @@ func (gh *ghostdagHelper) sortByBlueScore(arr []*externalapi.DomainHash) error { err = error return false } - var isSmaller = false + if blockLeft.BlueScore < blockRight.BlueScore { - isSmaller = true - } else { - if blockRight.BlueScore == blockLeft.BlueScore { - isSmaller = ismoreHash(arr[j], arr[i]) - } + return true } - return isSmaller + if blockLeft.BlueScore == blockRight.BlueScore { + return ismoreHash(arr[j], arr[i]) + } + return false }) return err } diff --git a/domain/consensus/testdata/dags/dag30.json b/domain/consensus/testdata/dags/dag30.json new file mode 100644 index 000000000..9ae408b92 --- /dev/null +++ b/domain/consensus/testdata/dags/dag30.json @@ -0,0 +1,252 @@ +{ + "K": 4, + "GenesisID": "A", + "ExpectedReds": [ + "Q", + "H", + "I" + ], + "Blocks": [ + { + "ID": "B", + "ExpectedScore": 1, + "ExpectedSelectedParent": "A", + "ExpectedReds": [], + "ExpectedBlues": [ + "A" + ], + "Parents": [ + "A" + ] + }, + { + "ID": "C", + "ExpectedScore": 2, + "ExpectedSelectedParent": "B", + "ExpectedReds": [], + "ExpectedBlues": [ + "B" + ], + "Parents": [ + "B" + ] + }, + { + "ID": "D", + "ExpectedScore": 1, + "ExpectedSelectedParent": "A", + "ExpectedReds": [], + "ExpectedBlues": [ + "A" + ], + "Parents": [ + "A" + ] + }, + { + "ID": "E", + "ExpectedScore": 4, + "ExpectedSelectedParent": "C", + "ExpectedReds": [], + "ExpectedBlues": [ + "C", + "D" + ], + "Parents": [ + "C", + "D" + ] + }, + { + "ID": "F", + "ExpectedScore": 1, + "ExpectedSelectedParent": "A", + "ExpectedReds": [], + "ExpectedBlues": [ + "A" + ], + "Parents": [ + "A" + ] + }, + { + "ID": "G", + "ExpectedScore": 2, + "ExpectedSelectedParent": "F", + "ExpectedReds": [], + "ExpectedBlues": [ + "F" + ], + "Parents": [ + "F" + ] + }, + { + "ID": "H", + "ExpectedScore": 1, + "ExpectedSelectedParent": "A", + "ExpectedReds": [], + "ExpectedBlues": [ + "A" + ], + "Parents": [ + "A" + ] + }, + { + "ID": "I", + "ExpectedScore": 1, + "ExpectedSelectedParent": "A", + "ExpectedReds": [], + "ExpectedBlues": [ + "A" + ], + "Parents": [ + "A" + ] + }, + { + "ID": "J", + "ExpectedScore": 7, + "ExpectedSelectedParent": "E", + "ExpectedReds": [], + "ExpectedBlues": [ + "E", + "F", + "G" + ], + "Parents": [ + "E", + "G" + ] + }, + { + "ID": "K", + "ExpectedScore": 8, + "ExpectedSelectedParent": "J", + "ExpectedReds": [], + "ExpectedBlues": [ + "J" + ], + "Parents": [ + "J" + ] + }, + { + "ID": "L", + "ExpectedScore": 9, + "ExpectedSelectedParent": "K", + "ExpectedReds": ["I"], + "ExpectedBlues": [ + "K" + ], + "Parents": [ + "I", + "K" + ] + }, + { + "ID": "M", + "ExpectedScore": 10, + "ExpectedSelectedParent": "L", + "ExpectedReds": [], + "ExpectedBlues": [ + "L" + ], + "Parents": [ + "L" + ] + }, + { + "ID": "N", + "ExpectedScore": 11, + "ExpectedSelectedParent": "M", + "ExpectedReds": [], + "ExpectedBlues": [ + "M" + ], + "Parents": [ + "M" + ] + }, + { + "ID": "O", + "ExpectedScore": 11, + "ExpectedSelectedParent": "M", + "ExpectedReds": [], + "ExpectedBlues": [ + "M" + ], + "Parents": [ + "M" + ] + }, + { + "ID": "P", + "ExpectedScore": 11, + "ExpectedSelectedParent": "M", + "ExpectedReds": [], + "ExpectedBlues": [ + "M" + ], + "Parents": [ + "M" + ] + }, + { + "ID": "Q", + "ExpectedScore": 11, + "ExpectedSelectedParent": "M", + "ExpectedReds": [], + "ExpectedBlues": [ + "M" + ], + "Parents": [ + "M" + ] + }, + { + "ID": "R", + "ExpectedScore": 11, + "ExpectedSelectedParent": "M", + "ExpectedReds": [], + "ExpectedBlues": [ + "M" + ], + "Parents": [ + "M" + ] + }, + { + "ID": "S", + "ExpectedScore": 12, + "ExpectedSelectedParent": "R", + "ExpectedReds": [], + "ExpectedBlues": [ + "R" + ], + "Parents": [ + "R" + ] + }, + { + "ID": "T", + "ExpectedScore": 16, + "ExpectedSelectedParent": "S", + "ExpectedReds": ["Q"], + "ExpectedBlues": [ + "S", + "P", + "N", + "O" + ], + "Parents": [ + "N", + "O", + "P", + "Q", + "S" + ] + } + ] +}