6363from chia .consensus .vdf_info_computation import get_signage_point_vdf_info
6464from chia .daemon .keychain_proxy import KeychainProxy , connect_to_keychain_and_validate , wrap_local_keychain
6565from chia .full_node .bundle_tools import simple_solution_generator , simple_solution_generator_backrefs
66- from chia .plotting .create_plots import PlotKeys , create_plots
66+ from chia .plotting .create_plots import PlotKeys , create_plots , create_v2_plots
6767from chia .plotting .manager import PlotManager
6868from chia .plotting .prover import PlotVersion , QualityProtocol , V1Prover , V2Prover , V2Quality
6969from chia .plotting .util import (
@@ -319,6 +319,7 @@ def __init__(
319319 self .temp_dir .mkdir (parents = True , exist_ok = True )
320320 self .expected_plots : dict [bytes32 , Path ] = {}
321321 self .created_plots : int = 0
322+ self .created_plots2 : int = 0
322323 self .total_result = PlotRefreshResult ()
323324
324325 def test_callback (event : PlotRefreshEvents , update_result : PlotRefreshResult ) -> None :
@@ -338,6 +339,29 @@ def test_callback(event: PlotRefreshEvents, update_result: PlotRefreshResult) ->
338339 assert self .total_result .processed == update_result .processed
339340 assert self .total_result .duration == update_result .duration
340341 assert update_result .remaining == 0
342+
343+ expected_plots : set [str ] = set ()
344+ found_plots : set [str ] = set ()
345+ if len (self .plot_manager .plots ) != len (self .expected_plots ):
346+ for pid , filename in self .expected_plots .items ():
347+ expected_plots .add (filename .name )
348+ for filename , _ in self .plot_manager .plots .items ():
349+ found_plots .add (filename .name )
350+ print (f"directory: { self .plot_dir } " )
351+ print (f"expected: { len (expected_plots )} " )
352+ for f in expected_plots :
353+ print (f )
354+ print (f"plot manager: { len (found_plots )} " )
355+ for f in found_plots :
356+ print (f )
357+ diff = found_plots .difference (expected_plots )
358+ print (f"found unexpected: { len (diff )} " )
359+ for f in diff :
360+ print (f )
361+ diff = expected_plots .difference (found_plots )
362+ print (f"not found: { len (diff )} " )
363+ for f in diff :
364+ print (f )
341365 assert len (self .plot_manager .plots ) == len (self .expected_plots )
342366
343367 self .plot_manager : PlotManager = PlotManager (
@@ -498,11 +522,25 @@ async def setup_plots(
498522 num_og_plots : int = 15 ,
499523 num_pool_plots : int = 5 ,
500524 num_non_keychain_plots : int = 3 ,
525+ num_v2_plots : int = 320 ,
501526 plot_size : int = 20 ,
502527 bitfield : bool = True ,
503528 ) -> bool :
529+ # we have 20 v1 plots, each about 16.6 MB
530+ # in order to balance that out with v2 plots, we need approximately the
531+ # same size on disk. A v2 k-18 plot is expected to be about 1 MB, so we
532+ # need about 16 times more v2 plots, i.e. 320.
533+ # Additionally, the current reference plots are quite a bit larger than
534+ # the expected final plots. So until we have the optimized plot format
535+ # completed, the actual disk space for the v2 plots will be larger.
536+ print (
537+ f"setup_plots({ num_og_plots } , { num_pool_plots } , "
538+ f"{ num_non_keychain_plots } , { num_v2_plots } ) "
539+ f"plot-dir: { self .plot_dir } "
540+ )
504541 self .add_plot_directory (self .plot_dir )
505542 assert self .created_plots == 0
543+ assert self .created_plots2 == 0
506544 existing_plots : bool = True
507545 # OG Plots
508546 for i in range (num_og_plots ):
@@ -525,6 +563,11 @@ async def setup_plots(
525563 )
526564 if plot .new_plot :
527565 existing_plots = False
566+ # v2 plots
567+ for i in range (num_v2_plots ):
568+ plot = await self .new_plot2 (plot_size = 18 )
569+ if plot .new_plot :
570+ existing_plots = False
528571 await self .refresh_plots ()
529572 assert len (self .plot_manager .plots ) == len (self .expected_plots )
530573 return existing_plots
@@ -604,6 +647,48 @@ async def new_plot(
604647 shutil .rmtree (self .temp_dir , ignore_errors = True )
605648 sys .exit (1 )
606649
650+ async def new_plot2 (
651+ self ,
652+ path : Optional [Path ] = None ,
653+ exclude_plots : bool = False ,
654+ plot_size : int = 18 ,
655+ ) -> BlockToolsNewPlotResult :
656+ final_dir = self .plot_dir
657+ if path is not None :
658+ final_dir = path
659+ final_dir .mkdir (parents = True , exist_ok = True )
660+
661+ # No datetime in the filename, to get deterministic filenames and not re-plot
662+ created , existed = await create_v2_plots (
663+ final_dir = Path (final_dir ),
664+ size = plot_size ,
665+ pool_ph = self .pool_ph ,
666+ farmer_pk = self .farmer_pk ,
667+ use_datetime = False ,
668+ test_private_keys = [AugSchemeMPL .key_gen (std_hash (self .created_plots2 .to_bytes (2 , "big" )))],
669+ )
670+ self .created_plots2 += 1
671+
672+ plot_id_new : Optional [bytes32 ] = None
673+ path_new : Optional [Path ] = None
674+ new_plot : bool = True
675+
676+ if len (created ):
677+ assert len (existed ) == 0
678+ plot_id_new , path_new = next (iter (created .items ()))
679+
680+ if len (existed ):
681+ assert len (created ) == 0
682+ plot_id_new , path_new = next (iter (existed .items ()))
683+ new_plot = False
684+ assert plot_id_new is not None
685+ assert path_new is not None
686+
687+ if not exclude_plots :
688+ self .expected_plots [plot_id_new ] = path_new
689+
690+ return BlockToolsNewPlotResult (plot_id_new , new_plot )
691+
607692 async def refresh_plots (self ) -> None :
608693 self .plot_manager .refresh_parameter = replace (
609694 self .plot_manager .refresh_parameter , batch_size = uint32 (4 if len (self .expected_plots ) % 3 == 0 else 3 )
@@ -2080,6 +2165,7 @@ async def create_block_tools_async(
20802165 num_og_plots : int = 15 ,
20812166 num_pool_plots : int = 5 ,
20822167 num_non_keychain_plots : int = 3 ,
2168+ num_v2_plots : int = 320 ,
20832169) -> BlockTools :
20842170 global create_block_tools_async_count
20852171 create_block_tools_async_count += 1
@@ -2090,6 +2176,7 @@ async def create_block_tools_async(
20902176 num_og_plots = num_og_plots ,
20912177 num_pool_plots = num_pool_plots ,
20922178 num_non_keychain_plots = num_non_keychain_plots ,
2179+ num_v2_plots = num_v2_plots ,
20932180 )
20942181
20952182 return bt
0 commit comments