Use variable names in pseudcode that match the specification fields

The pseudocode is Python-esque, so snake_case makes sense for other
variables, but as the pseudocode is intended for specification clarity
it should defer to the specification's naming scheme.
This commit is contained in:
Jack Grigg 2020-02-28 05:56:27 +13:00 committed by Daira Hopwood
parent 7032b92143
commit 752f2c2c01
1 changed files with 44 additions and 44 deletions

View File

@ -396,17 +396,17 @@ Tree nodes and hashing (pseudocode)
right_child: 'Optional[ZcashMMRNode]'
# commitments
subtree_commitment: bytes
start_time: int
end_time: int
start_target: int
end_target: int
start_sapling_root: bytes # left child's sapling root
end_sapling_root: bytes # right child's sapling root
subtree_total_work: int # total difficulty accumulated within each subtree
start_height: int
end_height: int
count_shielded_txs: int # number of shielded transactions in block
hashSubtreeCommitment: bytes
nEarliestTimestamp: int
nLatestTimestamp: int
nEarliestTarget: int
nLatestTarget: int
hashEarliestSaplingRoot: bytes # left child's sapling root
hashLatestSaplingRoot: bytes # right child's sapling root
nSubTreeTotalWork: int # total difficulty accumulated within each subtree
nEarliestHeight: int
nLatestHeight: int
nShieldedTxCount: int # number of shielded transactions in block
@classmethod
def from_block(Z, block: ZcashBlock) -> 'ZcashMMRNode':
@ -414,32 +414,32 @@ Tree nodes and hashing (pseudocode)
return Z(
left_child=None,
right_child=None,
subtree_commitment=block.header_hash,
start_time=block.timestamp,
end_time=block.timestamp,
start_target=block.nBits,
end_target=block.nBits,
start_sapling_root=block.sapling_root,
end_sapling_root=block.sapling_root,
subtree_total_work=calculate_work(block.nBits),
start_height=block.height,
end_height=block.height,
count_shielded_txs=block_shielded_tx_count)
hashSubtreeCommitment=block.header_hash,
nEarliestTimestamp=block.timestamp,
nLatestTimestamp=block.timestamp,
nEarliestTarget=block.nBits,
nLatestTarget=block.nBits,
hashEarliestSaplingRoot=block.sapling_root,
hashLatestSaplingRoot=block.sapling_root,
nSubTreeTotalWork=calculate_work(block.nBits),
nEarliestHeight=block.height,
nLatestHeight=block.height,
nShieldedTxCount=block_shielded_tx_count)
def serialize(self) -> bytes:
'''serializes a node'''
return (
self.subtree_commitment
+ serialize_uint32(self.start_time)
+ serialize_uint32(self.end_time)
+ serialize_uint32(self.start_target)
+ serialize_uint32(self.end_target)
+ start_sapling_root
+ end_sapling_root
+ serialize_uint256(self.subtree_total_work)
+ serialize_compact_uint(self.start_height)
+ serialize_compact_uint(self.end_height)
+ serialize_compact_uint(self.count_shielded_txs))
self.hashSubtreeCommitment
+ serialize_uint32(self.nEarliestTimestamp)
+ serialize_uint32(self.nLatestTimestamp)
+ serialize_uint32(self.nEarliestTarget)
+ serialize_uint32(self.nLatestTarget)
+ hashEarliestSaplingRoot
+ hashLatestSaplingRoot
+ serialize_uint256(self.nSubTreeTotalWork)
+ serialize_compact_uint(self.nEarliestHeight)
+ serialize_compact_uint(self.nLatestHeight)
+ serialize_compact_uint(self.nShieldedTxCount))
def make_parent(
@ -448,17 +448,17 @@ Tree nodes and hashing (pseudocode)
return ZcashMMRNode(
left_child=left_child,
right_child=right_child,
subtree_commitment=H(left_child.serialize() + right_child.serialize()),
start_time=left_child.start_time,
end_time=right_child.end_time,
start_target=left_child.start_target,
end_target=left_child.end_target,
start_sapling_root=left_child.sapling_root,
end_sapling_root=right_child.sapling_root,
subtree_total_work=left_child.subtree_total_work + right_child.subtree_total_work,
start_height=left_child.start_height,
end_height=right_child.end_height,
count_shielded_txs=left_child.count_shield + right_child.count_shield)
hashSubtreeCommitment=H(left_child.serialize() + right_child.serialize()),
nEarliestTimestamp=left_child.nEarliestTimestamp,
nLatestTimestamp=right_child.nLatestTimestamp,
nEarliestTarget=left_child.nEarliestTarget,
nLatestTarget=left_child.nLatestTarget,
hashEarliestSaplingRoot=left_child.sapling_root,
hashLatestSaplingRoot=right_child.sapling_root,
nSubTreeTotalWork=left_child.nSubTreeTotalWork + right_child.nSubTreeTotalWork,
nEarliestHeight=left_child.nEarliestHeight,
nLatestHeight=right_child.nLatestHeight,
nShieldedTxCount=left_child.count_shield + right_child.count_shield)
def make_root_commitment(root: ZcashMMRNode) -> bytes:
'''Makes the root commitment for a blockheader'''