@@ -77,10 +77,14 @@ pub struct Block<N: Network> {
7777 ratifications : Ratifications < N > ,
7878 /// The solutions in the block.
7979 solutions : Solutions < N > ,
80+ /// The prior solution ids in the block.
81+ prior_solution_ids : Vec < SolutionID < N > > ,
8082 /// The aborted solution IDs in this block.
8183 aborted_solution_ids : Vec < SolutionID < N > > ,
8284 /// The transactions in this block.
8385 transactions : Transactions < N > ,
86+ /// The prior transaction ids in the block.
87+ prior_transaction_ids : Vec < N :: TransactionID > ,
8488 /// The aborted transaction IDs in this block.
8589 aborted_transaction_ids : Vec < N :: TransactionID > ,
8690}
@@ -94,8 +98,10 @@ impl<N: Network> Block<N> {
9498 header : Header < N > ,
9599 ratifications : Ratifications < N > ,
96100 solutions : Solutions < N > ,
101+ prior_solution_ids : Vec < SolutionID < N > > ,
97102 aborted_solution_ids : Vec < SolutionID < N > > ,
98103 transactions : Transactions < N > ,
104+ prior_transaction_ids : Vec < N :: TransactionID > ,
99105 aborted_transaction_ids : Vec < N :: TransactionID > ,
100106 rng : & mut R ,
101107 ) -> Result < Self > {
@@ -110,8 +116,10 @@ impl<N: Network> Block<N> {
110116 authority,
111117 ratifications,
112118 solutions,
119+ prior_solution_ids,
113120 aborted_solution_ids,
114121 transactions,
122+ prior_transaction_ids,
115123 aborted_transaction_ids,
116124 )
117125 }
@@ -124,8 +132,10 @@ impl<N: Network> Block<N> {
124132 subdag : Subdag < N > ,
125133 ratifications : Ratifications < N > ,
126134 solutions : Solutions < N > ,
135+ prior_solution_ids : Vec < SolutionID < N > > ,
127136 aborted_solution_ids : Vec < SolutionID < N > > ,
128137 transactions : Transactions < N > ,
138+ prior_transaction_ids : Vec < N :: TransactionID > ,
129139 aborted_transaction_ids : Vec < N :: TransactionID > ,
130140 ) -> Result < Self > {
131141 // Construct the beacon authority.
@@ -137,8 +147,10 @@ impl<N: Network> Block<N> {
137147 authority,
138148 ratifications,
139149 solutions,
150+ prior_solution_ids,
140151 aborted_solution_ids,
141152 transactions,
153+ prior_transaction_ids,
142154 aborted_transaction_ids,
143155 )
144156 }
@@ -151,8 +163,10 @@ impl<N: Network> Block<N> {
151163 authority : Authority < N > ,
152164 ratifications : Ratifications < N > ,
153165 solutions : Solutions < N > ,
166+ prior_solution_ids : Vec < SolutionID < N > > ,
154167 aborted_solution_ids : Vec < SolutionID < N > > ,
155168 transactions : Transactions < N > ,
169+ prior_transaction_ids : Vec < N :: TransactionID > ,
156170 aborted_transaction_ids : Vec < N :: TransactionID > ,
157171 ) -> Result < Self > {
158172 // Ensure the number of aborted solutions IDs is within the allowed range.
@@ -202,8 +216,10 @@ impl<N: Network> Block<N> {
202216 Self :: check_subdag_transmissions (
203217 subdag,
204218 & solutions,
219+ & prior_solution_ids,
205220 & aborted_solution_ids,
206221 & transactions,
222+ & prior_transaction_ids,
207223 & aborted_transaction_ids,
208224 ) ?;
209225 }
@@ -231,8 +247,10 @@ impl<N: Network> Block<N> {
231247 authority,
232248 ratifications,
233249 solutions,
250+ prior_solution_ids,
234251 aborted_solution_ids,
235252 transactions,
253+ prior_transaction_ids,
236254 aborted_transaction_ids,
237255 )
238256 }
@@ -247,8 +265,10 @@ impl<N: Network> Block<N> {
247265 authority : Authority < N > ,
248266 ratifications : Ratifications < N > ,
249267 solutions : Solutions < N > ,
268+ prior_solution_ids : Vec < SolutionID < N > > ,
250269 aborted_solution_ids : Vec < SolutionID < N > > ,
251270 transactions : Transactions < N > ,
271+ prior_transaction_ids : Vec < N :: TransactionID > ,
252272 aborted_transaction_ids : Vec < N :: TransactionID > ,
253273 ) -> Result < Self > {
254274 // Return the block.
@@ -259,11 +279,81 @@ impl<N: Network> Block<N> {
259279 authority,
260280 ratifications,
261281 solutions,
282+ prior_solution_ids,
262283 aborted_solution_ids,
263284 transactions,
285+ prior_transaction_ids,
264286 aborted_transaction_ids,
265287 } )
266288 }
289+
290+ /// Consume the Block and return a Subdag with full batch certificates.
291+ pub fn into_full_subdag ( self ) -> Result < Subdag < N > > {
292+ let Block {
293+ ratifications,
294+ solutions,
295+ prior_solution_ids,
296+ transactions,
297+ prior_transaction_ids,
298+ aborted_transaction_ids,
299+ authority,
300+ ..
301+ } = self ;
302+
303+ // Check if Authority is a Quorum
304+ let Authority :: Quorum ( subdag) = authority else {
305+ bail ! ( "Can only convert block with Quorum Authority to full subdag" ) ;
306+ } ;
307+
308+ // Collect ratification IDs.
309+ let ratification_ids = ratifications. ratification_ids ( ) . copied ( ) . collect_vec ( ) ;
310+ // Collect transaction IDs.
311+ let transaction_ids = transactions. transaction_ids ( ) . copied ( ) . collect_vec ( ) ;
312+
313+ // Convert Quorum authority to subdag with full batch certificates.
314+ subdag. into_full (
315+ ratification_ids,
316+ solutions. as_puzzle_solutions ( ) . cloned ( ) ,
317+ prior_solution_ids,
318+ transaction_ids,
319+ prior_transaction_ids,
320+ aborted_transaction_ids,
321+ )
322+ }
323+
324+ /// Borrow the Block and return a Subdag with full batch certificates.
325+ pub fn to_full_subdag ( & self ) -> Result < Subdag < N > > {
326+ let Block {
327+ ratifications,
328+ solutions,
329+ prior_solution_ids,
330+ transactions,
331+ prior_transaction_ids,
332+ aborted_transaction_ids,
333+ authority,
334+ ..
335+ } = self ;
336+
337+ // Check if Authority is a Quorum
338+ let Authority :: Quorum ( subdag) = authority else {
339+ bail ! ( "Can only convert block with Quorum Authority to full subdag" ) ;
340+ } ;
341+
342+ // Collect ratification IDs.
343+ let ratification_ids = ratifications. ratification_ids ( ) . copied ( ) . collect_vec ( ) ;
344+ // Collect transaction IDs.
345+ let transaction_ids = transactions. transaction_ids ( ) . copied ( ) . collect_vec ( ) ;
346+
347+ // Convert Quorum authority to subdag with full batch certificates.
348+ subdag. clone ( ) . into_full (
349+ ratification_ids,
350+ solutions. as_puzzle_solutions ( ) . cloned ( ) ,
351+ prior_solution_ids. clone ( ) ,
352+ transaction_ids,
353+ prior_transaction_ids. clone ( ) ,
354+ aborted_transaction_ids. clone ( ) ,
355+ )
356+ }
267357}
268358
269359impl < N : Network > Block < N > {
@@ -297,11 +387,21 @@ impl<N: Network> Block<N> {
297387 & self . aborted_solution_ids
298388 }
299389
390+ /// Returns the prior solution ids in the block.
391+ pub const fn prior_solution_ids ( & self ) -> & Vec < SolutionID < N > > {
392+ & self . prior_solution_ids
393+ }
394+
300395 /// Returns the transactions in this block.
301396 pub const fn transactions ( & self ) -> & Transactions < N > {
302397 & self . transactions
303398 }
304399
400+ /// Returns the prior transactions ids in the block.
401+ pub const fn prior_transaction_ids ( & self ) -> & Vec < N :: TransactionID > {
402+ & self . prior_transaction_ids
403+ }
404+
305405 /// Returns the aborted transaction IDs in this block.
306406 pub const fn aborted_transaction_ids ( & self ) -> & Vec < N :: TransactionID > {
307407 & self . aborted_transaction_ids
@@ -709,8 +809,10 @@ pub mod test_helpers {
709809 ratifications,
710810 None . into ( ) ,
711811 vec ! [ ] ,
812+ vec ! [ ] ,
712813 transactions,
713814 vec ! [ ] ,
815+ vec ! [ ] ,
714816 rng,
715817 )
716818 . unwrap ( ) ;
0 commit comments