diff --git a/go.mod b/go.mod index b4df94167..e34e522c3 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 c20bbda20..e309abd53 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/pkg/blockhandler/blockhandler.go b/pkg/blockhandler/blockhandler.go index b712bab88..1ca6f13d2 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 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 { 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 diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index 6f312ac5e..0d70f9e37 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 625e4af90..2c7eefdbe 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 cf646a695..168566b47 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 d3873d07e..f6992e0d7 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=