From 4947fcbcde9bdee38813ac1470bde742964b88d8 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 24 Nov 2023 13:10:52 +0100 Subject: [PATCH 1/5] Add missing return if statediff retrieval returns an error --- pkg/protocol/engine/mempool/v1/mempool.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index f1b3abc03..0cd8cfcb4 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -483,6 +483,8 @@ func (m *MemPool[VoteRank]) setupTransaction(transaction *TransactionMetadata) { stateDiff, err := m.stateDiff(slot) if err != nil { m.errorHandler(ierrors.Wrapf(err, "failed to get state diff for slot %d", slot)) + + return } if err := stateDiff.AddTransaction(transaction, m.errorHandler); err != nil { From d13b20109e1313c27b0a0da771f7a1a31fce4f9b Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 24 Nov 2023 12:38:02 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Don=E2=80=99t=20restart=20the=20nodes=20and?= =?UTF-8?q?=20validators=20in=20the=20docker-network=20if=20they=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/docker-network/docker-compose.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/docker-network/docker-compose.yml b/tools/docker-network/docker-compose.yml index c9a17d95c..62b563cbe 100644 --- a/tools/docker-network/docker-compose.yml +++ b/tools/docker-network/docker-compose.yml @@ -12,7 +12,7 @@ services: node-1-validator: build: *iota-core_build stop_grace_period: 1m - restart: unless-stopped + restart: no ulimits: nofile: soft: 16384 @@ -37,7 +37,7 @@ services: node-2-validator: image: docker-network-node-1-validator:latest stop_grace_period: 1m - restart: unless-stopped + restart: no ulimits: nofile: soft: 16384 @@ -62,7 +62,7 @@ services: node-3-validator: image: docker-network-node-1-validator:latest stop_grace_period: 1m - restart: unless-stopped + restart: no ulimits: nofile: soft: 16384 @@ -87,7 +87,7 @@ services: node-4: image: docker-network-node-1-validator:latest stop_grace_period: 1m - restart: unless-stopped + restart: no ulimits: nofile: soft: 16384 @@ -112,7 +112,7 @@ services: node-5: image: docker-network-node-1-validator:latest stop_grace_period: 1m - restart: unless-stopped + restart: no ulimits: nofile: soft: 16384 @@ -141,7 +141,7 @@ services: prometheus: image: prom/prometheus:latest stop_grace_period: 1m - restart: unless-stopped + restart: no depends_on: node-1-validator: condition: service_started @@ -158,7 +158,7 @@ services: grafana: image: grafana/grafana:9.5.6 - restart: unless-stopped + restart: no networks: - iota-core ports: @@ -180,7 +180,7 @@ services: inx-indexer: image: iotaledger/inx-indexer:2.0-alpha stop_grace_period: 1m - restart: unless-stopped + restart: no depends_on: node-1-validator: condition: service_healthy @@ -197,7 +197,7 @@ services: inx-mqtt: image: iotaledger/inx-mqtt:2.0-alpha stop_grace_period: 1m - restart: unless-stopped + restart: no depends_on: node-1-validator: condition: service_healthy @@ -251,7 +251,7 @@ services: inx-validator-1: image: iotaledger/inx-validator:1.0-alpha stop_grace_period: 1m - restart: unless-stopped + restart: no depends_on: node-1-validator: condition: service_started @@ -268,7 +268,7 @@ services: inx-validator-2: image: iotaledger/inx-validator:1.0-alpha stop_grace_period: 1m - restart: unless-stopped + restart: no depends_on: node-2-validator: condition: service_started @@ -284,7 +284,7 @@ services: inx-validator-3: image: iotaledger/inx-validator:1.0-alpha stop_grace_period: 1m - restart: unless-stopped + restart: no depends_on: node-3-validator: condition: service_started From 0e35bf9b72a09e66cb1d46336d3e99f595fc367c Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 24 Nov 2023 14:06:45 +0100 Subject: [PATCH 3/5] Fix memory leak when attaching a block --- pkg/blockhandler/blockhandler.go | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/blockhandler/blockhandler.go b/pkg/blockhandler/blockhandler.go index b712bab88..9aafea085 100644 --- a/pkg/blockhandler/blockhandler.go +++ b/pkg/blockhandler/blockhandler.go @@ -2,8 +2,10 @@ package blockhandler import ( "context" + "time" "github.com/iotaledger/hive.go/ierrors" + "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/runtime/event" "github.com/iotaledger/hive.go/runtime/workerpool" "github.com/iotaledger/iota-core/pkg/model" @@ -24,7 +26,7 @@ var ( // - if the engine name/chain is the same we can always issue a block. // - if the engine name/chain is different we need to make sure to wait "slot ratification" slots. -// BlockIssuer contains logic to create and issue blocks signed by the given account. +// BlockHandler contains the logic to attach blocks to the Tangle and await for it to be processed. type BlockHandler struct { events *Events @@ -58,36 +60,46 @@ func (i *BlockHandler) SubmitBlockAndAwaitEvent(ctx context.Context, block *mode exit := make(chan struct{}) defer close(exit) - defer evt.Hook(func(eventBlock *blocks.Block) { - if block.ID() != eventBlock.ID() { + // Make sure we don't wait forever here. If the block is not dispatched to the main engine, + // it will never trigger one of the below events. + processingCtx, processingCtxCancel := context.WithTimeout(ctx, 5*time.Second) + defer processingCtxCancel() + + // Calculate the blockID so that we don't capture the block pointer in the event handlers. + blockID := block.ID() + + evtUnhook := evt.Hook(func(eventBlock *blocks.Block) { + if blockID != eventBlock.ID() { return } select { case triggered <- nil: case <-exit: } - }, event.WithWorkerPool(i.workerPool)).Unhook() + }, event.WithWorkerPool(i.workerPool)).Unhook - defer i.protocol.Events.Engine.Filter.BlockPreFiltered.Hook(func(event *filter.BlockPreFilteredEvent) { - if block.ID() != event.Block.ID() { + prefilteredUnhook := i.protocol.Events.Engine.Filter.BlockPreFiltered.Hook(func(event *filter.BlockPreFilteredEvent) { + if blockID != event.Block.ID() { return } select { case triggered <- event.Reason: case <-exit: } - }, event.WithWorkerPool(i.workerPool)).Unhook() + }, event.WithWorkerPool(i.workerPool)).Unhook + + defer lo.Batch(evtUnhook, prefilteredUnhook) if err := i.submitBlock(block); err != nil { - return ierrors.Wrapf(err, "failed to issue block %s", block.ID()) + return ierrors.Wrapf(err, "failed to issue block %s", blockID) } select { - case <-ctx.Done(): - return ierrors.Errorf("context canceled whilst waiting for event on block %s", block.ID()) + case <-processingCtx.Done(): + return ierrors.Errorf("context canceled whilst waiting for event on block %s", blockID) case err := <-triggered: if err != nil { - return ierrors.Wrapf(err, "block filtered out %s", block.ID()) + return ierrors.Wrapf(err, "block filtered out %s", blockID) } return nil From 29769616ae5aab992de3008b4441a594be6f73b0 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 24 Nov 2023 14:50:02 +0100 Subject: [PATCH 4/5] Update hive.go with memleak fix in OrderedMap --- go.mod | 2 +- go.sum | 4 ++-- tools/gendoc/go.mod | 2 +- tools/gendoc/go.sum | 4 ++-- tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 966dd83c3..ae4be0fc1 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/iotaledger/hive.go/constraints v0.0.0-20231122112629-bdf1cc39fba7 github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42 github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7 - github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42 + github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7 github.com/iotaledger/hive.go/kvstore v0.0.0-20231110191152-7135670285dc github.com/iotaledger/hive.go/lo v0.0.0-20231122112629-bdf1cc39fba7 diff --git a/go.sum b/go.sum index 853d98815..d8712364b 100644 --- a/go.sum +++ b/go.sum @@ -285,8 +285,8 @@ github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42 h1: github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42/go.mod h1:CdixkrB7VdQzEDlVuwsxPtsiJL/WXrQgz3PELIqlLko= github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7 h1:vLLhxGhipU6AH/paexuRX3zsOvcl8bdYcwJRAchUP8g= github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7/go.mod h1:OQ9EVTTQT1mkO/16BgwSIyQlAhEg+Cptud/yutevWsI= -github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42 h1:QZiMlDxmikF64zimWQunTrsEGOK9ydRahUAz2I46JAk= -github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= +github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff h1:3NlcDKCwmc9K9oOF/dcNGEhKjFVxMBBYUTsgpyS1N5I= +github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7 h1:tf7x4U+ZXnmFXhUmqYtn0kcgpOcGPIhbxR/akpzAU4U= github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= github.com/iotaledger/hive.go/kvstore v0.0.0-20231110191152-7135670285dc h1:3fsqfM2NqfhrewVdlKT3MHcXxVNvUCSP7P32il1ypa0= diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index 33697e170..9ba308ebd 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -61,7 +61,7 @@ require ( github.com/iotaledger/hive.go/constraints v0.0.0-20231122112629-bdf1cc39fba7 // indirect github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42 // indirect github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7 // indirect - github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42 // indirect + github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff // indirect github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7 // indirect github.com/iotaledger/hive.go/kvstore v0.0.0-20231110191152-7135670285dc // indirect github.com/iotaledger/hive.go/lo v0.0.0-20231122112629-bdf1cc39fba7 // indirect diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 8941f11a3..52209eb39 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -289,8 +289,8 @@ github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42 h1: github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42/go.mod h1:CdixkrB7VdQzEDlVuwsxPtsiJL/WXrQgz3PELIqlLko= github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7 h1:vLLhxGhipU6AH/paexuRX3zsOvcl8bdYcwJRAchUP8g= github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7/go.mod h1:OQ9EVTTQT1mkO/16BgwSIyQlAhEg+Cptud/yutevWsI= -github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42 h1:QZiMlDxmikF64zimWQunTrsEGOK9ydRahUAz2I46JAk= -github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= +github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff h1:3NlcDKCwmc9K9oOF/dcNGEhKjFVxMBBYUTsgpyS1N5I= +github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7 h1:tf7x4U+ZXnmFXhUmqYtn0kcgpOcGPIhbxR/akpzAU4U= github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= github.com/iotaledger/hive.go/kvstore v0.0.0-20231110191152-7135670285dc h1:3fsqfM2NqfhrewVdlKT3MHcXxVNvUCSP7P32il1ypa0= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index 89bbe8913..e842757a6 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -29,7 +29,7 @@ require ( github.com/iotaledger/hive.go/ads v0.0.0-20231110191152-7135670285dc // indirect github.com/iotaledger/hive.go/constraints v0.0.0-20231122112629-bdf1cc39fba7 // indirect github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42 // indirect - github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42 // indirect + github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff // indirect github.com/iotaledger/hive.go/kvstore v0.0.0-20231110191152-7135670285dc // indirect github.com/iotaledger/hive.go/log v0.0.0-20231110191152-7135670285dc // indirect github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231113110812-4ca2b6cc9a42 // indirect diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index 23ddfa2f8..41718ac26 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -36,8 +36,8 @@ github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42 h1: github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231113110812-4ca2b6cc9a42/go.mod h1:CdixkrB7VdQzEDlVuwsxPtsiJL/WXrQgz3PELIqlLko= github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7 h1:vLLhxGhipU6AH/paexuRX3zsOvcl8bdYcwJRAchUP8g= github.com/iotaledger/hive.go/crypto v0.0.0-20231122112629-bdf1cc39fba7/go.mod h1:OQ9EVTTQT1mkO/16BgwSIyQlAhEg+Cptud/yutevWsI= -github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42 h1:QZiMlDxmikF64zimWQunTrsEGOK9ydRahUAz2I46JAk= -github.com/iotaledger/hive.go/ds v0.0.0-20231113110812-4ca2b6cc9a42/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= +github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff h1:3NlcDKCwmc9K9oOF/dcNGEhKjFVxMBBYUTsgpyS1N5I= +github.com/iotaledger/hive.go/ds v0.0.0-20231124134854-9ec596cfd9ff/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7 h1:tf7x4U+ZXnmFXhUmqYtn0kcgpOcGPIhbxR/akpzAU4U= github.com/iotaledger/hive.go/ierrors v0.0.0-20231122112629-bdf1cc39fba7/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= github.com/iotaledger/hive.go/kvstore v0.0.0-20231110191152-7135670285dc h1:3fsqfM2NqfhrewVdlKT3MHcXxVNvUCSP7P32il1ypa0= From 4c1d9229cea32eb0ca2f33e4e40e9a8c2226c4ab Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 24 Nov 2023 16:05:12 +0100 Subject: [PATCH 5/5] Fix defer not unhooking the events --- pkg/blockhandler/blockhandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/blockhandler/blockhandler.go b/pkg/blockhandler/blockhandler.go index 9aafea085..1ca6f13d2 100644 --- a/pkg/blockhandler/blockhandler.go +++ b/pkg/blockhandler/blockhandler.go @@ -88,7 +88,7 @@ func (i *BlockHandler) SubmitBlockAndAwaitEvent(ctx context.Context, block *mode } }, event.WithWorkerPool(i.workerPool)).Unhook - defer lo.Batch(evtUnhook, prefilteredUnhook) + defer lo.Batch(evtUnhook, prefilteredUnhook)() if err := i.submitBlock(block); err != nil { return ierrors.Wrapf(err, "failed to issue block %s", blockID)