@@ -748,6 +748,32 @@ FUZZ_TARGET(txgraph)
748748 }
749749 builder_data.done = new_done;
750750 break ;
751+ } else if (!main_sim.IsOversized () && command-- == 0 ) {
752+ // GetWorstMainChunk.
753+ auto [worst_chunk, worst_chunk_feerate] = real->GetWorstMainChunk ();
754+ // Just do some sanity checks here. Consistency with GetBlockBuilder is checked
755+ // below.
756+ if (main_sim.GetTransactionCount () == 0 ) {
757+ assert (worst_chunk.empty ());
758+ assert (worst_chunk_feerate.IsEmpty ());
759+ } else {
760+ assert (!worst_chunk.empty ());
761+ SimTxGraph::SetType done;
762+ FeePerWeight sum;
763+ for (TxGraph::Ref* ref : worst_chunk) {
764+ // Each transaction in the chunk must exist in the main graph.
765+ auto simpos = main_sim.Find (ref);
766+ assert (simpos != SimTxGraph::MISSING);
767+ sum += main_sim.graph .FeeRate (simpos);
768+ // Make sure the chunk contains no duplicate transactions.
769+ assert (!done[simpos]);
770+ done.Set (simpos);
771+ // All elements are preceded by all their descendants.
772+ assert (main_sim.graph .Descendants (simpos).IsSubsetOf (done));
773+ }
774+ assert (sum == worst_chunk_feerate);
775+ }
776+ break ;
751777 }
752778 }
753779 }
@@ -806,6 +832,8 @@ FUZZ_TARGET(txgraph)
806832 // if nothing is skipped.
807833 auto builder = real->GetBlockBuilder ();
808834 std::vector<SimTxGraph::Pos> vec_builder;
835+ std::vector<TxGraph::Ref*> last_chunk;
836+ FeePerWeight last_chunk_feerate;
809837 while (auto chunk = builder->GetCurrentChunk ()) {
810838 FeePerWeight sum;
811839 for (TxGraph::Ref* ref : chunk->first ) {
@@ -820,10 +848,18 @@ FUZZ_TARGET(txgraph)
820848 vec_builder.push_back (simpos);
821849 }
822850 assert (sum == chunk->second );
851+ last_chunk = std::move (chunk->first );
852+ last_chunk_feerate = chunk->second ;
823853 builder->Include ();
824854 }
825855 assert (vec_builder == vec1);
826856
857+ // The last chunk returned by the BlockBuilder must match GetWorstMainChunk, in reverse.
858+ std::reverse (last_chunk.begin (), last_chunk.end ());
859+ auto [worst_chunk, worst_chunk_feerate] = real->GetWorstMainChunk ();
860+ assert (last_chunk == worst_chunk);
861+ assert (last_chunk_feerate == worst_chunk_feerate);
862+
827863 // Check that the implied ordering gives rise to a combined diagram that matches the
828864 // diagram constructed from the individual cluster linearization chunkings.
829865 auto main_real_diagram = get_diagram_fn (/* main_only=*/ true );
0 commit comments