Skip to content

Commit

Permalink
Remove the tree abomination.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss committed Apr 19, 2021
1 parent 44ba535 commit 166ab7c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 61 deletions.
21 changes: 1 addition & 20 deletions chia/full_node/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def create_generator_args(generator_ref_list: List[SerializedProgram]) -> Progra
`create_generator_args`: The format and contents of these arguments affect consensus.
"""
gen_ref_list = [bytes(g) for g in generator_ref_list]
gen_ref_tree = list_to_tree(gen_ref_list)
return Program.to([gen_ref_tree])
return Program.to([gen_ref_list])


def create_compressed_generator(
Expand Down Expand Up @@ -72,21 +71,3 @@ def run_generator_unsafe(self: BlockGenerator, max_cost: int) -> Tuple[int, Seri
"""This mode is meant for accepting possibly soft-forked transactions into the mempool"""
program, args = setup_generator_args(self)
return GENERATOR_MOD.run_with_cost(max_cost, program, args)


def list_to_tree(items):
"""
This recursively turns a python list into a minimal depth tree.
[] => []
[a] => a (a leaf node)
[a_1, ..., a_n] => (list_to_tree(B_0), list_to_tree(B_1)) where len(B_0) - len(B_1) is 0 or 1
and B_0 + B_1 is the original list
[1, 2, 3, 4] => ((1, 2), (3, 4))
"""
size = len(items)
if size == 0:
return []
if size == 1:
return items[0]
halfway = (size + 1) // 2
return (list_to_tree(items[:halfway]), list_to_tree(items[halfway:]))
2 changes: 1 addition & 1 deletion chia/wallet/puzzles/block_program_zero.clvm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
(decompress_cses decompress_puzzle decompress_coin_solution_entry (r cses) deserialize puzzle_prefix ))
()) )

(decompress_cses decompress_puzzle decompress_coin_solution_entry compressed_cses deserialize (substr gen_list start end))
(decompress_cses decompress_puzzle decompress_coin_solution_entry compressed_cses deserialize (substr (f gen_list) start end))

)
2 changes: 1 addition & 1 deletion chia/wallet/puzzles/block_program_zero.clvm.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ff02ffff01ff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ff5fffff04ff81bfffff04ffff0cff82017fff17ff2f80ff8080808080808080ffff04ffff01ff02ffff03ff17ffff01ff04ffff02ff0bffff04ff2fffff04ff05ffff04ff5fffff04ff27ff808080808080ffff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ff37ffff04ff2fffff04ff5fff808080808080808080ff8080ff0180ff018080
ff02ffff01ff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ff5fffff04ff81bfffff04ffff0cff82027fff17ff2f80ff8080808080808080ffff04ffff01ff02ffff03ff17ffff01ff04ffff02ff0bffff04ff2fffff04ff05ffff04ff5fffff04ff27ff808080808080ffff02ff02ffff04ff02ffff04ff05ffff04ff0bffff04ff37ffff04ff2fffff04ff5fff808080808080808080ff8080ff0180ff018080
2 changes: 1 addition & 1 deletion chia/wallet/puzzles/block_program_zero.clvm.hex.sha256tree
Original file line number Diff line number Diff line change
@@ -1 +1 @@
036661dec6b8eb15204b20b3a495d723b5871f29eb1e02ca9ec674f6dd8e3657
d6a3e2a83979ef1c43811fac3abcdca92b561ee43e81d62aab837cabb9f4c8ac
4 changes: 2 additions & 2 deletions tests/generator/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_block_program_zero(self):
Program.to(end),
cse2,
DESERIALIZE_MOD,
bytes(original_generator),
[bytes(original_generator)],
],
)

Expand Down Expand Up @@ -194,7 +194,7 @@ def test_block_program_zero_with_curry(self):
# (mod (decompress_puzzle decompress_coin_solution_entry start end compressed_cses deserialize generator_list reserved_arg)
# cost, out = DECOMPRESS_BLOCK.run_with_cost(INFINITE_COST, [DECOMPRESS_PUZZLE, DECOMPRESS_CSE, start, Program.to(end), cse0, DESERIALIZE_MOD, bytes(original_generator)])
p = DECOMPRESS_BLOCK.curry(DECOMPRESS_PUZZLE, DECOMPRESS_CSE_WITH_PREFIX, start, Program.to(end))
cost, out = p.run_with_cost(INFINITE_COST, [cse2, DESERIALIZE_MOD, bytes(original_generator)])
cost, out = p.run_with_cost(INFINITE_COST, [cse2, DESERIALIZE_MOD, [bytes(original_generator)]])

print()
print(p)
Expand Down
38 changes: 2 additions & 36 deletions tests/generator/test_generator_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from chia.types.blockchain_format.program import Program, SerializedProgram
from chia.types.generator_types import GeneratorBlockCacheInterface
from chia.full_node.generator import create_block_generator, create_generator_args, list_to_tree
from chia.full_node.generator import create_block_generator, create_generator_args
from chia.util.ints import uint32

gen0 = SerializedProgram.from_bytes(
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_make_generator_args(self):
gen_args_as_program = Program.from_bytes(bytes(gen_args))

# First Argument to the block generator is the first template generator
arg2 = gen_args_as_program.first()
arg2 = gen_args_as_program.first().first()
print(arg2)
assert arg2 == bytes(gen1)

Expand All @@ -58,37 +58,3 @@ def test_make_generator_args(self):
# arg2 = gen_args_as_program.rest().first()
# assert arg2 == binutils.assemble("('gen1' 'gen2')")
# print(arg2)

def test_list_to_tree(self):
self.assertEqual([], list_to_tree([]))
self.assertEqual(1, list_to_tree([1]))
self.assertEqual((1, 2), list_to_tree([1, 2]))
self.assertEqual(((1, 2), 3), list_to_tree([1, 2, 3]))
self.assertEqual(((1, 2), (3, 4)), list_to_tree([1, 2, 3, 4]))
self.assertEqual((((1, 2), 3), (4, 5)), list_to_tree([1, 2, 3, 4, 5]))
self.assertEqual((((1, 2), 3), ((4, 5), 6)), list_to_tree([1, 2, 3, 4, 5, 6]))
self.assertEqual((((1, 2), (3, 4)), ((5, 6), 7)), list_to_tree([1, 2, 3, 4, 5, 6, 7]))
self.assertEqual((((1, 2), (3, 4)), ((5, 6), (7, 8))), list_to_tree([1, 2, 3, 4, 5, 6, 7, 8]))
R = (
(
(
((((0, 1), 2), (3, 4)), (((5, 6), 7), (8, 9))),
((((10, 11), 12), (13, 14)), (((15, 16), 17), (18, 19))),
),
(
((((20, 21), 22), (23, 24)), (((25, 26), 27), (28, 29))),
((((30, 31), 32), (33, 34)), (((35, 36), 37), (38, 39))),
),
),
(
(
((((40, 41), 42), (43, 44)), (((45, 46), 47), (48, 49))),
((((50, 51), 52), (53, 54)), (((55, 56), 57), (58, 59))),
),
(
((((60, 61), 62), (63, 64)), (((65, 66), 67), (68, 69))),
((((70, 71), 72), (73, 74)), (((75, 76), 77), (78, 79))),
),
),
)
self.assertEqual(R, list_to_tree(list(range(80))))

0 comments on commit 166ab7c

Please sign in to comment.