From b37f7a117201257ef1fc38eddff66857979c822d Mon Sep 17 00:00:00 2001 From: Philipp Gackstatter Date: Wed, 22 May 2024 16:51:45 +0200 Subject: [PATCH 1/9] Add nil payload test --- .../docker-network/tests/nil_payload_test.go | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tools/docker-network/tests/nil_payload_test.go diff --git a/tools/docker-network/tests/nil_payload_test.go b/tools/docker-network/tests/nil_payload_test.go new file mode 100644 index 000000000..eabe17042 --- /dev/null +++ b/tools/docker-network/tests/nil_payload_test.go @@ -0,0 +1,61 @@ +//go:build dockertests + +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/iotaledger/hive.go/lo" + "github.com/iotaledger/iota-core/pkg/testsuite/mock" + "github.com/iotaledger/iota-core/tools/docker-network/tests/dockertestframework" +) + +// Test_AccountTransitions follows the account state transition flow described in: +// 1. Create account-1. +// 2. Create account-2. +// 3. account-1 requests faucet funds then allots 1000 mana to account-2. +// 4. account-2 requests faucet funds then creates native tokens. +func Test_Payload_Nil_Test(t *testing.T) { + d := dockertestframework.NewDockerTestFramework(t, + dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptionsFunc()...), + ) + defer d.Stop() + + d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6") + d.AddValidatorNode("V2", "docker-network-inx-validator-2-1", "http://localhost:8060", "rms1pqm4xk8e9ny5w5rxjkvtp249tfhlwvcshyr3pc0665jvp7g3hc875k538hl") + d.AddValidatorNode("V3", "docker-network-inx-validator-3-1", "http://localhost:8070", "rms1pp4wuuz0y42caz48vv876qfpmffswsvg40zz8v79sy8cp0jfxm4kunflcgt") + d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw") + d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080") + + err := d.Run() + require.NoError(t, err) + + d.WaitUntilNetworkReady() + + ctx, cancel := context.WithCancel(context.Background()) + + // cancel the context when the test is done + t.Cleanup(cancel) + + // create account-1 + accounts := d.CreateAccountsFromFaucet(ctx, 2, "account-1", "account-2") + account1 := accounts[0] + account2 := accounts[1] + + // allot 1000 mana from account-1 to account-2 + fmt.Println("Allotting mana from account-1 to account-2") + d.RequestFaucetFundsAndAllotManaTo(account1.Wallet(), account2.Account(), 1000) + + // create native token + fmt.Println("Creating native token") + d.CreateNativeToken(account1.Wallet(), 5_000_000, 10_000_000_000) + + blk := lo.PanicOnErr(d.DefaultWallet().CreateBasicBlock(ctx, "something", mock.WithPayload(nil))) + d.SubmitBlock(ctx, blk.ProtocolBlock()) + + d.AwaitEpochFinalized() +} From f1f7b8cf06286a7ab7b8ef752c6254bdf60a5730 Mon Sep 17 00:00:00 2001 From: Philipp Gackstatter Date: Wed, 22 May 2024 16:56:40 +0200 Subject: [PATCH 2/9] Update account used in test --- tools/docker-network/tests/nil_payload_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker-network/tests/nil_payload_test.go b/tools/docker-network/tests/nil_payload_test.go index eabe17042..5f0bb2270 100644 --- a/tools/docker-network/tests/nil_payload_test.go +++ b/tools/docker-network/tests/nil_payload_test.go @@ -54,7 +54,7 @@ func Test_Payload_Nil_Test(t *testing.T) { fmt.Println("Creating native token") d.CreateNativeToken(account1.Wallet(), 5_000_000, 10_000_000_000) - blk := lo.PanicOnErr(d.DefaultWallet().CreateBasicBlock(ctx, "something", mock.WithPayload(nil))) + blk := lo.PanicOnErr(account1.Wallet().CreateBasicBlock(ctx, "something", mock.WithPayload(nil))) d.SubmitBlock(ctx, blk.ProtocolBlock()) d.AwaitEpochFinalized() From 52ccb9f209c438e7c9041e68910fb9f679083826 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 22 May 2024 16:36:18 +0200 Subject: [PATCH 3/9] Fix nil selection with empty payload. --- components/restapi/core/node.go | 4 +++- .../sybilprotectionv1/performance/performance.go | 2 +- .../sybilprotection/sybilprotectionv1/sybilprotection.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/restapi/core/node.go b/components/restapi/core/node.go index cbcf39d49..c1ff22019 100644 --- a/components/restapi/core/node.go +++ b/components/restapi/core/node.go @@ -1,6 +1,8 @@ package core -import "github.com/iotaledger/iota.go/v4/api" +import ( + "github.com/iotaledger/iota.go/v4/api" +) func info() *api.InfoResponse { return &api.InfoResponse{ diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go index 5e19ec195..8103e5a7e 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go @@ -104,7 +104,7 @@ func (t *Tracker) TrackCandidateBlock(block *blocks.Block) { t.mutex.Lock() defer t.mutex.Unlock() - if block.Payload().PayloadType() != iotago.PayloadCandidacyAnnouncement { + if payload := block.Payload(); payload == nil || payload.PayloadType() != iotago.PayloadCandidacyAnnouncement { return } diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index 99cabf7f8..03ef4d676 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -113,7 +113,7 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) { return } - if block.Payload().PayloadType() != iotago.PayloadCandidacyAnnouncement { + if payload := block.Payload(); payload == nil || payload.PayloadType() != iotago.PayloadCandidacyAnnouncement { return } From 30f761e06350f98f59216ae58bbd9bf9ba9cd194 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 22 May 2024 17:27:26 +0200 Subject: [PATCH 4/9] Make checks more verbose --- .../sybilprotectionv1/sybilprotection.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index 03ef4d676..d2c8a2e3d 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -113,7 +113,15 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) { return } - if payload := block.Payload(); payload == nil || payload.PayloadType() != iotago.PayloadCandidacyAnnouncement { + if block == nil { + panic("what the fuck") + } + + payload := block.Payload() + if payload == nil { + return + } + if payload.PayloadType() != iotago.PayloadCandidacyAnnouncement { return } From ef8cd72e41d1fd003002297700db011ab964ec8e Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 22 May 2024 17:54:36 +0200 Subject: [PATCH 5/9] Fix building image for Docker tests. --- tools/docker-network/docker-compose.yml | 21 --------------------- tools/docker-network/tests/run_tests.sh | 2 ++ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/tools/docker-network/docker-compose.yml b/tools/docker-network/docker-compose.yml index b07611e53..013d01e94 100644 --- a/tools/docker-network/docker-compose.yml +++ b/tools/docker-network/docker-compose.yml @@ -38,9 +38,6 @@ services: --prometheus.goMetrics=true --prometheus.processMetrics=true --debugAPI.enabled=true - profiles: - - minimal - - full node-2-validator: image: docker-network-node-1-validator:latest @@ -275,9 +272,6 @@ services: --inx.address=node-1-validator:9029 --restAPI.bindAddress=0.0.0.0:9091 --restAPI.advertiseAddress=inx-indexer:9091 - profiles: - - minimal - - full inx-mqtt: image: iotaledger/inx-mqtt:2.0-alpha @@ -291,9 +285,6 @@ services: command: > --inx.address=node-1-validator:9029 --mqtt.websocket.bindAddress=inx-mqtt:1888 - profiles: - - minimal - - full inx-blockissuer: image: iotaledger/inx-blockissuer:1.0-alpha @@ -313,9 +304,6 @@ services: --restAPI.bindAddress=inx-blockissuer:9086 --blockIssuer.accountAddress=rms1prkursay9fs2qjmfctamd6yxg9x8r3ry47786x0mvwek4qr9xd9d5c6gkun --blockIssuer.proofOfWork.targetTrailingZeros=5 - profiles: - - minimal - - full inx-faucet: image: iotaledger/inx-faucet:2.0-alpha @@ -343,9 +331,6 @@ services: --faucet.baseTokenAmountMaxTarget=5000000000 --faucet.manaAmount=100000000 --faucet.manaAmountMinFaucet=1000000000 - profiles: - - minimal - - full inx-validator-1: image: iotaledger/inx-validator:1.0-alpha @@ -365,9 +350,6 @@ services: --validator.accountAddress=rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6 --validator.candidacyRetryInterval=${CANDIDACY_RETRY_INTERVAL:-10s} --validator.issueCandidacyPayload=${ISSUE_CANDIDACY_PAYLOAD_V1:-true} - profiles: - - minimal - - full inx-validator-2: image: iotaledger/inx-validator:1.0-alpha @@ -447,9 +429,6 @@ services: - "--dashboard.auth.username=${DASHBOARD_USERNAME:-admin}" - "--dashboard.auth.passwordHash=${DASHBOARD_PASSWORD:-0000000000000000000000000000000000000000000000000000000000000000}" - "--dashboard.auth.passwordSalt=${DASHBOARD_SALT:-0000000000000000000000000000000000000000000000000000000000000000}" - profiles: - - minimal - - full inx-dashboard-2: container_name: inx-dashboard-2 diff --git a/tools/docker-network/tests/run_tests.sh b/tools/docker-network/tests/run_tests.sh index d614ab092..8bbe53ba8 100755 --- a/tools/docker-network/tests/run_tests.sh +++ b/tools/docker-network/tests/run_tests.sh @@ -20,6 +20,8 @@ mkdir -p docker-network-snapshots/ # Allow 'others' to write, so a snapshot can be created via the management API from within docker containers. chmod o+w docker-network-snapshots/ +export COMPOSE_PROFILES="full" + # Allow docker compose to build and cache an image docker compose build --build-arg DOCKER_BUILD_CONTEXT=${DOCKER_BUILD_CONTEXT} --build-arg DOCKERFILE_PATH=${DOCKERFILE_PATH} From b2d13ad4671835dd42fef74baad33dd7a09a9038 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 22 May 2024 17:54:53 +0200 Subject: [PATCH 6/9] Revert verbosity changes. --- .../sybilprotectionv1/sybilprotection.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index d2c8a2e3d..03ef4d676 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -113,15 +113,7 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) { return } - if block == nil { - panic("what the fuck") - } - - payload := block.Payload() - if payload == nil { - return - } - if payload.PayloadType() != iotago.PayloadCandidacyAnnouncement { + if payload := block.Payload(); payload == nil || payload.PayloadType() != iotago.PayloadCandidacyAnnouncement { return } From 9d73fe5426ccfeb2a5a354fa7b16161ae499663b Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 22 May 2024 17:57:58 +0200 Subject: [PATCH 7/9] Remove unnecessary profiles. --- tools/docker-network/run.sh | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index cc3051aaf..02cab58b4 100755 --- a/tools/docker-network/run.sh +++ b/tools/docker-network/run.sh @@ -1,31 +1,34 @@ #!/bin/bash # Create a function to join an array of strings by a given character -function join { local IFS="$1"; shift; echo "$*"; } +function join { + local IFS="$1" + shift + echo "$*" +} # Initialize variables MONITORING=0 MINIMAL=0 # Loop over all arguments -for arg in "$@" -do - case $arg in - monitoring=*) - MONITORING="${arg#*=}" - shift - ;; - minimal=*) - MINIMAL="${arg#*=}" - shift - ;; - *) - # Unknown option - echo "Unknown argument: $arg" - echo 'Call with ./run.sh [monitoring=0|1] [minimal=0|1]' - exit 1 - ;; - esac +for arg in "$@"; do + case $arg in + monitoring=*) + MONITORING="${arg#*=}" + shift + ;; + minimal=*) + MINIMAL="${arg#*=}" + shift + ;; + *) + # Unknown option + echo "Unknown argument: $arg" + echo 'Call with ./run.sh [monitoring=0|1] [minimal=0|1]' + exit 1 + ;; + esac done export DOCKER_BUILDKIT=1 @@ -94,7 +97,6 @@ if [ $MONITORING -ne 0 ]; then fi if [ $MINIMAL -ne 0 ]; then - PROFILES+=("minimal") echo "Minimal profile active" else PROFILES+=("full") @@ -102,6 +104,8 @@ else fi export COMPOSE_PROFILES=$(join , ${PROFILES[@]}) +echo $COMPOSE_PROFILES + docker compose up echo "Clean up docker resources" From 7dd62f4cc6dc6b3857f47e0b500250fa7e3e1dcc Mon Sep 17 00:00:00 2001 From: Philipp Gackstatter Date: Wed, 22 May 2024 18:05:37 +0200 Subject: [PATCH 8/9] Fix nil nil lint --- pkg/testsuite/snapshotcreator/snapshotcreator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/testsuite/snapshotcreator/snapshotcreator.go b/pkg/testsuite/snapshotcreator/snapshotcreator.go index a7926cd55..8b608c12b 100644 --- a/pkg/testsuite/snapshotcreator/snapshotcreator.go +++ b/pkg/testsuite/snapshotcreator/snapshotcreator.go @@ -216,6 +216,7 @@ func createGenesisOutput(api iotago.API, genesisTokenAmount iotago.BaseToken, ge return output, nil } + //nolint:nilnil // we want to return nil here return nil, nil } From 32da493bfad4e5143e18467ed40ced8c1558fb1b Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 22 May 2024 18:09:03 +0200 Subject: [PATCH 9/9] Update tools/docker-network/run.sh --- tools/docker-network/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index 02cab58b4..54153c5b4 100755 --- a/tools/docker-network/run.sh +++ b/tools/docker-network/run.sh @@ -104,7 +104,6 @@ else fi export COMPOSE_PROFILES=$(join , ${PROFILES[@]}) -echo $COMPOSE_PROFILES docker compose up