@@ -368,9 +368,7 @@ impl Node {
368368 } )
369369 . collect ( ) ,
370370 CpuTaskType :: VTBundleValidated ( _, votes) => {
371- std:: iter:: repeat ( cpu_times. vote_validation )
372- . take ( votes. ebs . len ( ) )
373- . collect ( )
371+ std:: iter:: repeat_n ( cpu_times. vote_validation , votes. ebs . len ( ) ) . collect ( )
374372 }
375373 }
376374 }
@@ -578,16 +576,17 @@ impl Node {
578576 pipeline,
579577 producer : self . id ,
580578 } ) ;
581- let mut eb = EndorserBlock {
579+ let ibs = self . select_ibs_for_eb ( pipeline) ;
580+ let ebs = self . select_ebs_for_eb ( pipeline) ;
581+ let bytes = self . sim_config . sizes . eb ( ibs. len ( ) , ebs. len ( ) ) ;
582+ let eb = EndorserBlock {
582583 slot,
583584 pipeline,
584585 producer : self . id ,
585- bytes : 0 ,
586- ibs : vec ! [ ] ,
587- ebs : vec ! [ ] ,
586+ bytes,
587+ ibs,
588+ ebs,
588589 } ;
589- self . try_filling_eb ( & mut eb) ;
590- eb. bytes = self . sim_config . sizes . eb ( eb. ibs . len ( ) , eb. ebs . len ( ) ) ;
591590 self . schedule_cpu_task ( CpuTaskType :: EBBlockGenerated ( eb) ) ;
592591 // A node should only generate at most 1 EB per slot
593592 return ;
@@ -1318,37 +1317,28 @@ impl Node {
13181317 Ok ( ( ) )
13191318 }
13201319
1321- fn try_filling_eb ( & mut self , eb : & mut EndorserBlock ) {
1322- eb. ibs = self . select_ibs_from_pipeline ( eb. pipeline ) ;
1323- eb. ebs = self . select_ebs_for_eb ( eb. pipeline ) ;
1324- if !self . sim_config . late_ib_inclusion {
1325- return ;
1326- }
1327- let Some ( expected_referenced_pipelines) = self . pipelines_referenced_by_ebs ( eb. pipeline )
1328- else {
1329- return ;
1330- } ;
1331-
1332- let pipelines_referenced_by_ebs: HashSet < u64 > =
1333- eb. ebs . iter ( ) . map ( |eb| eb. pipeline ) . collect ( ) ;
1334- for pipeline in expected_referenced_pipelines {
1335- if !pipelines_referenced_by_ebs. contains ( & pipeline) {
1336- let mut pipeline_ibs = self . select_ibs_from_pipeline ( pipeline) ;
1337- eb. ibs . append ( & mut pipeline_ibs) ;
1338- }
1320+ fn select_ibs_for_eb ( & self , pipeline : u64 ) -> Vec < InputBlockId > {
1321+ let mut ibs = vec ! [ ] ;
1322+ for p in self . pipelines_for_ib_references ( pipeline) {
1323+ let Some ( p_ibs) = self . leios . ibs_by_pipeline . get ( & p) else {
1324+ continue ;
1325+ } ;
1326+ ibs. extend ( p_ibs. iter ( ) . cloned ( ) ) ;
13391327 }
1328+ ibs
13401329 }
13411330
1342- fn select_ibs_from_pipeline ( & self , pipeline : u64 ) -> Vec < InputBlockId > {
1343- self . leios
1344- . ibs_by_pipeline
1345- . get ( & pipeline)
1346- . cloned ( )
1347- . unwrap_or_default ( )
1331+ fn pipelines_for_ib_references ( & self , pipeline : u64 ) -> impl Iterator < Item = u64 > + use < ' _ > {
1332+ let oldest_pipeline = if self . sim_config . late_ib_inclusion {
1333+ pipeline. saturating_sub ( 2 )
1334+ } else {
1335+ pipeline
1336+ } ;
1337+ oldest_pipeline..=pipeline
13481338 }
13491339
13501340 fn select_ebs_for_eb ( & self , pipeline : u64 ) -> Vec < EndorserBlockId > {
1351- let Some ( referenced_pipelines) = self . pipelines_referenced_by_ebs ( pipeline) else {
1341+ let Some ( referenced_pipelines) = self . pipelines_for_eb_references ( pipeline) else {
13521342 return vec ! [ ] ;
13531343 } ;
13541344
@@ -1362,7 +1352,7 @@ impl Node {
13621352 ebs
13631353 }
13641354
1365- fn pipelines_referenced_by_ebs (
1355+ fn pipelines_for_eb_references (
13661356 & self ,
13671357 pipeline : u64 ,
13681358 ) -> Option < impl Iterator < Item = u64 > + use < ' _ > > {
@@ -1409,30 +1399,22 @@ impl Node {
14091399
14101400 fn should_vote_for ( & self , eb : & EndorserBlock ) -> Result < ( ) , NoVoteReason > {
14111401 let mut ib_set = HashSet :: new ( ) ;
1412- let mut pipelines_referenced_by_ibs = HashSet :: new ( ) ;
1402+ let expected_ib_pipelines: HashSet < u64 > =
1403+ self . pipelines_for_ib_references ( eb. pipeline ) . collect ( ) ;
14131404
14141405 for ib in & eb. ibs {
14151406 if !matches ! ( self . leios. ibs. get( ib) , Some ( InputBlockState :: Received ( _) ) ) {
14161407 return Err ( NoVoteReason :: MissingIB ) ;
14171408 }
1418- ib_set. insert ( * ib) ;
1419- pipelines_referenced_by_ibs. insert ( ib. pipeline ) ;
1420- }
1421-
1422- if let Some ( ibs) = self . leios . ibs_by_pipeline . get ( & eb. pipeline ) {
1423- for ib in ibs {
1424- if !ib_set. contains ( ib) {
1425- return Err ( NoVoteReason :: ExtraIB ) ;
1426- }
1409+ if !expected_ib_pipelines. contains ( & ib. pipeline ) {
1410+ return Err ( NoVoteReason :: InvalidSlot ) ;
14271411 }
1412+ ib_set. insert ( * ib) ;
14281413 }
14291414
1430- // If this EB is meant to reference other EBs, validate that it references whatever it needs
1431- if let Some ( expected_referenced_pipelines) = self . pipelines_referenced_by_ebs ( eb. pipeline ) {
1432- let pipelines_referenced_by_ebs: HashSet < u64 > =
1433- eb. ebs . iter ( ) . map ( |id| id. pipeline ) . collect ( ) ;
1434-
1435- for expected_pipeline in expected_referenced_pipelines {
1415+ if let Some ( expected_eb_pipelines) = self . pipelines_for_eb_references ( eb. pipeline ) {
1416+ let actual_eb_pipelines: HashSet < u64 > = eb. ebs . iter ( ) . map ( |id| id. pipeline ) . collect ( ) ;
1417+ for expected_pipeline in expected_eb_pipelines {
14361418 let saw_certified_eb = self
14371419 . leios
14381420 . earliest_eb_cert_times_by_pipeline
@@ -1445,24 +1427,11 @@ impl Node {
14451427 . unwrap_or_default ( ) ;
14461428 certified_at <= & cutoff
14471429 } ) ;
1448-
1449- if saw_certified_eb && !pipelines_referenced_by_ebs. contains ( & expected_pipeline) {
1430+ if saw_certified_eb && !actual_eb_pipelines. contains ( & expected_pipeline) {
14501431 // We saw at least one certified EB for this pipeline, so we should have included one.
14511432 return Err ( NoVoteReason :: MissingEB ) ;
14521433 }
1453- if pipelines_referenced_by_ebs. contains ( & expected_pipeline)
1454- && pipelines_referenced_by_ibs. contains ( & expected_pipeline)
1455- {
1456- // No pipeline should be referenced by both an EB and any IBs
1457- return Err ( NoVoteReason :: ExtraIB ) ;
1458- }
14591434 }
1460- } else if pipelines_referenced_by_ibs
1461- . iter ( )
1462- . any ( |pipeline| * pipeline != eb. pipeline )
1463- {
1464- // This EB should only reference IBs from its own pipeline
1465- return Err ( NoVoteReason :: InvalidSlot ) ;
14661435 }
14671436
14681437 // If this EB _does_ reference other EBs, make sure we trust them
0 commit comments