main_chain.js
function filterAltBranchRootUnits(cb){
						//console.log('===== before filtering:', arrAltBranchRootUnits);
						var arrFilteredAltBranchRootUnits = [];
						conn.query("SELECT unit, is_free, main_chain_index FROM units WHERE unit IN(?)", [arrAltBranchRootUnits], function(rows){
							if (rows.length === 0)
								throw Error("no alt branch root units?");
							async.eachSeries(
								rows, 
								function(row, cb2){
									
									function addUnit(){
										arrBestChildren.push(row.unit);
									//	if (row.is_free === 0) // seems no reason to exclude
											arrFilteredAltBranchRootUnits.push(row.unit);
										cb2();
									}
									
									if (row.main_chain_index !== null && row.main_chain_index <= max_later_limci)
										addUnit();
									else
										graph.determineIfIncludedOrEqual(conn, row.unit, arrLaterUnits, function(bIncluded){
											bIncluded ? addUnit() : cb2();
										});
								},
								function(){
									//console.log('filtered:', arrFilteredAltBranchRootUnits);
									if (arrFilteredAltBranchRootUnits.length === 0)
										return handleBestChildrenList([]);
									var arrInitialBestChildren = _.clone(arrBestChildren);
									var start_time = Date.now();
									if (conf.bFaster)
										return collectBestChildren(arrFilteredAltBranchRootUnits, function(){
											console.log("collectBestChildren took "+(Date.now()-start_time)+"ms");
											cb();
										});
									goDownAndCollectBestChildrenOld(arrFilteredAltBranchRootUnits, function(){
										console.log("goDownAndCollectBestChildrenOld took "+(Date.now()-start_time)+"ms");
										var arrBestChildren1 = _.clone(arrBestChildren.sort());
										arrBestChildren = arrInitialBestChildren;
										start_time = Date.now();
										collectBestChildren(arrFilteredAltBranchRootUnits, function(){
											console.log("collectBestChildren took "+(Date.now()-start_time)+"ms");
											arrBestChildren.sort();
											if (!_.isEqual(arrBestChildren, arrBestChildren1)){
												throwError("different best children, old "+arrBestChildren1.join(', ')+'; new '+arrBestChildren.join(', ')+', later '+arrLaterUnits.join(', ')+', earlier '+earlier_unit+", global db? = "+(conn === db));
												arrBestChildren = arrBestChildren1;
											}
											cb();
										});
									});
								}
							);
						});
					}
function filterAltBranchRootUnits(cb){
						//console.log('===== before filtering:', arrAltBranchRootUnits);
						var arrFilteredAltBranchRootUnits = [];
						conn.query("SELECT unit, is_free, main_chain_index FROM units WHERE unit IN(?)", [arrAltBranchRootUnits], function(rows){
							if (rows.length === 0)
								throw Error("no alt branch root units?");
							async.eachSeries(
								rows, 
								function(row, cb2){
									
									function addUnit(){
										arrBestChildren.push(row.unit);
									//	if (row.is_free === 0) // seems no reason to exclude
											arrFilteredAltBranchRootUnits.push(row.unit);
										cb2();
									}
									
									if (row.main_chain_index !== null && row.main_chain_index <= max_later_limci)
										addUnit();
									else
										graph.determineIfIncludedOrEqual(conn, row.unit, arrLaterUnits, function(bIncluded){
											bIncluded ? addUnit() : cb2();
										});
								},
								function(){
									//console.log('filtered:', arrFilteredAltBranchRootUnits);
									if (arrFilteredAltBranchRootUnits.length === 0)
										return handleBestChildrenList([]);
									var arrInitialBestChildren = _.clone(arrBestChildren);
									var start_time = Date.now();
									if (conf.bFaster)
										return collectBestChildren(arrFilteredAltBranchRootUnits, function(){
											console.log("collectBestChildren took "+(Date.now()-start_time)+"ms");
											cb();
										});
									goDownAndCollectBestChildrenOld(arrFilteredAltBranchRootUnits, function(){
										console.log("goDownAndCollectBestChildrenOld took "+(Date.now()-start_time)+"ms");
										var arrBestChildren1 = _.clone(arrBestChildren.sort());
										arrBestChildren = arrInitialBestChildren;
										start_time = Date.now();
										collectBestChildren(arrFilteredAltBranchRootUnits, function(){
											console.log("collectBestChildren took "+(Date.now()-start_time)+"ms");
											arrBestChildren.sort();
											if (!_.isEqual(arrBestChildren, arrBestChildren1)){
												throwError("different best children, old "+arrBestChildren1.join(', ')+'; new '+arrBestChildren.join(', ')+', later '+arrLaterUnits.join(', ')+', earlier '+earlier_unit+", global db? = "+(conn === db));
												arrBestChildren = arrBestChildren1;
											}
											cb();
										});
									});
								}
							);
						});
					}
function filterAltBranchRootUnits ( cb ) { //console.log('===== before filtering:', arrAltBranchRootUnits); var arrFilteredAltBranchRootUnits = [ ] ; conn . query ( "SELECT unit, is_free, main_chain_index FROM units WHERE unit IN(?)" , [ arrAltBranchRootUnits ] , function ( rows ) { if ( rows . length === 0 ) throw Error ( "no alt branch root units?" ) ; async . eachSeries ( rows , function ( row , cb2 ) { function addUnit ( ) { arrBestChildren . push ( row . unit ) ; //	if (row.is_free === 0) // seems no reason to exclude arrFilteredAltBranchRootUnits . push ( row . unit ) ; cb2 ( ) ; } if ( row . main_chain_index !== null && row . main_chain_index <= max_later_limci ) addUnit ( ) ; else graph . determineIfIncludedOrEqual ( conn , row . unit , arrLaterUnits , function ( bIncluded ) { bIncluded ? addUnit ( ) : cb2 ( ) ; } ) ; } , function ( ) { //console.log('filtered:', arrFilteredAltBranchRootUnits); if ( arrFilteredAltBranchRootUnits . length === 0 ) return handleBestChildrenList ( [ ] ) ; var arrInitialBestChildren = _ . clone ( arrBestChildren ) ; var start_time = Date . now ( ) ; if ( conf . bFaster ) return collectBestChildren ( arrFilteredAltBranchRootUnits , function ( ) { console . log ( "collectBestChildren took " + ( Date . now ( ) - start_time ) + "ms" ) ; cb ( ) ; } ) ; goDownAndCollectBestChildrenOld ( arrFilteredAltBranchRootUnits , function ( ) { console . log ( "goDownAndCollectBestChildrenOld took " + ( Date . now ( ) - start_time ) + "ms" ) ; var arrBestChildren1 = _ . clone ( arrBestChildren . sort ( ) ) ; arrBestChildren = arrInitialBestChildren ; start_time = Date . now ( ) ; collectBestChildren ( arrFilteredAltBranchRootUnits , function ( ) { console . log ( "collectBestChildren took " + ( Date . now ( ) - start_time ) + "ms" ) ; arrBestChildren . sort ( ) ; if ( ! _ . isEqual ( arrBestChildren , arrBestChildren1 ) ) { throwError ( "different best children, old " + arrBestChildren1 . join ( ', ' ) + '; new ' + arrBestChildren . join ( ', ' ) + ', later ' + arrLaterUnits . join ( ', ' ) + ', earlier ' + earlier_unit + ", global db? = " + ( conn === db ) ) ; arrBestChildren = arrBestChildren1 ; } cb ( ) ; } ) ; } ) ; } ) ; } ) ; }
leaves only those roots that are included by later units
leaves only those roots that are included by later units