-
Notifications
You must be signed in to change notification settings - Fork 223
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
Implement new mechanism for updating UTXO Diffs #1671
Conversation
Codecov Report
@@ Coverage Diff @@
## v0.10.0-dev #1671 +/- ##
===============================================
+ Coverage 59.35% 59.53% +0.17%
===============================================
Files 550 551 +1
Lines 21838 21930 +92
===============================================
+ Hits 12962 13056 +94
+ Misses 6817 6793 -24
- Partials 2059 2081 +22
Continue to review full report at Codecov.
|
@@ -66,7 +78,7 @@ func (csm *consensusStateManager) CalculatePastUTXOAndAcceptanceData(stagingArea | |||
} | |||
|
|||
func (csm *consensusStateManager) restorePastUTXO( | |||
stagingArea *model.StagingArea, blockHash *externalapi.DomainHash) (externalapi.MutableUTXODiff, error) { | |||
stagingArea *model.StagingArea, blockHash *externalapi.DomainHash) (externalapi.UTXODiff, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you convert it to immutable? Doesn't it add extra clone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is later being passed to a place that expects immutable.
Also, because you shouldn't mutate it outside restorePastUTXO.
ToImmutable doesn't add a clone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but you add an extra clone in applyMergeSetBlocks. I suspect that it was there on purpose because of performance reasons.
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
stability-tests/reorg/reorg.go
Outdated
@@ -19,6 +19,7 @@ import ( | |||
func testReorg(cfg *configFlags) { | |||
params := dagconfig.DevnetParams | |||
params.SkipProofOfWork = true | |||
params.DisableDifficultyAdjustment = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? If it's a bug please open an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SkipProofOfWork without difficulty adjustment creates a ton of blocks with the same timestamp, which kills some assumption in the difficulty adjustment algorithm.
It can't really happen in a real DAG.
// During resolveSingleBlockStatus, all unverifiedBlocks (excluding the tip) were assigned their selectedParent | ||
// as their UTXODiffChild. | ||
// Now that the whole chain has been resolved - we can reverse the UTXODiffs, to create shorter UTXODiffChild paths. | ||
err = csm.reverseUTXODiffs(stagingArea, unverifiedBlocks, tipUTXOSet, oneBlockBeforeCurrentUTXOSet, useSeparateStagingAreaPerBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we crash in the middle/after reverseUTXODiffs, but before we committed the main stagingArea, we are going to be left with UTXODiffs to nothing.
stability-tests/reorg/reorg.go
Outdated
@@ -19,6 +19,7 @@ import ( | |||
func testReorg(cfg *configFlags) { | |||
params := dagconfig.DevnetParams | |||
params.SkipProofOfWork = true | |||
params.DisableDifficultyAdjustment = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SkipProofOfWork without difficulty adjustment creates a ton of blocks with the same timestamp, which kills some assumption in the difficulty adjustment algorithm.
It can't really happen in a real DAG.
domain/consensus/processes/consensusstatemanager/resolve_block_status.go
Outdated
Show resolved
Hide resolved
|
||
log.Debugf("Reversing utxoDiffs") | ||
|
||
// Set previousUTXODiff and previousBlock to oneBlockBeforeTip before we start touching them, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneBlockBeforeTip doesn't exist anymore
onEnd := logger.LogAndMeasureExecutionTime(log, "reverseUTXODiffs") | ||
defer onEnd() | ||
|
||
readStagingArea := model.NewStagingArea() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename it to emptyStagingArea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer "readStagingArea" because it's only used for reads (and the writes happen in a separate staging area).
return err | ||
} | ||
|
||
// oneBlockBeforeTip is special in the sense that we don't have it's diff available in reverse, however, we |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneBlockBeforeTip doesn't exist anymore
This PR implements a mechanism described in the following document: https://github.com/kaspanet/docs/blob/main/Specs/Updates%20to%20UTXO%20Diffs.md
Among other things, this enables a re-org of finalityWindow blocks, without a crashing node or a node stuck forever.
Nevertheless, it still takes around 2 hours to re-org a whole finalityWindow.
This fixes #1516