Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: WarpSync #568

Merged
merged 65 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b6878f4
Fix: Fix WarpSync
hmoog Nov 27, 2023
0539f34
Feat: added more logic
hmoog Nov 27, 2023
e82a4be
Fix: fixed more code
hmoog Nov 27, 2023
ab3fdec
Trigger Commitment's IsCommittable at - MCA + 1
karimodm Nov 27, 2023
66807e0
Deadlock fix
karimodm Nov 27, 2023
18ab2ef
Merge branch 'feat/reactive-chainmanager' into fix/warpSync
karimodm Nov 28, 2023
000355b
Force accept and commit with MCA delay
karimodm Nov 28, 2023
58a9972
Add rootblocks only before force-accepting them
karimodm Nov 28, 2023
d1cfa46
Merge remote-tracking branch 'origin/feat/reactive-chainmanager' into…
karimodm Nov 28, 2023
9e9697c
Reset the Engine when WarpSyncMode turns true
karimodm Nov 28, 2023
4338642
Merge branch 'feat/reactive-chainmanager' of github.com:iotaledger/io…
hmoog Nov 28, 2023
51431c7
Fix: TestLossOfAcceptanceFromGenesis test fixed
hmoog Nov 28, 2023
ef9927b
Merge branch 'feat/reactive-chainmanager' of github.com:iotaledger/io…
hmoog Nov 29, 2023
b4d6346
Feat: increased timeout
hmoog Nov 29, 2023
e1bfcdf
Feat: extend waiting time?
hmoog Nov 29, 2023
1e4b2f2
Feat: Added PR for bundled changes while debugging
hmoog Nov 29, 2023
a467a26
Feat: added more logs
hmoog Nov 29, 2023
ed38887
Feat: added log output
hmoog Nov 29, 2023
0db2bf0
Feat: changed some code
hmoog Nov 30, 2023
13cd73a
Feat: added log
hmoog Nov 30, 2023
8f60e3d
Feat: add logging
hmoog Nov 30, 2023
a524987
Feat: added logging
hmoog Nov 30, 2023
ff87a2e
Feat: added solidity stuff to the logging - let's see
hmoog Nov 30, 2023
8b97187
Feat: add logging
hmoog Nov 30, 2023
7b8abd6
Merge branch 'feat/reactive-chainmanager' of github.com:iotaledger/io…
hmoog Nov 30, 2023
aa6642e
Change warp sync to wait for WeightPropagated instead of Booked of bl…
jonastheis Dec 1, 2023
bb338af
Adjust TestProtocol_EngineSwitching_CommitteeRotation to wait for the…
jonastheis Dec 1, 2023
aeb9258
Fix calculation of WarpSyncThreshold
jonastheis Dec 1, 2023
62a9cb4
WarpSyncMode should be enabled if latestProducedCommitment == nil
jonastheis Dec 1, 2023
7243706
Feat: fixed some stuff
hmoog Dec 1, 2023
66e843a
Merge branch 'fix/warpSync' of github.com:iotaledger/iota-core into d…
hmoog Dec 1, 2023
32ebf8b
Fix: fixed tests
hmoog Dec 1, 2023
b3049b5
Refactor: reverted changes
hmoog Dec 1, 2023
9c845ec
Refactor: reverted more changes
hmoog Dec 1, 2023
1e8e9dd
Refactor: reverted more changes
hmoog Dec 1, 2023
52694be
Fix: fixed bugs and refactored code
hmoog Dec 1, 2023
8ad929b
Refactor: refactored warpsync to be able to handle loss of acceptance
hmoog Dec 3, 2023
89f0213
Refactor: fixed typo + race condition
hmoog Dec 3, 2023
af324c3
Fix bugs in WarpSync logic (#577)
hmoog Dec 3, 2023
6eae1b4
Refactor: started reverting unnecessary changes
hmoog Dec 3, 2023
14f7108
Merge branch 'fix/warpSync' of github.com:iotaledger/iota-core into d…
hmoog Dec 3, 2023
7675908
Refactor: reverted changes
hmoog Dec 3, 2023
8a2a19e
Refactor: reverted rename
hmoog Dec 3, 2023
aa420c9
Refactor: addressed linter issues
hmoog Dec 3, 2023
dd8771a
Refactor: reduced changes
hmoog Dec 3, 2023
044b797
Refactor: reverted unnecessary changes
hmoog Dec 3, 2023
010e103
Refactor: reverted more changes
hmoog Dec 3, 2023
a3a5c72
Refactor: minimizing more changes
hmoog Dec 3, 2023
0ce46e7
Refactor: reverted more code
hmoog Dec 3, 2023
b6b430f
Refactor: revert
hmoog Dec 3, 2023
5beda14
Refactor: revert
hmoog Dec 3, 2023
2b819f9
Refactor: reverted more
hmoog Dec 3, 2023
75240f0
Refactor: revert
hmoog Dec 3, 2023
e83a78e
Fix: fix possible nil pointer exception
hmoog Dec 3, 2023
90c1fd3
Refactor: renamed flags
hmoog Dec 4, 2023
8b5b5dc
Refactor: finished rename
hmoog Dec 4, 2023
5241622
Refactor: refactored warpsync protocol
hmoog Dec 4, 2023
c6a7242
Feat: updated comments
hmoog Dec 4, 2023
5fb3535
Refactor: updated comments
hmoog Dec 4, 2023
bfe40ba
Merge remote-tracking branch 'origin/feat/reactive-chainmanager' into…
jonastheis Dec 4, 2023
6044a6d
Merge branch 'feat/reactive-chainmanager' into fix/warpSync
karimodm Dec 4, 2023
9576fd6
Do not mark blocks as root blocks when warp syncing as that is done a…
jonastheis Dec 4, 2023
d8d6430
Address review comments
jonastheis Dec 4, 2023
1419993
Merge branch 'fix/warpSync' of github.com:iotaledger/iota-core into f…
jonastheis Dec 4, 2023
ac6a993
Fix deadlock
jonastheis Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (c *Chain) addCommitment(newCommitment *Commitment) (shutdown func()) {

return lo.Batch(
newCommitment.IsAttested.OnTrigger(func() { c.LatestAttestedCommitment.Set(newCommitment) }),
newCommitment.IsVerified.OnTrigger(func() { c.LatestProducedCommitment.Set(newCommitment) }),
newCommitment.IsCommitted.OnTrigger(func() { c.LatestProducedCommitment.Set(newCommitment) }),
)
}

Expand Down
40 changes: 26 additions & 14 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ type Commitment struct {
// IsAttested contains a flag indicating if we have received attestations for this Commitment.
IsAttested reactive.Event

// IsVerified contains a flag indicating if this Commitment is verified (we produced this Commitment ourselves by
// booking all the contained blocks and transactions).
IsVerified reactive.Event
// IsFullyBooked contains a flag indicating if we have received all blocks for this Commitment.
IsFullyBooked reactive.Event

// IsCommittable contains a flag indicating if this Commitment is committable (we have received all blocks and all attestations).
IsCommittable reactive.Event

// IsCommitted contains a flag indicating if we Commitment produced this Commitment ourselves by replaying all the
// blocks of the Commitment.
IsCommitted reactive.Event

// IsAboveLatestVerifiedCommitment contains a flag indicating if this Commitment is above the latest verified
// Commitment.
Expand Down Expand Up @@ -94,7 +100,9 @@ func newCommitment(commitments *Commitments, model *model.Commitment) *Commitmen
CumulativeAttestedWeight: reactive.NewVariable[uint64](),
IsRoot: reactive.NewEvent(),
IsAttested: reactive.NewEvent(),
IsVerified: reactive.NewEvent(),
IsFullyBooked: reactive.NewEvent(),
IsCommittable: reactive.NewEvent(),
IsCommitted: reactive.NewEvent(),
IsAboveLatestVerifiedCommitment: reactive.NewVariable[bool](),
ReplayDroppedBlocks: reactive.NewVariable[bool](),
IsEvicted: reactive.NewEvent(),
Expand Down Expand Up @@ -135,7 +143,9 @@ func (c *Commitment) initLogger() (shutdown func()) {
c.CumulativeAttestedWeight.LogUpdates(c, log.LevelTrace, "CumulativeAttestedWeight"),
c.IsRoot.LogUpdates(c, log.LevelTrace, "IsRoot"),
c.IsAttested.LogUpdates(c, log.LevelTrace, "IsAttested"),
c.IsVerified.LogUpdates(c, log.LevelTrace, "IsVerified"),
c.IsFullyBooked.LogUpdates(c, log.LevelTrace, "IsFullyBooked"),
c.IsCommittable.LogUpdates(c, log.LevelTrace, "IsCommittable"),
c.IsCommitted.LogUpdates(c, log.LevelTrace, "IsCommitted"),
c.ReplayDroppedBlocks.LogUpdates(c, log.LevelTrace, "ReplayDroppedBlocks"),
c.IsEvicted.LogUpdates(c, log.LevelTrace, "IsEvicted"),

Expand All @@ -147,10 +157,12 @@ func (c *Commitment) initLogger() (shutdown func()) {
func (c *Commitment) initDerivedProperties() (shutdown func()) {
return lo.Batch(
// mark commitments that are marked as root as verified
c.IsVerified.InheritFrom(c.IsRoot),
c.IsCommitted.InheritFrom(c.IsRoot),

// mark commitments that are marked as verified as attested
c.IsAttested.InheritFrom(c.IsVerified),
// mark commitments that are marked as verified as attested, fully booked and committable
c.IsAttested.InheritFrom(c.IsCommitted),
c.IsFullyBooked.InheritFrom(c.IsCommitted),
c.IsCommittable.InheritFrom(c.IsCommitted),

c.Parent.WithNonEmptyValue(func(parent *Commitment) func() {
// the weight can be fixed as a one time operation (as it only relies on static information from the parent
Expand Down Expand Up @@ -245,9 +257,9 @@ func (c *Commitment) deriveCumulativeAttestedWeight(parent *Commitment) func() {
// deriveIsAboveLatestVerifiedCommitment derives the IsAboveLatestVerifiedCommitment flag of this Commitment which is
// true if the parent is already above the latest verified Commitment or if the parent is verified and we are not.
func (c *Commitment) deriveIsAboveLatestVerifiedCommitment(parent *Commitment) func() {
return c.IsAboveLatestVerifiedCommitment.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, parentAboveLatestVerifiedCommitment bool, parentIsVerified bool, isVerified bool) bool {
return parentAboveLatestVerifiedCommitment || (parentIsVerified && !isVerified)
}, parent.IsAboveLatestVerifiedCommitment, parent.IsVerified, c.IsVerified))
return c.IsAboveLatestVerifiedCommitment.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, parentAboveLatestVerifiedCommitment bool, parentIsCommitted bool, isCommitted bool) bool {
return parentAboveLatestVerifiedCommitment || (parentIsCommitted && !isCommitted)
}, parent.IsAboveLatestVerifiedCommitment, parent.IsCommitted, c.IsCommitted))
}

// deriveRequestAttestations derives the RequestAttestations flag of this Commitment which is true if our Chain is
Expand All @@ -261,9 +273,9 @@ func (c *Commitment) deriveRequestAttestations(chain *Chain, parent *Commitment)
// deriveWarpSyncBlocks derives the WarpSyncBlocks flag of this Commitment which is true if our Chain is requesting
jonastheis marked this conversation as resolved.
Show resolved Hide resolved
// warp sync, and we are the directly above the latest verified Commitment.
func (c *Commitment) deriveWarpSyncBlocks(chain *Chain, parent *Commitment) func() {
return c.WarpSyncBlocks.DeriveValueFrom(reactive.NewDerivedVariable4(func(_ bool, engineInstance *engine.Engine, warpSync bool, parentIsVerified bool, isVerified bool) bool {
return engineInstance != nil && warpSync && parentIsVerified && !isVerified
}, chain.Engine, chain.WarpSyncMode, parent.IsVerified, c.IsVerified))
return c.WarpSyncBlocks.DeriveValueFrom(reactive.NewDerivedVariable4(func(_ bool, engineInstance *engine.Engine, warpSync bool, parentIsFullyBooked bool, isFullyBooked bool) bool {
return engineInstance != nil && warpSync && parentIsFullyBooked && !isFullyBooked
}, chain.Engine, chain.WarpSyncMode, parent.IsFullyBooked, c.IsFullyBooked))
}

// deriveReplayDroppedBlocks derives the ReplayDroppedBlocks flag of this Commitment which is true if our Chain has an
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/commitments.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *Commitments) publishEngineCommitments(chain *Chain, engine *engine.Engi
// mark it as produced by ourselves and force it to be on the right chain (in case our chain produced a
// different commitment than the one we erroneously expected it to be - we always trust our engine most).
publishedCommitment.AttestedWeight.Set(publishedCommitment.Weight.Get())
publishedCommitment.IsVerified.Set(true)
publishedCommitment.IsCommitted.Set(true)
publishedCommitment.forceChain(chain)
}
})
Expand Down
23 changes: 16 additions & 7 deletions pkg/protocol/protocol_warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ func (w *WarpSyncProtocol) ProcessResponse(commitmentID iotago.CommitmentID, blo
if targetEngine.Workers.WaitChildren(); targetEngine.Storage.Settings().LatestCommitment().ID().Slot() > commitmentID.Slot() {
return blocksToWarpSync
}
targetEngine.Reset()
// TODO: reset the engine only once at the very beginning of the warp-sync process
// targetEngine.Reset()

// Once all blocks are booked we
// 1. Mark all transactions as accepted
Expand All @@ -186,8 +187,19 @@ func (w *WarpSyncProtocol) ProcessResponse(commitmentID iotago.CommitmentID, blo
}
}

