Skip to content

Commit

Permalink
Merge pull request #555 from iotaledger/fix/statediff-crash
Browse files Browse the repository at this point in the history
Add missing return if statediff retrieval returns an error
  • Loading branch information
karimodm authored Nov 27, 2023
2 parents 2585be1 + 4c1d922 commit 35e33cc
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 32 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
34 changes: 23 additions & 11 deletions pkg/blockhandler/blockhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/protocol/engine/mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions tools/docker-network/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -158,7 +158,7 @@ services:

grafana:
image: grafana/grafana:9.5.6
restart: unless-stopped
restart: no
networks:
- iota-core
ports:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis-snapshot/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 35e33cc

Please sign in to comment.