misc/sizes.py: rename "block" to "share" and "subblock" to "block"

This renaming is already in place in all of our other documentation and code, but misc/sizes.py got overlooked.
This commit is contained in:
Zooko O'Whielacronx 2007-08-08 22:31:12 -07:00
parent fedab34f83
commit 63d7e126ff

View File

@ -42,90 +42,90 @@ class Sizes:
self.file_size = file_size self.file_size = file_size
self.seg_size = seg_size = 1.0 * min(MAX_SEGSIZE, file_size) self.seg_size = seg_size = 1.0 * min(MAX_SEGSIZE, file_size)
self.num_segs = num_segs = math.ceil(file_size / seg_size) self.num_segs = num_segs = math.ceil(file_size / seg_size)
self.num_subblocks = num_subblocks = num_segs self.num_blocks = num_blocks = num_segs
self.num_blocks = num_blocks = 100 self.num_shares = num_shares = 100
self.blocks_needed = blocks_needed = 25 self.shares_needed = shares_needed = 25
self.subblock_size = subblock_size = seg_size / blocks_needed self.block_size = block_size = seg_size / shares_needed
self.block_size = block_size = subblock_size * num_subblocks self.share_size = share_size = block_size * num_blocks
# none of this includes the block-level hash chain yet, since that is # none of this includes the share-level hash chain yet, since that is
# only a function of the number of blocks. All overhead numbers # only a function of the number of shares. All overhead numbers
# assume that the block-level hash chain has already been sent, # assume that the share-level hash chain has already been sent,
# including the root of the subblock-level hash tree. # including the root of the block-level hash tree.
if mode == "alpha": if mode == "alpha":
# no hash tree at all # no hash tree at all
self.subblock_arity = 0 self.block_arity = 0
self.subblock_tree_depth = 0 self.block_tree_depth = 0
self.subblock_overhead = 0 self.block_overhead = 0
self.bytes_until_some_data = 20 + block_size self.bytes_until_some_data = 20 + share_size
self.block_storage_overhead = 0 self.share_storage_overhead = 0
self.block_transmission_overhead = 0 self.share_transmission_overhead = 0
elif mode == "beta": elif mode == "beta":
# k=num_subblocks, d=1 # k=num_blocks, d=1
# each subblock has a 20-byte hash # each block has a 20-byte hash
self.subblock_arity = num_subblocks self.block_arity = num_blocks
self.subblock_tree_depth = 1 self.block_tree_depth = 1
self.subblock_overhead = 20 self.block_overhead = 20
# the block has a list of hashes, one for each subblock # the share has a list of hashes, one for each block
self.block_storage_overhead = (self.subblock_overhead * self.share_storage_overhead = (self.block_overhead *
num_subblocks) num_blocks)
# we can get away with not sending the hash of the block that # we can get away with not sending the hash of the share that
# we're sending in full, once # we're sending in full, once
self.block_transmission_overhead = self.block_storage_overhead - 20 self.share_transmission_overhead = self.share_storage_overhead - 20
# we must get the whole list (so it can be validated) before # we must get the whole list (so it can be validated) before
# any data can be validated # any data can be validated
self.bytes_until_some_data = (self.block_transmission_overhead + self.bytes_until_some_data = (self.share_transmission_overhead +
subblock_size) block_size)
elif mode == "gamma": elif mode == "gamma":
self.subblock_arity = k = arity self.block_arity = k = arity
d = math.ceil(math.log(num_subblocks, k)) d = math.ceil(math.log(num_blocks, k))
self.subblock_tree_depth = d self.block_tree_depth = d
num_leaves = k ** d num_leaves = k ** d
# to make things easier, we make the pessimistic assumption that # to make things easier, we make the pessimistic assumption that
# we have to store hashes for all the empty places in the tree # we have to store hashes for all the empty places in the tree
# (when the number of blocks is not an exact exponent of k) # (when the number of shares is not an exact exponent of k)
self.subblock_overhead = 20 self.block_overhead = 20
# the subblock hashes are organized into a k-ary tree, which # the block hashes are organized into a k-ary tree, which
# means storing (and eventually transmitting) more hashes. This # means storing (and eventually transmitting) more hashes. This
# count includes all the low-level block hashes and the root. # count includes all the low-level share hashes and the root.
hash_nodes = (num_leaves*k - 1) / (k - 1) hash_nodes = (num_leaves*k - 1) / (k - 1)
#print "hash_depth", d #print "hash_depth", d
#print "num_leaves", num_leaves #print "num_leaves", num_leaves
#print "hash_nodes", hash_nodes #print "hash_nodes", hash_nodes
# the storage overhead is this # the storage overhead is this
self.block_storage_overhead = 20 * (hash_nodes - 1) self.share_storage_overhead = 20 * (hash_nodes - 1)
# the transmission overhead is smaller: if we actually transmit # the transmission overhead is smaller: if we actually transmit
# every subblock, we don't have to transmit 1/k of the # every block, we don't have to transmit 1/k of the
# lowest-level subblock hashes, and we don't have to transmit the # lowest-level block hashes, and we don't have to transmit the
# root because it was already sent with the block-level hash tree # root because it was already sent with the share-level hash tree
self.block_transmission_overhead = 20 * (hash_nodes self.share_transmission_overhead = 20 * (hash_nodes
- 1 # the root - 1 # the root
- num_leaves / k) - num_leaves / k)
# we must get a full sibling hash chain before we can validate # we must get a full sibling hash chain before we can validate
# any data # any data
sibling_length = d * (k-1) sibling_length = d * (k-1)
self.bytes_until_some_data = 20 * sibling_length + subblock_size self.bytes_until_some_data = 20 * sibling_length + block_size
else: else:
raise RuntimeError("unknown mode '%s" % mode) raise RuntimeError("unknown mode '%s" % mode)
self.storage_overhead = self.block_storage_overhead * num_blocks self.storage_overhead = self.share_storage_overhead * num_shares
self.storage_overhead_percentage = 100.0 * self.storage_overhead / file_size self.storage_overhead_percentage = 100.0 * self.storage_overhead / file_size
def dump(self): def dump(self):
for k in ("mode", "file_size", "seg_size", for k in ("mode", "file_size", "seg_size",
"num_segs", "num_subblocks", "num_blocks", "blocks_needed", "num_segs", "num_blocks", "num_shares", "shares_needed",
"subblock_size", "block_size", "block_size", "share_size",
"subblock_arity", "subblock_tree_depth", "block_arity", "block_tree_depth",
"subblock_overhead", "block_overhead",
"block_storage_overhead", "block_transmission_overhead", "share_storage_overhead", "share_transmission_overhead",
"storage_overhead", "storage_overhead_percentage", "storage_overhead", "storage_overhead_percentage",
"bytes_until_some_data"): "bytes_until_some_data"):
print k, getattr(self, k) print k, getattr(self, k)
@ -164,7 +164,7 @@ def text():
# 0123456789012345678901234567890123456789012345678901234567890123456 # 0123456789012345678901234567890123456789012345678901234567890123456
print "mode=%s" % mode, " arity=%d" % arity print "mode=%s" % mode, " arity=%d" % arity
print " storage storage" print " storage storage"
print "Size blocksize overhead overhead k d alacrity" print "Size sharesize overhead overhead k d alacrity"
print " (bytes) (%)" print " (bytes) (%)"
print "------- ------- -------- -------- ---- -- --------" print "------- ------- -------- -------- ---- -- --------"
#sizes = [2 ** i for i in range(7, 41)] #sizes = [2 ** i for i in range(7, 41)]
@ -177,11 +177,11 @@ def text():
s = Sizes(mode, file_size, arity) s = Sizes(mode, file_size, arity)
out = "" out = ""
out += "%7s " % fmt(file_size, trim=True) out += "%7s " % fmt(file_size, trim=True)
out += "%7s " % fmt(s.block_size) out += "%7s " % fmt(s.share_size)
out += "%8s" % fmt(s.storage_overhead) out += "%8s" % fmt(s.storage_overhead)
out += "%10.2f " % s.storage_overhead_percentage out += "%10.2f " % s.storage_overhead_percentage
out += " %4d" % int(s.subblock_arity) out += " %4d" % int(s.block_arity)
out += " %2d" % int(s.subblock_tree_depth) out += " %2d" % int(s.block_tree_depth)
out += " %8s" % fmt(s.bytes_until_some_data) out += " %8s" % fmt(s.bytes_until_some_data)
print out print out