Fixed explicit trunks messing with canonical checksums
Updating the canonical checksum should only depend on if the tag is a
trunkish tag (not a checksum tag), and not if the tag is in the current
trunk. The trunk parameter to lfsr_rbyd_fetch should have no effect on
the canonical checksum.
Fixed in boath lfsr_rbyd_fetch and scripts.
Curiously no code changes:
code stack
before: 36416 2616
after: 36416 (+0.0%) 2616 (+0.0%
This commit is contained in:
@@ -3066,40 +3066,42 @@ static int lfsr_rbyd_fetch(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// found a trunk of a tree?
|
// found a trunk?
|
||||||
if (lfsr_tag_istrunk(tag)
|
if (lfsr_tag_istrunk(tag)) {
|
||||||
&& (!trunk || off <= trunk || trunk__)) {
|
if (!(trunk && off > trunk && !trunk__)) {
|
||||||
// start of trunk?
|
// start of trunk?
|
||||||
if (!trunk__) {
|
if (!trunk__) {
|
||||||
// keep track of trunk's entry point
|
// keep track of trunk's entry point
|
||||||
trunk__ = off;
|
trunk__ = off;
|
||||||
// reset weight
|
// reset weight
|
||||||
weight_ = 0;
|
weight_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// derive weight of the tree from alt pointers
|
// derive weight of the tree from alt pointers
|
||||||
//
|
//
|
||||||
// NOTE we can't check for overflow/underflow here because we
|
// NOTE we can't check for overflow/underflow here because we
|
||||||
// may be overeagerly parsing an invalid commit, it's ok for
|
// may be overeagerly parsing an invalid commit, it's ok for
|
||||||
// this to overflow/underflow as long as we throw it out later
|
// this to overflow/underflow as long as we throw it out later
|
||||||
// on a bad cksum
|
// on a bad cksum
|
||||||
weight_ += weight__;
|
weight_ += weight__;
|
||||||
|
|
||||||
// end of trunk?
|
// end of trunk?
|
||||||
if (!lfsr_tag_isalt(tag)) {
|
if (!lfsr_tag_isalt(tag)) {
|
||||||
// update canonical checksum, xoring out any perturb
|
// update trunk and weight, unless we are a shrub trunk
|
||||||
// state, we don't want erased-state affecting our
|
if (!lfsr_tag_isshrub(tag) || trunk__ == trunk) {
|
||||||
// canonical checksum
|
trunk_ = trunk__;
|
||||||
cksum = cksum_ ^ ((lfsr_rbyd_isperturb(rbyd))
|
weight = weight_;
|
||||||
? LFS_CRC32C_ODDZERO
|
}
|
||||||
: LFS_CRC32C_EVENZERO);
|
trunk__ = 0;
|
||||||
// update trunk and weight, unless we are a shrub trunk
|
|
||||||
if (!lfsr_tag_isshrub(tag) || trunk__ == trunk) {
|
|
||||||
trunk_ = trunk__;
|
|
||||||
weight = weight_;
|
|
||||||
}
|
}
|
||||||
trunk__ = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update canonical checksum, xoring out any perturb
|
||||||
|
// state, we don't want erased-state affecting our
|
||||||
|
// canonical checksum
|
||||||
|
cksum = cksum_ ^ ((lfsr_rbyd_isperturb(rbyd))
|
||||||
|
? LFS_CRC32C_ODDZERO
|
||||||
|
: LFS_CRC32C_EVENZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip data
|
// skip data
|
||||||
|
|||||||
+26
-25
@@ -695,33 +695,34 @@ class Rbyd:
|
|||||||
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
# evaluate trunks
|
# evaluate trunks
|
||||||
if (tag & 0xf000) != TAG_CKSUM and (
|
if (tag & 0xf000) != TAG_CKSUM:
|
||||||
not trunk or j_-d <= trunk or trunk___):
|
if not (trunk and j_-d > trunk and not trunk___):
|
||||||
# new trunk?
|
# new trunk?
|
||||||
if not trunk___:
|
if not trunk___:
|
||||||
trunk___ = j_-d
|
trunk___ = j_-d
|
||||||
weight__ = 0
|
weight__ = 0
|
||||||
|
|
||||||
# keep track of weight
|
# keep track of weight
|
||||||
weight__ += w
|
weight__ += w
|
||||||
|
|
||||||
# end of trunk?
|
# end of trunk?
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
# update canonical checksum, xoring out any perturb state
|
# update trunk/weight unless we found a shrub or an
|
||||||
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
# explicit trunk (which may be a shrub) is requested
|
||||||
# update trunk/weight unless we found a shrub or an
|
if not tag & TAG_SHRUB or trunk___ == trunk:
|
||||||
# explicit trunk (which may be a shrub) is requested
|
trunk__ = trunk___
|
||||||
if not tag & TAG_SHRUB or trunk___ == trunk:
|
weight_ = weight__
|
||||||
trunk__ = trunk___
|
# keep track of eoff for best matching trunk
|
||||||
weight_ = weight__
|
if trunk and j_ + size > trunk:
|
||||||
# keep track of eoff for best matching trunk
|
eoff_ = j_ + size
|
||||||
if trunk and j_ + size > trunk:
|
eoff = eoff_
|
||||||
eoff_ = j_ + size
|
cksum = cksum_
|
||||||
eoff = eoff_
|
trunk_ = trunk__
|
||||||
cksum = cksum_
|
weight = weight_
|
||||||
trunk_ = trunk__
|
trunk___ = 0
|
||||||
weight = weight_
|
|
||||||
trunk___ = 0
|
# update canonical checksum, xoring out any perturb state
|
||||||
|
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
j_ += size
|
j_ += size
|
||||||
|
|||||||
+26
-25
@@ -368,33 +368,34 @@ class Rbyd:
|
|||||||
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
# evaluate trunks
|
# evaluate trunks
|
||||||
if (tag & 0xf000) != TAG_CKSUM and (
|
if (tag & 0xf000) != TAG_CKSUM:
|
||||||
not trunk or j_-d <= trunk or trunk___):
|
if not (trunk and j_-d > trunk and not trunk___):
|
||||||
# new trunk?
|
# new trunk?
|
||||||
if not trunk___:
|
if not trunk___:
|
||||||
trunk___ = j_-d
|
trunk___ = j_-d
|
||||||
weight__ = 0
|
weight__ = 0
|
||||||
|
|
||||||
# keep track of weight
|
# keep track of weight
|
||||||
weight__ += w
|
weight__ += w
|
||||||
|
|
||||||
# end of trunk?
|
# end of trunk?
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
# update canonical checksum, xoring out any perturb state
|
# update trunk/weight unless we found a shrub or an
|
||||||
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
# explicit trunk (which may be a shrub) is requested
|
||||||
# update trunk/weight unless we found a shrub or an
|
if not tag & TAG_SHRUB or trunk___ == trunk:
|
||||||
# explicit trunk (which may be a shrub) is requested
|
trunk__ = trunk___
|
||||||
if not tag & TAG_SHRUB or trunk___ == trunk:
|
weight_ = weight__
|
||||||
trunk__ = trunk___
|
# keep track of eoff for best matching trunk
|
||||||
weight_ = weight__
|
if trunk and j_ + size > trunk:
|
||||||
# keep track of eoff for best matching trunk
|
eoff_ = j_ + size
|
||||||
if trunk and j_ + size > trunk:
|
eoff = eoff_
|
||||||
eoff_ = j_ + size
|
cksum = cksum_
|
||||||
eoff = eoff_
|
trunk_ = trunk__
|
||||||
cksum = cksum_
|
weight = weight_
|
||||||
trunk_ = trunk__
|
trunk___ = 0
|
||||||
weight = weight_
|
|
||||||
trunk___ = 0
|
# update canonical checksum, xoring out any perturb state
|
||||||
|
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
j_ += size
|
j_ += size
|
||||||
|
|||||||
+26
-25
@@ -399,33 +399,34 @@ class Rbyd:
|
|||||||
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
# evaluate trunks
|
# evaluate trunks
|
||||||
if (tag & 0xf000) != TAG_CKSUM and (
|
if (tag & 0xf000) != TAG_CKSUM:
|
||||||
not trunk or j_-d <= trunk or trunk___):
|
if not (trunk and j_-d > trunk and not trunk___):
|
||||||
# new trunk?
|
# new trunk?
|
||||||
if not trunk___:
|
if not trunk___:
|
||||||
trunk___ = j_-d
|
trunk___ = j_-d
|
||||||
weight__ = 0
|
weight__ = 0
|
||||||
|
|
||||||
# keep track of weight
|
# keep track of weight
|
||||||
weight__ += w
|
weight__ += w
|
||||||
|
|
||||||
# end of trunk?
|
# end of trunk?
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
# update canonical checksum, xoring out any perturb state
|
# update trunk/weight unless we found a shrub or an
|
||||||
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
# explicit trunk (which may be a shrub) is requested
|
||||||
# update trunk/weight unless we found a shrub or an
|
if not tag & TAG_SHRUB or trunk___ == trunk:
|
||||||
# explicit trunk (which may be a shrub) is requested
|
trunk__ = trunk___
|
||||||
if not tag & TAG_SHRUB or trunk___ == trunk:
|
weight_ = weight__
|
||||||
trunk__ = trunk___
|
# keep track of eoff for best matching trunk
|
||||||
weight_ = weight__
|
if trunk and j_ + size > trunk:
|
||||||
# keep track of eoff for best matching trunk
|
eoff_ = j_ + size
|
||||||
if trunk and j_ + size > trunk:
|
eoff = eoff_
|
||||||
eoff_ = j_ + size
|
cksum = cksum_
|
||||||
eoff = eoff_
|
trunk_ = trunk__
|
||||||
cksum = cksum_
|
weight = weight_
|
||||||
trunk_ = trunk__
|
trunk___ = 0
|
||||||
weight = weight_
|
|
||||||
trunk___ = 0
|
# update canonical checksum, xoring out any perturb state
|
||||||
|
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
j_ += size
|
j_ += size
|
||||||
|
|||||||
+26
-25
@@ -383,33 +383,34 @@ class Rbyd:
|
|||||||
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
# evaluate trunks
|
# evaluate trunks
|
||||||
if (tag & 0xf000) != TAG_CKSUM and (
|
if (tag & 0xf000) != TAG_CKSUM:
|
||||||
not trunk or j_-d <= trunk or trunk___):
|
if not (trunk and j_-d > trunk and not trunk___):
|
||||||
# new trunk?
|
# new trunk?
|
||||||
if not trunk___:
|
if not trunk___:
|
||||||
trunk___ = j_-d
|
trunk___ = j_-d
|
||||||
weight__ = 0
|
weight__ = 0
|
||||||
|
|
||||||
# keep track of weight
|
# keep track of weight
|
||||||
weight__ += w
|
weight__ += w
|
||||||
|
|
||||||
# end of trunk?
|
# end of trunk?
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
# update canonical checksum, xoring out any perturb state
|
# update trunk/weight unless we found a shrub or an
|
||||||
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
# explicit trunk (which may be a shrub) is requested
|
||||||
# update trunk/weight unless we found a shrub or an
|
if not tag & TAG_SHRUB or trunk___ == trunk:
|
||||||
# explicit trunk (which may be a shrub) is requested
|
trunk__ = trunk___
|
||||||
if not tag & TAG_SHRUB or trunk___ == trunk:
|
weight_ = weight__
|
||||||
trunk__ = trunk___
|
# keep track of eoff for best matching trunk
|
||||||
weight_ = weight__
|
if trunk and j_ + size > trunk:
|
||||||
# keep track of eoff for best matching trunk
|
eoff_ = j_ + size
|
||||||
if trunk and j_ + size > trunk:
|
eoff = eoff_
|
||||||
eoff_ = j_ + size
|
cksum = cksum_
|
||||||
eoff = eoff_
|
trunk_ = trunk__
|
||||||
cksum = cksum_
|
weight = weight_
|
||||||
trunk_ = trunk__
|
trunk___ = 0
|
||||||
weight = weight_
|
|
||||||
trunk___ = 0
|
# update canonical checksum, xoring out any perturb state
|
||||||
|
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
j_ += size
|
j_ += size
|
||||||
|
|||||||
+29
-27
@@ -577,12 +577,13 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
|
|||||||
|
|
||||||
# end of trunk?
|
# end of trunk?
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
# update canonical checksum, xoring out any perturb state
|
|
||||||
cksum = cksum_ ^ (0xfca42daf if perturb else 0)
|
|
||||||
# derive the current tag's rid from alt weights
|
# derive the current tag's rid from alt weights
|
||||||
rid = lower_ + w-1
|
rid = lower_ + w-1
|
||||||
trunk_ = 0
|
trunk_ = 0
|
||||||
|
|
||||||
|
# update canonical checksum, xoring out any perturb state
|
||||||
|
cksum = cksum_ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
# show human-readable tag representation
|
# show human-readable tag representation
|
||||||
print('%s%08x:%s %*s%s%*s %-*s%s%s%s' % (
|
print('%s%08x:%s %*s%s%*s %-*s%s%s%s' % (
|
||||||
'\x1b[90m' if color and j >= eoff else '',
|
'\x1b[90m' if color and j >= eoff else '',
|
||||||
@@ -976,33 +977,34 @@ def main(disk, blocks=None, *,
|
|||||||
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
cksum__ = cksum_ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
# evaluate trunks
|
# evaluate trunks
|
||||||
if (tag & 0xf000) != TAG_CKSUM and (
|
if (tag & 0xf000) != TAG_CKSUM:
|
||||||
not trunk or j_-d <= trunk or trunk___):
|
if not (trunk and j_-d > trunk and not trunk___):
|
||||||
# new trunk?
|
# new trunk?
|
||||||
if not trunk___:
|
if not trunk___:
|
||||||
trunk___ = j_-d
|
trunk___ = j_-d
|
||||||
weight__ = 0
|
weight__ = 0
|
||||||
|
|
||||||
# keep track of weight
|
# keep track of weight
|
||||||
weight__ += w
|
weight__ += w
|
||||||
|
|
||||||
# end of trunk?
|
# end of trunk?
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
# update canonical checksum, xoring out any perturb state
|
# update trunk/weight unless we found a shrub or an
|
||||||
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
# explicit trunk (which may be a shrub) is requested
|
||||||
# update trunk/weight unless we found a shrub or an
|
if not tag & TAG_SHRUB or trunk___ == trunk:
|
||||||
# explicit trunk (which may be a shrub) is requested
|
trunk__ = trunk___
|
||||||
if not tag & TAG_SHRUB or trunk___ == trunk:
|
weight_ = weight__
|
||||||
trunk__ = trunk___
|
# keep track of eoff for best matching trunk
|
||||||
weight_ = weight__
|
if trunk and j_ + size > trunk:
|
||||||
# keep track of eoff for best matching trunk
|
eoff_ = j_ + size
|
||||||
if trunk and j_ + size > trunk:
|
eoff = eoff_
|
||||||
eoff_ = j_ + size
|
cksum = cksum_
|
||||||
eoff = eoff_
|
trunk_ = trunk__
|
||||||
cksum = cksum_
|
weight = weight_
|
||||||
trunk_ = trunk__
|
trunk___ = 0
|
||||||
weight = weight_
|
|
||||||
trunk___ = 0
|
# update canonical checksum, xoring out any perturb state
|
||||||
|
cksum_ = cksum__ ^ (0xfca42daf if perturb else 0)
|
||||||
|
|
||||||
if not tag & TAG_ALT:
|
if not tag & TAG_ALT:
|
||||||
j_ += size
|
j_ += size
|
||||||
|
|||||||
Reference in New Issue
Block a user