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