Fix ordering of Waku/Whisper queue and increase queue capacity

This commit is contained in:
kdeme 2020-01-14 18:17:37 +01:00
parent 5e476dd7d2
commit ab287d234a
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
4 changed files with 22 additions and 3 deletions

View File

@ -63,7 +63,7 @@ declarePublicCounter dropped_malicious_duplicate_envelopes,
"Dropped malicious duplicate envelopes" "Dropped malicious duplicate envelopes"
const const
defaultQueueCapacity = 256 defaultQueueCapacity = 2048
wakuVersion* = 0 ## Waku version. wakuVersion* = 0 ## Waku version.
wakuVersionStr* = $wakuVersion ## Waku version. wakuVersionStr* = $wakuVersion ## Waku version.
defaultMinPow* = 0.2'f64 ## The default minimum PoW requirement for this node. defaultMinPow* = 0.2'f64 ## The default minimum PoW requirement for this node.

View File

@ -473,7 +473,7 @@ proc calcPowHash*(self: Envelope): Hash =
proc cmpPow(a, b: Message): int = proc cmpPow(a, b: Message): int =
## Biggest pow first, lowest at the end (for easy popping) ## Biggest pow first, lowest at the end (for easy popping)
if a.pow > b.pow: 1 if a.pow < b.pow: 1
elif a.pow == b.pow: 0 elif a.pow == b.pow: 0
else: -1 else: -1

View File

@ -56,7 +56,7 @@ declarePublicCounter dropped_malicious_duplicate_envelopes,
"Dropped malicious duplicate envelopes" "Dropped malicious duplicate envelopes"
const const
defaultQueueCapacity = 256 defaultQueueCapacity = 2048
whisperVersion* = 6 ## Whisper version. whisperVersion* = 6 ## Whisper version.
whisperVersionStr* = $whisperVersion ## Whisper version. whisperVersionStr* = $whisperVersion ## Whisper version.
defaultMinPow* = 0.2'f64 ## The default minimum PoW requirement for this node. defaultMinPow* = 0.2'f64 ## The default minimum PoW requirement for this node.

View File

@ -182,6 +182,9 @@ let
env1 = Envelope( env1 = Envelope(
expiry:100000, ttl: 30, topic: [byte 0, 0, 0, 0], expiry:100000, ttl: 30, topic: [byte 0, 0, 0, 0],
data: repeat(byte 9, 256), nonce: 1010102) data: repeat(byte 9, 256), nonce: 1010102)
env2 = Envelope(
expiry:100000, ttl: 30, topic: [byte 0, 0, 0, 0],
data: repeat(byte 9, 256), nonce: 1010103)
suite "Whisper envelope": suite "Whisper envelope":
@ -247,6 +250,22 @@ suite "Whisper queue":
queue.items.len() == 2 queue.items.len() == 2
test "check if order of queue is by decreasing PoW":
var queue = initQueue(3)
let msg0 = initMessage(env0)
let msg1 = initMessage(env1)
let msg2 = initMessage(env2)
discard queue.add(msg0)
discard queue.add(msg1)
discard queue.add(msg2)
check:
queue.items.len() == 3
queue.items[0].pow > queue.items[1].pow and
queue.items[1].pow > queue.items[2].pow
test "check field order against expected rlp order": test "check field order against expected rlp order":
check rlp.encode(env0) == check rlp.encode(env0) ==
rlp.encodeList(env0.expiry, env0.ttl, env0.topic, env0.data, env0.nonce) rlp.encodeList(env0.expiry, env0.ttl, env0.topic, env0.data, env0.nonce)