mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-04 06:53:12 +00:00
* Separate new lightpush protocol New RPC defined Rename al occurence of old lightpush to legacy lightpush, fix rest tests of lightpush New lightpush protocol added back Setup new lightpush protocol, mounting and rest api for it modified: apps/chat2/chat2.nim modified: tests/node/test_wakunode_lightpush.nim modified: tests/node/test_wakunode_sharding.nim modified: tests/test_peer_manager.nim modified: tests/test_wakunode_lightpush.nim renamed: tests/waku_lightpush/lightpush_utils.nim -> tests/waku_lightpush_legacy/lightpush_utils.nim renamed: tests/waku_lightpush/test_all.nim -> tests/waku_lightpush_legacy/test_all.nim renamed: tests/waku_lightpush/test_client.nim -> tests/waku_lightpush_legacy/test_client.nim renamed: tests/waku_lightpush/test_ratelimit.nim -> tests/waku_lightpush_legacy/test_ratelimit.nim modified: tests/wakunode_rest/test_all.nim renamed: tests/wakunode_rest/test_rest_lightpush.nim -> tests/wakunode_rest/test_rest_lightpush_legacy.nim modified: waku/factory/node_factory.nim modified: waku/node/waku_node.nim modified: waku/waku_api/rest/admin/handlers.nim modified: waku/waku_api/rest/builder.nim new file: waku/waku_api/rest/legacy_lightpush/client.nim new file: waku/waku_api/rest/legacy_lightpush/handlers.nim new file: waku/waku_api/rest/legacy_lightpush/types.nim modified: waku/waku_api/rest/lightpush/client.nim modified: waku/waku_api/rest/lightpush/handlers.nim modified: waku/waku_api/rest/lightpush/types.nim modified: waku/waku_core/codecs.nim modified: waku/waku_lightpush.nim modified: waku/waku_lightpush/callbacks.nim modified: waku/waku_lightpush/client.nim modified: waku/waku_lightpush/common.nim modified: waku/waku_lightpush/protocol.nim modified: waku/waku_lightpush/rpc.nim modified: waku/waku_lightpush/rpc_codec.nim modified: waku/waku_lightpush/self_req_handler.nim new file: waku/waku_lightpush_legacy.nim renamed: waku/waku_lightpush/README.md -> waku/waku_lightpush_legacy/README.md new file: waku/waku_lightpush_legacy/callbacks.nim new file: waku/waku_lightpush_legacy/client.nim new file: waku/waku_lightpush_legacy/common.nim new file: waku/waku_lightpush_legacy/protocol.nim new file: waku/waku_lightpush_legacy/protocol_metrics.nim new file: waku/waku_lightpush_legacy/rpc.nim new file: waku/waku_lightpush_legacy/rpc_codec.nim new file: waku/waku_lightpush_legacy/self_req_handler.nim Adapt to non-invasive libp2p observers cherry pick latest lightpush (v1) changes into legacy lightpush code after rebase to latest master Fix vendor dependencies from origin/master after failed rebase of them Adjust examples, test to new lightpush - keep using of legacy Fixup error code mappings Fix REST admin interface with distinct legacy and new lightpush Fix lightpush v2 tests * Utilize new publishEx interface of pubsub libp2p * Adapt to latest libp2p pubslih design changes. publish returns an outcome as Result error. * Fix review findings * Fix tests, re-added lost one * Fix rebase * Apply suggestions from code review Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> * Addressing review comments * Fix incentivization tests * Fix build failed on libwaku * Change new lightpush endpoint version to 3 instead of 2. Noticed that old and new lightpush metrics can cause trouble in monitoring dashboards so decided to give new name as v3 for the new lightpush metrics and change legacy ones back - temporarly till old lightpush will be decommissioned * Fixing flaky test with rate limit timing * Fixing logscope of lightpush and legacy lightpush --------- Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
449 lines
12 KiB
Nim
449 lines
12 KiB
Nim
{.used.}
|
|
|
|
import std/[options, sequtils], stew/results, testutils/unittests
|
|
import waku/waku_core, waku/waku_enr, ./testlib/wakucore
|
|
|
|
suite "Waku ENR - Capabilities bitfield":
|
|
test "check capabilities support":
|
|
## Given
|
|
let bitfield: CapabilitiesBitfield = 0b0000_1101u8 # Lightpush, Filter, Relay
|
|
|
|
## Then
|
|
check:
|
|
bitfield.supportsCapability(Capabilities.Relay)
|
|
not bitfield.supportsCapability(Capabilities.Store)
|
|
bitfield.supportsCapability(Capabilities.Filter)
|
|
bitfield.supportsCapability(Capabilities.Lightpush)
|
|
|
|
test "bitfield to capabilities list":
|
|
## Given
|
|
let bitfield = CapabilitiesBitfield.init(
|
|
relay = true, store = false, lightpush = true, filter = true
|
|
)
|
|
|
|
## When
|
|
let caps = bitfield.toCapabilities()
|
|
|
|
## Then
|
|
check:
|
|
caps == @[Capabilities.Relay, Capabilities.Filter, Capabilities.Lightpush]
|
|
|
|
test "encode and decode record with capabilities field (EnrBuilder ext)":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
## When
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
builder.withWakuCapabilities(Capabilities.Relay, Capabilities.Store)
|
|
|
|
let recordRes = builder.build()
|
|
|
|
## Then
|
|
check recordRes.isOk()
|
|
let record = recordRes.tryGet()
|
|
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let bitfieldOpt = typedRecord.value.waku2
|
|
check bitfieldOpt.isSome()
|
|
|
|
let bitfield = bitfieldOpt.get()
|
|
check:
|
|
bitfield.toCapabilities() == @[Capabilities.Relay, Capabilities.Store]
|
|
|
|
test "cannot decode capabilities from record":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let record = EnrBuilder.init(enrPrivKey, enrSeqNum).build().tryGet()
|
|
|
|
## When
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let bitfieldOpt = typedRecord.value.waku2
|
|
|
|
## Then
|
|
check bitfieldOpt.isNone()
|
|
|
|
test "check capabilities on a waku node record":
|
|
## Given
|
|
let wakuRecord =
|
|
"-Hy4QC73_E3B_FkZhsOakaD4pHe-U--UoGASdG9N0F3SFFUDY_jdQbud8" &
|
|
"EXVyrlOZ5pZ7VYFBDPMRCENwy87Lh74dFIBgmlkgnY0iXNlY3AyNTZrMaECvNt1jIWbWGp" &
|
|
"AWWdlLGYm1E1OjlkQk3ONoxDC5sfw8oOFd2FrdTID"
|
|
|
|
## When
|
|
var record: Record
|
|
require waku_enr.fromBase64(record, wakuRecord)
|
|
|
|
## Then
|
|
let typedRecordRes = record.toTyped()
|
|
require typedRecordRes.isOk()
|
|
|
|
let bitfieldOpt = typedRecordRes.value.waku2
|
|
require bitfieldOpt.isSome()
|
|
|
|
let bitfield = bitfieldOpt.get()
|
|
check:
|
|
bitfield.supportsCapability(Capabilities.Relay) == true
|
|
bitfield.supportsCapability(Capabilities.Store) == true
|
|
bitfield.supportsCapability(Capabilities.Filter) == false
|
|
bitfield.supportsCapability(Capabilities.Lightpush) == false
|
|
bitfield.toCapabilities() == @[Capabilities.Relay, Capabilities.Store]
|
|
|
|
test "get capabilities codecs from record":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
## When
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
builder.withWakuCapabilities(Capabilities.Relay, Capabilities.Store)
|
|
|
|
let recordRes = builder.build()
|
|
|
|
## Then
|
|
assert recordRes.isOk(), $recordRes.error
|
|
let record = recordRes.tryGet()
|
|
|
|
let codecs = record.getCapabilitiesCodecs()
|
|
check:
|
|
codecs.len == 2
|
|
codecs.contains(WakuRelayCodec)
|
|
codecs.contains(WakuStoreCodec)
|
|
|
|
test "check capabilities on a non-waku node record":
|
|
## Given
|
|
# non waku enr, i.e. Ethereum one
|
|
let nonWakuEnr =
|
|
"enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2G" &
|
|
"xb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNl" &
|
|
"Y3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA"
|
|
|
|
## When
|
|
var record: Record
|
|
require waku_enr.fromURI(record, nonWakuEnr)
|
|
|
|
## Then
|
|
let typedRecordRes = record.toTyped()
|
|
require typedRecordRes.isOk()
|
|
|
|
let bitfieldOpt = typedRecordRes.value.waku2
|
|
check bitfieldOpt.isNone()
|
|
|
|
check:
|
|
record.getCapabilities() == []
|
|
record.supportsCapability(Capabilities.Relay) == false
|
|
record.supportsCapability(Capabilities.Store) == false
|
|
record.supportsCapability(Capabilities.Filter) == false
|
|
record.supportsCapability(Capabilities.Lightpush) == false
|
|
|
|
suite "Waku ENR - Multiaddresses":
|
|
test "decode record with multiaddrs field":
|
|
## Given
|
|
let enrUri =
|
|
"enr:-QEMuEAs8JmmyUI3b9v_ADqYtELHUYAsAMS21lA2BMtrzF86tVmyy9cCrhmzfHGH" &
|
|
"x_g3nybn7jIRybzXTGNj3C2KzrriAYJpZIJ2NIJpcISf3_Jeim11bHRpYWRkcnO4XAAr" &
|
|
"NiZzdG9yZS0wMS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1cy5pbQZ2XwAtNiZzdG9y" &
|
|
"ZS0wMS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1cy5pbQYBu94DgnJzjQAQBQABACAA" &
|
|
"QACAAQCJc2VjcDI1NmsxoQLfoaQH3oSYW59yxEBfeAZbltmUnC4BzYkHqer2VQMTyoN0" &
|
|
"Y3CCdl-DdWRwgiMohXdha3UyAw"
|
|
|
|
var record: Record
|
|
require record.fromURI(enrUri)
|
|
|
|
# TODO: get rid of wakuv2 here too. Needt to generate a ne ENR record
|
|
let
|
|
expectedAddr1 = MultiAddress
|
|
.init("/dns4/store-01.do-ams3.status.prod.status.im/tcp/30303")
|
|
.get()
|
|
expectedAddr2 = MultiAddress
|
|
.init("/dns4/store-01.do-ams3.status.prod.status.im/tcp/443/wss")
|
|
.get()
|
|
|
|
## When
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let multiaddrsOpt = typedRecord.value.multiaddrs
|
|
|
|
## Then
|
|
check multiaddrsOpt.isSome()
|
|
let multiaddrs = multiaddrsOpt.get()
|
|
|
|
check:
|
|
multiaddrs.len == 2
|
|
multiaddrs.contains(expectedAddr1)
|
|
multiaddrs.contains(expectedAddr2)
|
|
|
|
test "encode and decode record with multiaddrs field (EnrBuilder ext)":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let
|
|
addr1 = MultiAddress.init("/ip4/127.0.0.1/tcp/80/ws").get()
|
|
addr2 = MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss").get()
|
|
|
|
## When
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
builder.withMultiaddrs(addr1, addr2)
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
let record = recordRes.tryGet()
|
|
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let multiaddrsOpt = typedRecord.value.multiaddrs
|
|
|
|
## Then
|
|
check multiaddrsOpt.isSome()
|
|
|
|
let multiaddrs = multiaddrsOpt.get()
|
|
check:
|
|
multiaddrs.len == 2
|
|
multiaddrs.contains(addr1)
|
|
multiaddrs.contains(addr2)
|
|
|
|
test "cannot decode multiaddresses from record":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let record = EnrBuilder.init(enrPrivKey, enrSeqNum).build().tryGet()
|
|
|
|
## When
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let fieldOpt = typedRecord.value.multiaddrs
|
|
|
|
## Then
|
|
check fieldOpt.isNone()
|
|
|
|
test "encode and decode record with multiaddresses field - strip peer ID":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let
|
|
addr1 = MultiAddress
|
|
.init(
|
|
"/ip4/127.0.0.1/tcp/80/ws/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr31iDQpSN5Qa882BCjjwgrD"
|
|
)
|
|
.get()
|
|
addr2 = MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss").get()
|
|
|
|
let expectedAddr1 = MultiAddress.init("/ip4/127.0.0.1/tcp/80/ws").get()
|
|
|
|
## When
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
builder.withMultiaddrs(addr1, addr2)
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
let record = recordRes.tryGet()
|
|
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let multiaddrsOpt = typedRecord.value.multiaddrs
|
|
|
|
## Then
|
|
check multiaddrsOpt.isSome()
|
|
|
|
let multiaddrs = multiaddrsOpt.get()
|
|
check:
|
|
multiaddrs.contains(expectedAddr1)
|
|
multiaddrs.contains(addr2)
|
|
|
|
suite "Waku ENR - Relay static sharding":
|
|
test "new relay shards object with single invalid shard id":
|
|
## Given
|
|
let
|
|
clusterId: uint16 = 22
|
|
shard: uint16 = 1024
|
|
|
|
## When
|
|
let shardsTopics = RelayShards.init(clusterId, shard)
|
|
|
|
## Then
|
|
assert shardsTopics.isErr(), $shardsTopics.get()
|
|
|
|
test "new relay shards object with single invalid shard id in list":
|
|
## Given
|
|
let
|
|
clusterId: uint16 = 22
|
|
shardIds: seq[uint16] = @[1u16, 1u16, 2u16, 3u16, 5u16, 8u16, 1024u16]
|
|
|
|
## When
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds)
|
|
|
|
## Then
|
|
assert shardsTopics.isErr(), $shardsTopics.get()
|
|
|
|
test "new relay shards object with single valid shard id":
|
|
## Given
|
|
let
|
|
clusterId: uint16 = 22
|
|
shardId: uint16 = 1
|
|
|
|
let shard = RelayShard(clusterId: clusterId, shardId: shardId)
|
|
|
|
## When
|
|
let shardsTopics = RelayShards.init(clusterId, shardId).expect("Valid Shards")
|
|
|
|
## Then
|
|
check:
|
|
shardsTopics.clusterId == clusterId
|
|
shardsTopics.shardIds == @[1u16]
|
|
|
|
let shards = shardsTopics.topics.mapIt($it)
|
|
check:
|
|
shards == @[$shard]
|
|
|
|
check:
|
|
shardsTopics.contains(clusterId, shardId)
|
|
not shardsTopics.contains(clusterId, 33u16)
|
|
not shardsTopics.contains(20u16, 33u16)
|
|
|
|
shardsTopics.contains(shard)
|
|
shardsTopics.contains("/waku/2/rs/22/1")
|
|
|
|
test "new relay shards object with repeated but valid shard ids":
|
|
## Given
|
|
let
|
|
clusterId: uint16 = 22
|
|
shardIds: seq[uint16] = @[1u16, 2u16, 2u16, 3u16, 3u16, 3u16]
|
|
|
|
## When
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid Shards")
|
|
|
|
## Then
|
|
check:
|
|
shardsTopics.clusterId == clusterId
|
|
shardsTopics.shardIds == @[1u16, 2u16, 3u16]
|
|
|
|
test "cannot decode relay shards from record if not present":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let record = EnrBuilder.init(enrPrivKey, enrSeqNum).build().tryGet()
|
|
|
|
## When
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let fieldOpt = typedRecord.value.relaySharding
|
|
|
|
## Then
|
|
check fieldOpt.isNone()
|
|
|
|
test "encode and decode record with relay shards field (EnrBuilder ext - shardIds list)":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let
|
|
clusterId: uint16 = 22
|
|
shardIds: seq[uint16] = @[1u16, 1u16, 2u16, 3u16, 5u16, 8u16]
|
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid Shards")
|
|
|
|
## When
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
|
|
|
let recordRes = builder.build()
|
|
|
|
## Then
|
|
check recordRes.isOk()
|
|
let record = recordRes.tryGet()
|
|
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let shardsOpt = typedRecord.value.relaySharding
|
|
check:
|
|
shardsOpt.isSome()
|
|
shardsOpt.get() == shardsTopics
|
|
|
|
test "encode and decode record with relay shards field (EnrBuilder ext - bit vector)":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let shardsTopics =
|
|
RelayShards.init(33, toSeq(0u16 ..< 64u16)).expect("Valid Shards")
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
|
|
|
let recordRes = builder.build()
|
|
require recordRes.isOk()
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
## When
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let shardsOpt = typedRecord.value.relaySharding
|
|
|
|
## Then
|
|
check:
|
|
shardsOpt.isSome()
|
|
shardsOpt.get() == shardsTopics
|
|
|
|
test "decode record with relay shards shard list and bit vector fields":
|
|
## Given
|
|
let
|
|
enrSeqNum = 1u64
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
let
|
|
relayShardsIndicesList = RelayShards
|
|
.init(22, @[1u16, 1u16, 2u16, 3u16, 5u16, 8u16])
|
|
.expect("Valid Shards")
|
|
relayShardsBitVector = RelayShards
|
|
.init(33, @[13u16, 24u16, 37u16, 61u16, 98u16, 159u16])
|
|
.expect("Valid Shards")
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
require builder.withWakuRelayShardingIndicesList(relayShardsIndicesList).isOk()
|
|
require builder.withWakuRelayShardingBitVector(relayShardsBitVector).isOk()
|
|
|
|
let recordRes = builder.build()
|
|
require recordRes.isOk()
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
## When
|
|
let typedRecord = record.toTyped()
|
|
require typedRecord.isOk()
|
|
|
|
let shardsOpt = typedRecord.value.relaySharding
|
|
|
|
## Then
|
|
check:
|
|
shardsOpt.isSome()
|
|
shardsOpt.get() == relayShardsIndicesList
|