From 294d06323c221098fbcb138a1750e017c324079f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex?= Date: Thu, 31 Oct 2024 18:23:24 +0100 Subject: [PATCH 1/2] docs(test): handle IHAVE / IWANT tests (#1202) Add documentation as requested. --- tests/pubsub/testgossipinternal.nim | 77 ++++++++++++++++++----------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 777b47978..2352fc6f7 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -677,55 +677,76 @@ suite "GossipSub internal": gossipSub.mesh[topic] = initHashSet[PubSubPeer]() gossipSub.subscribe(topic, handler2) + # Instantiates 30 peers and connects all of them to the previously defined `gossipSub` for i in 0 ..< 30: + # Define a new connection let conn = TestBufferStream.new(noop) conns &= conn let peerId = randomPeerId() conn.peerId = peerId let peer = gossipSub.getPubSubPeer(peerId) peer.handler = handler + # Add the connection to `gossipSub`, to their `gossipSub.gossipsub` and `gossipSub.mesh` tables gossipSub.grafted(peer, topic) gossipSub.mesh[topic].incl(peer) + # Peers with no budget should not request messages block: - # should ignore no budget peer - let conn = TestBufferStream.new(noop) - conns &= conn - let peerId = randomPeerId() - conn.peerId = peerId - let peer = gossipSub.getPubSubPeer(peerId) - let id = @[0'u8, 1, 2, 3] - let msg = ControlIHave(topicID: topic, messageIDs: @[id, id, id]) - peer.iHaveBudget = 0 - let iwants = gossipSub.handleIHave(peer, @[msg]) - check: - iwants.messageIDs.len == 0 - - block: - # given duplicate ihave should generate only one iwant - let conn = TestBufferStream.new(noop) - conns &= conn - let peerId = randomPeerId() - conn.peerId = peerId - let peer = gossipSub.getPubSubPeer(peerId) - let id = @[0'u8, 1, 2, 3] - let msg = ControlIHave(topicID: topic, messageIDs: @[id, id, id]) - let iwants = gossipSub.handleIHave(peer, @[msg]) - check: - iwants.messageIDs.len == 1 - - block: - # given duplicate iwant should generate only one message + # Define a new connection let conn = TestBufferStream.new(noop) conns &= conn let peerId = randomPeerId() conn.peerId = peerId let peer = gossipSub.getPubSubPeer(peerId) + # Add message to `gossipSub`'s message cache let id = @[0'u8, 1, 2, 3] gossipSub.mcache.put(id, Message()) peer.sentIHaves[^1].incl(id) + # Build an IHAVE message that contains the same message ID three times + let msg = ControlIHave(topicID: topic, messageIDs: @[id, id, id]) + # Given the peer has no budget to request messages + peer.iHaveBudget = 0 + # When a peer makes an IHAVE request for the a message that `gossipSub` has + let iwants = gossipSub.handleIHave(peer, @[msg]) + # Then `gossipSub` should not generate an IWant message for the message, + check: + iwants.messageIDs.len == 0 + + # Peers with budget should request messages. If ids are repeated, only one request should be generated + block: + # Define a new connection + let conn = TestBufferStream.new(noop) + conns &= conn + let peerId = randomPeerId() + conn.peerId = peerId + let peer = gossipSub.getPubSubPeer(peerId) + let id = @[0'u8, 1, 2, 3] + # Build an IHAVE message that contains the same message ID three times + let msg = ControlIHave(topicID: topic, messageIDs: @[id, id, id]) + # Given the budget is not 0 (because it's not been overridden) + # When a peer makes an IHAVE request for the a message that `gossipSub` does not have + let iwants = gossipSub.handleIHave(peer, @[msg]) + # Then `gossipSub` should generate an IWant message for the message + check: + iwants.messageIDs.len == 1 + + # Peers with budget should request messages. If ids are repeated, only one request should be generated + block: + # Define a new connection + let conn = TestBufferStream.new(noop) + conns &= conn + let peerId = randomPeerId() + conn.peerId = peerId + let peer = gossipSub.getPubSubPeer(peerId) + # Add message to `gossipSub`'s message cache + let id = @[0'u8, 1, 2, 3] + gossipSub.mcache.put(id, Message()) + peer.sentIHaves[^1].incl(id) + # Build an IWANT message that contains the same message ID three times let msg = ControlIWant(messageIDs: @[id, id, id]) + # When a peer makes an IWANT request for the a message that `gossipSub` has let genmsg = gossipSub.handleIWant(peer, @[msg]) + # Then `gossipSub` should return the message check: genmsg.len == 1 From 97192a3c801c94c82acdf18130c82fb0a360af1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex?= Date: Thu, 31 Oct 2024 18:56:13 +0100 Subject: [PATCH 2/2] fix(ci): nim 2.0 dependency failure (#1216) Broken due to an update to Nimble 0.16.2 for the version-2-0 branch. This PR sets the ref to the previous commit. Also, updates the key naming so it fits better. Nim's commit list: https://github.com/nim-lang/Nim/commits/version-2-0/ # Important Note In this PR some required job's names were changed. They need to be updated at repo-level so this PR can be merged. --- .github/actions/install_nim/action.yml | 6 +++--- .github/workflows/ci.yml | 18 +++++++++++------- .github/workflows/daily_amd64.yml | 2 +- .github/workflows/daily_common.yml | 6 +++--- .github/workflows/daily_devel.yml | 2 +- .github/workflows/daily_i386.yml | 2 +- .github/workflows/daily_sat.yml | 2 +- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/actions/install_nim/action.yml b/.github/actions/install_nim/action.yml index 83de4f313..96bdcec2a 100644 --- a/.github/actions/install_nim/action.yml +++ b/.github/actions/install_nim/action.yml @@ -6,7 +6,7 @@ inputs: cpu: description: "CPU to build for" default: "amd64" - nim_branch: + nim_ref: description: "Nim version" default: "version-1-6" shell: @@ -117,7 +117,7 @@ runs: uses: actions/cache@v4 with: path: '${{ github.workspace }}/nim' - key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_branch }}-cache-${{ env.cache_nonce }} + key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_ref }}-cache-${{ env.cache_nonce }} - name: Build Nim and Nimble shell: ${{ inputs.shell }} @@ -126,6 +126,6 @@ runs: # We don't want partial matches of the cache restored rm -rf nim curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh - env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ inputs.nim_branch }} \ + env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ inputs.nim_ref }} \ QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \ bash build_nim.sh nim csources dist/nimble NimBinaries diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3187c5502..bb71b236b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,10 +29,13 @@ jobs: cpu: amd64 - os: windows cpu: amd64 - nim: - - branch: version-1-6 + nim: + - ref: version-1-6 memory_management: refc - - branch: version-2-0 + # The ref below corresponds to the branch "version-2-0". + # Right before an update from Nimble 0.16.1 to 0.16.2. + # That update breaks our dependency resolution. + - ref: 8754469f4947844c5938f56e1fba846c349354b5 memory_management: refc include: - platform: @@ -56,7 +59,7 @@ jobs: run: shell: ${{ matrix.shell }} - name: '${{ matrix.platform.os }}-${{ matrix.platform.cpu }} (Nim ${{ matrix.nim.branch }})' + name: '${{ matrix.platform.os }}-${{ matrix.platform.cpu }} (Nim ${{ matrix.nim.ref }})' runs-on: ${{ matrix.builder }} steps: - name: Checkout @@ -70,7 +73,7 @@ jobs: os: ${{ matrix.platform.os }} cpu: ${{ matrix.platform.cpu }} shell: ${{ matrix.shell }} - nim_branch: ${{ matrix.nim.branch }} + nim_ref: ${{ matrix.nim.ref }} - name: Setup Go uses: actions/setup-go@v5 @@ -86,9 +89,9 @@ jobs: uses: actions/cache@v3 with: path: nimbledeps - # Using nim.branch as a simple way to differentiate between nimble using the "pkgs" or "pkgs2" directories. + # Using nim.ref as a simple way to differentiate between nimble using the "pkgs" or "pkgs2" directories. # The change happened on Nimble v0.14.0. - key: nimbledeps-${{ matrix.nim.branch }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows + key: nimbledeps-${{ matrix.nim.ref }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows - name: Install deps if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }} @@ -109,5 +112,6 @@ jobs: nim --version nimble --version gcc --version + NIMFLAGS="${NIMFLAGS} --mm:${{ matrix.nim.memory_management }}" nimble test diff --git a/.github/workflows/daily_amd64.yml b/.github/workflows/daily_amd64.yml index d1fc560bd..7e2e76570 100644 --- a/.github/workflows/daily_amd64.yml +++ b/.github/workflows/daily_amd64.yml @@ -10,5 +10,5 @@ jobs: name: Daily amd64 uses: ./.github/workflows/daily_common.yml with: - nim: "[{'branch': 'version-1-6', 'memory_management': 'refc'}, {'branch': 'version-2-0', 'memory_management': 'refc'}]" + nim: "[{'ref': 'version-1-6', 'memory_management': 'refc'}, {'ref': '8754469f4947844c5938f56e1fba846c349354b5', 'memory_management': 'refc'}]" cpu: "['amd64']" diff --git a/.github/workflows/daily_common.yml b/.github/workflows/daily_common.yml index a5ae19c5a..687dd4af1 100644 --- a/.github/workflows/daily_common.yml +++ b/.github/workflows/daily_common.yml @@ -7,7 +7,7 @@ on: nim: description: 'Nim Configuration' required: true - type: string # Following this format: [{"branch": ..., "memory_management": ...}, ...] + type: string # Following this format: [{"ref": ..., "memory_management": ...}, ...] cpu: description: 'CPU' required: true @@ -58,7 +58,7 @@ jobs: run: shell: ${{ matrix.platform.shell }} - name: '${{ matrix.platform.os }}-${{ matrix.cpu }} (Nim ${{ matrix.nim.branch }})' + name: '${{ matrix.platform.os }}-${{ matrix.cpu }} (Nim ${{ matrix.nim.ref }})' runs-on: ${{ matrix.platform.builder }} steps: - name: Checkout @@ -69,7 +69,7 @@ jobs: with: os: ${{ matrix.platform.os }} shell: ${{ matrix.platform.shell }} - nim_branch: ${{ matrix.nim.branch }} + nim_ref: ${{ matrix.nim.ref }} cpu: ${{ matrix.cpu }} - name: Setup Go diff --git a/.github/workflows/daily_devel.yml b/.github/workflows/daily_devel.yml index d2481f43b..ca31349f9 100644 --- a/.github/workflows/daily_devel.yml +++ b/.github/workflows/daily_devel.yml @@ -10,5 +10,5 @@ jobs: name: Daily Nim Devel uses: ./.github/workflows/daily_common.yml with: - nim: "[{'branch': 'devel', 'memory_management': 'orc'}]" + nim: "[{'ref': 'devel', 'memory_management': 'orc'}]" cpu: "['amd64']" diff --git a/.github/workflows/daily_i386.yml b/.github/workflows/daily_i386.yml index cdbec7f95..f6adf490b 100644 --- a/.github/workflows/daily_i386.yml +++ b/.github/workflows/daily_i386.yml @@ -10,6 +10,6 @@ jobs: name: Daily i386 (Linux) uses: ./.github/workflows/daily_common.yml with: - nim: "[{'branch': 'version-1-6', 'memory_management': 'refc'}, {'branch': 'version-2-0', 'memory_management': 'refc'}, {'branch': 'devel', 'memory_management': 'orc'}]" + nim: "[{'ref': 'version-1-6', 'memory_management': 'refc'}, {'ref': '8754469f4947844c5938f56e1fba846c349354b5', 'memory_management': 'refc'}, {'ref': 'devel', 'memory_management': 'orc'}]" cpu: "['i386']" exclude: "[{'platform': {'os':'macos'}}, {'platform': {'os':'windows'}}]" diff --git a/.github/workflows/daily_sat.yml b/.github/workflows/daily_sat.yml index f9bb9d7ff..a3bcc14a5 100644 --- a/.github/workflows/daily_sat.yml +++ b/.github/workflows/daily_sat.yml @@ -10,6 +10,6 @@ jobs: name: Daily SAT uses: ./.github/workflows/daily_common.yml with: - nim: "[{'branch': 'version-2-0', 'memory_management': 'refc'}]" + nim: "[{'ref': '8754469f4947844c5938f56e1fba846c349354b5', 'memory_management': 'refc'}]" cpu: "['amd64']" use_sat_solver: true