commitment.IsFullyBooked.OnUpdateOnce(func(_ bool, _ bool) {
minimumCommittableAge := w.protocol.APIForSlot(commitmentID.Slot()).ProtocolParameters().MinCommittableAge()
if committableCommitment, exists := chain.Commitment(commitmentID.Slot() - minimumCommittableAge + 1); exists {
committableCommitment.IsCommittable.Set(true)
}
})

commitment.IsCommittable.OnUpdateOnce(func(_ bool, _ bool) {
w.workerPool.Submit(forceCommitmentFunc)
})

if totalBlocks == 0 {
forceCommitmentFunc()
commitment.IsFullyBooked.Set(true)

return blocksToWarpSync
}
Expand All @@ -213,12 +225,9 @@ func (w *WarpSyncProtocol) ProcessResponse(commitmentID iotago.CommitmentID, blo
targetEngine.BlockGadget.SetAccepted(block)

block.Notarized().OnUpdate(func(_ bool, _ bool) {
// Wait for all blocks to be notarized before forcing the commitment of the slot.
if notarizedBlocks.Add(1) != totalBlocks {
return
if notarizedBlocks.Add(1) == totalBlocks {
karimodm marked this conversation as resolved.
Show resolved Hide resolved
commitment.IsFullyBooked.Set(true)
}

forceCommitmentFunc()
})
}
}
Expand Down
Loading