Skip to content

Instantly share code, notes, and snippets.

@vasild
Created March 14, 2020 08:51
Show Gist options
  • Save vasild/34e342c869aff9a5a870b3ef3fff154c to your computer and use it in GitHub Desktop.
Save vasild/34e342c869aff9a5a870b3ef3fff154c to your computer and use it in GitHub Desktop.
# This is the genesis block, it does not have an undo.
SaveBlockToDisk(): height=0
FindBlockPos(): height=0, belongs to blk00000[0..292]
FlatFileSeq::Allocate(): blk00000@[0..292]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00000
SaveBlockToDisk(): height=1
FindBlockPos(): height=1, belongs to blk00000[293..571]
FlatFileSeq::Allocate(): blk00000@[293..571]
FindUndoPos(): height=1, belongs to: rev00000[0..40]
FlatFileSeq::Allocate(): rev00000@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00000
SaveBlockToDisk(): height=2
FindBlockPos(): height=2, belongs to blk00000[572..850]
FlatFileSeq::Allocate(): blk00000@[572..850]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00000
FindUndoPos(): height=2, belongs to: rev00000[41..81]
FlatFileSeq::Allocate(): rev00000@[41..81]
SaveBlockToDisk(): height=3
FindBlockPos(): height=3, belongs to blk00000[851..1129]
FlatFileSeq::Allocate(): blk00000@[851..1129]
FindUndoPos(): height=3, belongs to: rev00000[82..122]
FlatFileSeq::Allocate(): rev00000@[82..122]
# Done writing to blk00000 and rev00000, but we don't know it yet.
SaveBlockToDisk(): height=4
FindBlockPos(): height=4, belongs to blk00001[0..278]
# We realize that we have moved to the next blk file and finalize the previous blk
# and rev. So far so good because blocks have been coming in-height-order.
FlushBlockFile(): blk00000 pos=1130, finalize=1
FlushBlockFile(): rev00000 pos=123, finalize=1
FlatFileSeq::Allocate(): blk00001@[0..278]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00001
FindUndoPos(): height=4, belongs to: rev00001[0..40]
FlatFileSeq::Allocate(): rev00001@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00001
SaveBlockToDisk(): height=5
FindBlockPos(): height=5, belongs to blk00001[279..557]
FlatFileSeq::Allocate(): blk00001@[279..557]
FindUndoPos(): height=5, belongs to: rev00001[41..81]
FlatFileSeq::Allocate(): rev00001@[41..81]
SaveBlockToDisk(): height=6
FindBlockPos(): height=6, belongs to blk00001[558..836]
FlatFileSeq::Allocate(): blk00001@[558..836]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00001
FindUndoPos(): height=6, belongs to: rev00001[82..122]
FlatFileSeq::Allocate(): rev00001@[82..122]
# The last block that would fit in blk00001 comes out-of-order. We don't write
# undo for it because it is not connected.
SaveBlockToDisk(): height=8
FindBlockPos(): height=8, belongs to blk00001[837..1115]
FlatFileSeq::Allocate(): blk00001@[837..1115]
# Done writing to blk00001 (we don't know yet), but not done with rev00001.
SaveBlockToDisk(): height=7
FindBlockPos(): height=7, belongs to blk00002[0..278]
# We realize that we have moved to the next blk file and finalize the previous blk
# and rev. The previous rev file shouldn't be finalized because we will
# eventually go back to it and append the undo for block 8.
FlushBlockFile(): blk00001 pos=1116, finalize=1
FlushBlockFile(): rev00001 pos=123, finalize=1
FlatFileSeq::Allocate(): blk00002@[0..278]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00002
FindUndoPos(): height=7, belongs to: rev00002[0..40]
FlatFileSeq::Allocate(): rev00002@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00002
# We realize that block 8 is now connected and write its undo to a preceding undo file
# which has already been finalized. Since it will never be finalized again,
# bytes [164..260] are wasted.
FindUndoPos(): height=8, belongs to: rev00001[123..163]
FlatFileSeq::Allocate(): rev00001@[123..163]
FlatFileSeq::Allocate(): Pre-allocating up to position 260 in rev00001
SaveBlockToDisk(): height=9
FindBlockPos(): height=9, belongs to blk00002[279..557]
FlatFileSeq::Allocate(): blk00002@[279..557]
FindUndoPos(): height=9, belongs to: rev00002[41..81]
FlatFileSeq::Allocate(): rev00002@[41..81]
SaveBlockToDisk(): height=10
FindBlockPos(): height=10, belongs to blk00002[558..836]
FlatFileSeq::Allocate(): blk00002@[558..836]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00002
FindUndoPos(): height=10, belongs to: rev00002[82..122]
FlatFileSeq::Allocate(): rev00002@[82..122]
# This is the genesis block, it does not have an undo.
SaveBlockToDisk(): height=0
FindBlockPos(): height=0, belongs to blk00000[0..292]
FlatFileSeq::Allocate(): blk00000@[0..292]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00000
SaveBlockToDisk(): height=1
FindBlockPos(): height=1, belongs to blk00000[293..571]
FlatFileSeq::Allocate(): blk00000@[293..571]
WriteUndoDataForBlock(): _pos.nFile=0, nHighestUndoFile=0, height=1, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=1, belongs to: rev00000[0..40]
FlatFileSeq::Allocate(): rev00000@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00000
SaveBlockToDisk(): height=2
FindBlockPos(): height=2, belongs to blk00000[572..850]
FlatFileSeq::Allocate(): blk00000@[572..850]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00000
WriteUndoDataForBlock(): _pos.nFile=0, nHighestUndoFile=0, height=2, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=2, belongs to: rev00000[41..81]
FlatFileSeq::Allocate(): rev00000@[41..81]
SaveBlockToDisk(): height=3
FindBlockPos(): height=3, belongs to blk00000[851..1129]
FlatFileSeq::Allocate(): blk00000@[851..1129]
WriteUndoDataForBlock(): _pos.nFile=0, nHighestUndoFile=0, height=3, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=3, belongs to: rev00000[82..122]
FlatFileSeq::Allocate(): rev00000@[82..122]
# Done writing to blk00000 and rev00000, but we don't know it yet.
SaveBlockToDisk(): height=4
FindBlockPos(): height=4, belongs to blk00001[0..278]
# We realize that we have moved to the next blk file and finalize the previous blk
FlushBlockFile(): blk00000 pos=1130, finalize=1
FlatFileSeq::Allocate(): blk00001@[0..278]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00001
WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=0, height=4, adjacentHeights=1, isLastEntry=1
FindUndoPos(): height=4, belongs to: rev00001[0..40]
FlatFileSeq::Allocate(): rev00001@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00001
# We realize that we have moved to the next rev file and finalize the previous one
FlushUndoFile(): rev00000 pos=123, finalize=1
SaveBlockToDisk(): height=5
FindBlockPos(): height=5, belongs to blk00001[279..557]
FlatFileSeq::Allocate(): blk00001@[279..557]
WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=1, height=5, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=5, belongs to: rev00001[41..81]
FlatFileSeq::Allocate(): rev00001@[41..81]
SaveBlockToDisk(): height=6
FindBlockPos(): height=6, belongs to blk00001[558..836]
FlatFileSeq::Allocate(): blk00001@[558..836]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00001
WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=1, height=6, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=6, belongs to: rev00001[82..122]
FlatFileSeq::Allocate(): rev00001@[82..122]
# The last block that would fit in blk00001 comes out-of-order. We don't write
# undo for it because it is not connected.
SaveBlockToDisk(): height=8
FindBlockPos(): height=8, belongs to blk00001[837..1115]
FlatFileSeq::Allocate(): blk00001@[837..1115]
# Done writing to blk00001 (we don't know yet), but not done with rev00001.
SaveBlockToDisk(): height=7
FindBlockPos(): height=7, belongs to blk00002[0..278]
# We realize that we have moved to the next blk file and finalize the previous blk
FlushBlockFile(): blk00001 pos=1116, finalize=1
FlatFileSeq::Allocate(): blk00002@[0..278]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00002
WriteUndoDataForBlock(): _pos.nFile=2, nHighestUndoFile=1, height=7, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=7, belongs to: rev00002[0..40]
FlatFileSeq::Allocate(): rev00002@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00002
# We realize that block 8 is now connected and write its undo to a preceding undo file
WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=2, height=8, adjacentHeights=1, isLastEntry=1
FindUndoPos(): height=8, belongs to: rev00001[123..163]
FlatFileSeq::Allocate(): rev00001@[123..163]
FlatFileSeq::Allocate(): Pre-allocating up to position 260 in rev00001
# We realize that this is a write to an old undo file, to its last and final
# entry and thus we finalize the file.
FlushUndoFile(): rev00001 pos=164, finalize=1
SaveBlockToDisk(): height=9
FindBlockPos(): height=9, belongs to blk00002[279..557]
FlatFileSeq::Allocate(): blk00002@[279..557]
WriteUndoDataForBlock(): _pos.nFile=2, nHighestUndoFile=2, height=9, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=9, belongs to: rev00002[41..81]
FlatFileSeq::Allocate(): rev00002@[41..81]
SaveBlockToDisk(): height=10
FindBlockPos(): height=10, belongs to blk00002[558..836]
FlatFileSeq::Allocate(): blk00002@[558..836]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00002
WriteUndoDataForBlock(): _pos.nFile=2, nHighestUndoFile=2, height=10, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=10, belongs to: rev00002[82..122]
FlatFileSeq::Allocate(): rev00002@[82..122]
--- /tmp/issue17890-bug.txt 2020-03-14 09:41:02.084064000 +0100
+++ /tmp/issue17890-fixed.txt 2020-03-14 09:41:11.077567000 +0100
@@ -7,6 +7,7 @@
SaveBlockToDisk(): height=1
FindBlockPos(): height=1, belongs to blk00000[293..571]
FlatFileSeq::Allocate(): blk00000@[293..571]
+WriteUndoDataForBlock(): _pos.nFile=0, nHighestUndoFile=0, height=1, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=1, belongs to: rev00000[0..40]
FlatFileSeq::Allocate(): rev00000@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00000
@@ -15,12 +16,14 @@
FindBlockPos(): height=2, belongs to blk00000[572..850]
FlatFileSeq::Allocate(): blk00000@[572..850]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00000
+WriteUndoDataForBlock(): _pos.nFile=0, nHighestUndoFile=0, height=2, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=2, belongs to: rev00000[41..81]
FlatFileSeq::Allocate(): rev00000@[41..81]
SaveBlockToDisk(): height=3
FindBlockPos(): height=3, belongs to blk00000[851..1129]
FlatFileSeq::Allocate(): blk00000@[851..1129]
+WriteUndoDataForBlock(): _pos.nFile=0, nHighestUndoFile=0, height=3, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=3, belongs to: rev00000[82..122]
FlatFileSeq::Allocate(): rev00000@[82..122]
@@ -29,18 +32,20 @@
SaveBlockToDisk(): height=4
FindBlockPos(): height=4, belongs to blk00001[0..278]
# We realize that we have moved to the next blk file and finalize the previous blk
- # and rev. So far so good because blocks have been coming in-height-order.
FlushBlockFile(): blk00000 pos=1130, finalize=1
- FlushBlockFile(): rev00000 pos=123, finalize=1
FlatFileSeq::Allocate(): blk00001@[0..278]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00001
+WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=0, height=4, adjacentHeights=1, isLastEntry=1
FindUndoPos(): height=4, belongs to: rev00001[0..40]
FlatFileSeq::Allocate(): rev00001@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00001
+ # We realize that we have moved to the next rev file and finalize the previous one
+ FlushUndoFile(): rev00000 pos=123, finalize=1
SaveBlockToDisk(): height=5
FindBlockPos(): height=5, belongs to blk00001[279..557]
FlatFileSeq::Allocate(): blk00001@[279..557]
+WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=1, height=5, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=5, belongs to: rev00001[41..81]
FlatFileSeq::Allocate(): rev00001@[41..81]
@@ -48,6 +53,7 @@
FindBlockPos(): height=6, belongs to blk00001[558..836]
FlatFileSeq::Allocate(): blk00001@[558..836]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00001
+WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=1, height=6, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=6, belongs to: rev00001[82..122]
FlatFileSeq::Allocate(): rev00001@[82..122]
@@ -62,25 +68,26 @@
SaveBlockToDisk(): height=7
FindBlockPos(): height=7, belongs to blk00002[0..278]
# We realize that we have moved to the next blk file and finalize the previous blk
- # and rev. The previous rev file shouldn't be finalized because we will
- # eventually go back to it and append the undo for block 8.
FlushBlockFile(): blk00001 pos=1116, finalize=1
- FlushBlockFile(): rev00001 pos=123, finalize=1
FlatFileSeq::Allocate(): blk00002@[0..278]
FlatFileSeq::Allocate(): Pre-allocating up to position 600 in blk00002
+WriteUndoDataForBlock(): _pos.nFile=2, nHighestUndoFile=1, height=7, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=7, belongs to: rev00002[0..40]
FlatFileSeq::Allocate(): rev00002@[0..40]
FlatFileSeq::Allocate(): Pre-allocating up to position 130 in rev00002
# We realize that block 8 is now connected and write its undo to a preceding undo file
- # which has already been finalized. Since it will never be finalized again,
- # bytes [164..260] are wasted.
+ WriteUndoDataForBlock(): _pos.nFile=1, nHighestUndoFile=2, height=8, adjacentHeights=1, isLastEntry=1
FindUndoPos(): height=8, belongs to: rev00001[123..163]
FlatFileSeq::Allocate(): rev00001@[123..163]
FlatFileSeq::Allocate(): Pre-allocating up to position 260 in rev00001
+ # We realize that this is a write to an old undo file, to its last and final
+ # entry and thus we finalize the file.
+ FlushUndoFile(): rev00001 pos=164, finalize=1
SaveBlockToDisk(): height=9
FindBlockPos(): height=9, belongs to blk00002[279..557]
FlatFileSeq::Allocate(): blk00002@[279..557]
+WriteUndoDataForBlock(): _pos.nFile=2, nHighestUndoFile=2, height=9, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=9, belongs to: rev00002[41..81]
FlatFileSeq::Allocate(): rev00002@[41..81]
@@ -88,5 +95,6 @@
FindBlockPos(): height=10, belongs to blk00002[558..836]
FlatFileSeq::Allocate(): blk00002@[558..836]
FlatFileSeq::Allocate(): Pre-allocating up to position 1200 in blk00002
+WriteUndoDataForBlock(): _pos.nFile=2, nHighestUndoFile=2, height=10, adjacentHeights=0, isLastEntry=1
FindUndoPos(): height=10, belongs to: rev00002[82..122]
FlatFileSeq::Allocate(): rev00002@[82..122]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment