Skip to content

Commit

Permalink
Merge pull request #543 from iotaledger/feat/block-monotonicity
Browse files Browse the repository at this point in the history
 Block time monotonicity check in filter
  • Loading branch information
karimodm authored Nov 28, 2023
2 parents 0a0c1ba + 0e23c70 commit 1f95534
Show file tree
Hide file tree
Showing 29 changed files with 464 additions and 368 deletions.
24 changes: 12 additions & 12 deletions components/protocol/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol"
"github.com/iotaledger/iota-core/pkg/protocol/engine/attestation/slotattestation"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/protocol/engine/commitmentfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/blockfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/postsolidfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/presolidfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/presolidfilter/presolidblockfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/mempool"
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization"
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization/slotnotarization"
Expand Down Expand Up @@ -163,9 +163,9 @@ func provide(c *dig.Container) error {
protocol.WithAttestationProvider(
slotattestation.NewProvider(),
),
protocol.WithFilterProvider(
blockfilter.NewProvider(
blockfilter.WithMaxAllowedWallClockDrift(ParamsProtocol.Filter.MaxAllowedClockDrift),
protocol.WithPreSolidFilterProvider(
presolidblockfilter.NewProvider(
presolidblockfilter.WithMaxAllowedWallClockDrift(ParamsProtocol.Filter.MaxAllowedClockDrift),
),
),
protocol.WithUpgradeOrchestratorProvider(
Expand Down Expand Up @@ -196,20 +196,20 @@ func configure() error {
Component.LogDebugf("AcceptedBlockProcessed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.Filter.BlockPreFiltered.Hook(func(event *filter.BlockPreFilteredEvent) {
deps.Protocol.Events.Engine.PreSolidFilter.BlockPreFiltered.Hook(func(event *presolidfilter.BlockPreFilteredEvent) {
Component.LogDebugf("BlockPreFiltered, blockID: %s, reason: %s", event.Block.ID(), event.Reason.Error())
})

deps.Protocol.Events.Engine.Filter.BlockPreAllowed.Hook(func(block *model.Block) {
deps.Protocol.Events.Engine.PreSolidFilter.BlockPreAllowed.Hook(func(block *model.Block) {
Component.LogDebugf("BlockPreAllowed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.CommitmentFilter.BlockAllowed.Hook(func(block *blocks.Block) {
Component.LogDebugf("CommitmentFilter.BlockAllowed, blockID: %s", block.ID())
deps.Protocol.Events.Engine.PostSolidFilter.BlockAllowed.Hook(func(block *blocks.Block) {
Component.LogDebugf("PostSolidFilter.BlockAllowed, blockID: %s", block.ID())
})

deps.Protocol.Events.Engine.CommitmentFilter.BlockFiltered.Hook(func(event *commitmentfilter.BlockFilteredEvent) {
Component.LogWarnf("CommitmentFilter.BlockFiltered, blockID: %s, reason: %s", event.Block.ID(), event.Reason.Error())
deps.Protocol.Events.Engine.PostSolidFilter.BlockFiltered.Hook(func(event *postsolidfilter.BlockFilteredEvent) {
Component.LogWarnf("PostSolidFilter.BlockFiltered, blockID: %s, reason: %s", event.Block.ID(), event.Reason.Error())
})

deps.Protocol.Events.Engine.TipManager.BlockAdded.Hook(func(tip tipmanager.TipMetadata) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/blockhandler/blockhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/protocol"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/presolidfilter"
iotago "github.com/iotaledger/iota.go/v4"
)

Expand Down Expand Up @@ -78,7 +78,7 @@ func (i *BlockHandler) SubmitBlockAndAwaitEvent(ctx context.Context, block *mode
}
}, event.WithWorkerPool(i.workerPool)).Unhook

prefilteredUnhook := i.protocol.Events.Engine.Filter.BlockPreFiltered.Hook(func(event *filter.BlockPreFilteredEvent) {
prefilteredUnhook := i.protocol.Events.Engine.PreSolidFilter.BlockPreFiltered.Hook(func(event *presolidfilter.BlockPreFilteredEvent) {
if blockID != event.Block.ID() {
return
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewProvider(opts ...options.Option[BlockDAG]) module.Provider[*engine.Engin
e.HookConstructed(func() {
wp := b.workers.CreatePool("BlockDAG.Attach", workerpool.WithWorkerCount(2))

e.Events.Filter.BlockPreAllowed.Hook(func(block *model.Block) {
e.Events.PreSolidFilter.BlockPreAllowed.Hook(func(block *model.Block) {
if _, _, err := b.Attach(block); err != nil {
b.errorHandler(ierrors.Wrapf(err, "failed to attach block with %s (issuerID: %s)", block.ID(), block.ProtocolBlock().Header.IssuerID))
}
Expand Down Expand Up @@ -203,8 +203,11 @@ func (b *BlockDAG) shouldAttach(data *model.Block) (shouldAttach bool, err error
}

// We already attached it before, but the parents are invalid, then we set the block as invalid.
if parentsValid, err := b.canAttachToParents(data); !parentsValid && storedBlock != nil {
storedBlock.SetInvalid()
if parentsValid, err := b.canAttachToParents(data); !parentsValid {
if storedBlock != nil {
storedBlock.SetInvalid()
}

return false, err
}

Expand Down

This file was deleted.

26 changes: 13 additions & 13 deletions pkg/protocol/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/protocol/engine/booker"
"github.com/iotaledger/iota-core/pkg/protocol/engine/clock"
"github.com/iotaledger/iota-core/pkg/protocol/engine/commitmentfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/congestioncontrol/scheduler"
"github.com/iotaledger/iota-core/pkg/protocol/engine/consensus/blockgadget"
"github.com/iotaledger/iota-core/pkg/protocol/engine/consensus/slotgadget"
"github.com/iotaledger/iota-core/pkg/protocol/engine/eviction"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/postsolidfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/filter/presolidfilter"
"github.com/iotaledger/iota-core/pkg/protocol/engine/ledger"
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization"
"github.com/iotaledger/iota-core/pkg/protocol/engine/syncmanager"
Expand All @@ -47,8 +47,8 @@ import (
type Engine struct {
Events *Events
Storage *storage.Storage
Filter filter.Filter
CommitmentFilter commitmentfilter.CommitmentFilter
PreSolidFilter presolidfilter.PreSolidFilter
PostSolidFilter postsolidfilter.PostSolidFilter
EvictionState *eviction.State
BlockRequester *eventticker.EventTicker[iotago.SlotIndex, iotago.BlockID]
BlockDAG blockdag.BlockDAG
Expand Down Expand Up @@ -89,8 +89,8 @@ func New(
workers *workerpool.Group,
errorHandler func(error),
storageInstance *storage.Storage,
filterProvider module.Provider[*Engine, filter.Filter],
commitmentFilterProvider module.Provider[*Engine, commitmentfilter.CommitmentFilter],
preSolidFilterProvider module.Provider[*Engine, presolidfilter.PreSolidFilter],
postSolidFilterProvider module.Provider[*Engine, postsolidfilter.PostSolidFilter],
blockDAGProvider module.Provider[*Engine, blockdag.BlockDAG],
bookerProvider module.Provider[*Engine, booker.Booker],
clockProvider module.Provider[*Engine, clock.Clock],
Expand Down Expand Up @@ -143,8 +143,8 @@ func New(
e.BlockRequester = eventticker.New(e.optsBlockRequester...)
e.SybilProtection = sybilProtectionProvider(e)
e.BlockDAG = blockDAGProvider(e)
e.Filter = filterProvider(e)
e.CommitmentFilter = commitmentFilterProvider(e)
e.PreSolidFilter = preSolidFilterProvider(e)
e.PostSolidFilter = postSolidFilterProvider(e)
e.Booker = bookerProvider(e)
e.Clock = clockProvider(e)
e.BlockGadget = blockGadgetProvider(e)
Expand Down Expand Up @@ -220,7 +220,7 @@ func New(
}

func (e *Engine) ProcessBlockFromPeer(block *model.Block, source peer.ID) {
e.Filter.ProcessReceivedBlock(block, source)
e.PreSolidFilter.ProcessReceivedBlock(block, source)
e.Events.BlockProcessed.Trigger(block.ID())
}

Expand All @@ -246,9 +246,9 @@ func (e *Engine) Reset() {
e.SybilProtection.Reset()
e.Booker.Reset()
e.Ledger.Reset()
e.CommitmentFilter.Reset()
e.PostSolidFilter.Reset()
e.BlockDAG.Reset()
e.Filter.Reset()
e.PreSolidFilter.Reset()
e.Retainer.Reset()
e.EvictionState.Reset()
e.BlockCache.Reset()
Expand Down Expand Up @@ -279,9 +279,9 @@ func (e *Engine) Shutdown() {
e.SybilProtection.Shutdown()
e.Booker.Shutdown()
e.Ledger.Shutdown()
e.CommitmentFilter.Shutdown()
e.PostSolidFilter.Shutdown()
e.BlockDAG.Shutdown()
e.Filter.Shutdown()
e.PreSolidFilter.Shutdown()
e.Retainer.Shutdown()
e.Workers.Shutdown()
e.Storage.Shutdown()
Expand Down
Loading

0 comments on commit 1f95534

Please sign in to comment.