writer.js
function updateWitnessedLevelByWitnesslist(arrWitnesses, cb){
			var arrCollectedWitnesses = [];
			
			function setWitnessedLevel(witnessed_level){
				profiler.start();
				if (witnessed_level !== objValidationState.witnessed_level)
					throwError("different witnessed levels, validation: "+objValidationState.witnessed_level+", writer: "+witnessed_level);
				objNewUnitProps.witnessed_level = witnessed_level;
				conn.query("UPDATE units SET witnessed_level=? WHERE unit=?", [witnessed_level, objUnit.unit], function(){
					profiler.stop('write-wl-update');
					cb();
				});
			}
			
			function addWitnessesAndGoUp(start_unit){
				profiler.start();
				storage.readStaticUnitProps(conn, start_unit, function(props){
					profiler.stop('write-wl-select-bp');
					var best_parent_unit = props.best_parent_unit;
					var level = props.level;
					if (level === null)
						throw Error("null level in updateWitnessedLevel");
					if (level === 0) // genesis
						return setWitnessedLevel(0);
					profiler.start();
					storage.readUnitAuthors(conn, start_unit, function(arrAuthors){
						profiler.stop('write-wl-select-authors');
						profiler.start();
						for (var i=0; i<arrAuthors.length; i++){
							var address = arrAuthors[i];
							if (arrWitnesses.indexOf(address) !== -1 && arrCollectedWitnesses.indexOf(address) === -1)
								arrCollectedWitnesses.push(address);
						}
						profiler.stop('write-wl-search');
						(arrCollectedWitnesses.length < constants.MAJORITY_OF_WITNESSES) 
							? addWitnessesAndGoUp(best_parent_unit) : setWitnessedLevel(level);
					});
				});
			}
			
			profiler.stop('write-update');
			addWitnessesAndGoUp(my_best_parent_unit);
		}
function updateWitnessedLevelByWitnesslist(arrWitnesses, cb){
			var arrCollectedWitnesses = [];
			
			function setWitnessedLevel(witnessed_level){
				profiler.start();
				if (witnessed_level !== objValidationState.witnessed_level)
					throwError("different witnessed levels, validation: "+objValidationState.witnessed_level+", writer: "+witnessed_level);
				objNewUnitProps.witnessed_level = witnessed_level;
				conn.query("UPDATE units SET witnessed_level=? WHERE unit=?", [witnessed_level, objUnit.unit], function(){
					profiler.stop('write-wl-update');
					cb();
				});
			}
			
			function addWitnessesAndGoUp(start_unit){
				profiler.start();
				storage.readStaticUnitProps(conn, start_unit, function(props){
					profiler.stop('write-wl-select-bp');
					var best_parent_unit = props.best_parent_unit;
					var level = props.level;
					if (level === null)
						throw Error("null level in updateWitnessedLevel");
					if (level === 0) // genesis
						return setWitnessedLevel(0);
					profiler.start();
					storage.readUnitAuthors(conn, start_unit, function(arrAuthors){
						profiler.stop('write-wl-select-authors');
						profiler.start();
						for (var i=0; i<arrAuthors.length; i++){
							var address = arrAuthors[i];
							if (arrWitnesses.indexOf(address) !== -1 && arrCollectedWitnesses.indexOf(address) === -1)
								arrCollectedWitnesses.push(address);
						}
						profiler.stop('write-wl-search');
						(arrCollectedWitnesses.length < constants.MAJORITY_OF_WITNESSES) 
							? addWitnessesAndGoUp(best_parent_unit) : setWitnessedLevel(level);
					});
				});
			}
			
			profiler.stop('write-update');
			addWitnessesAndGoUp(my_best_parent_unit);
		}
function updateWitnessedLevelByWitnesslist ( arrWitnesses , cb ) { var arrCollectedWitnesses = [ ] ; function setWitnessedLevel ( witnessed_level ) { profiler . start ( ) ; if ( witnessed_level !== objValidationState . witnessed_level ) throwError ( "different witnessed levels, validation: " + objValidationState . witnessed_level + ", writer: " + witnessed_level ) ; objNewUnitProps . witnessed_level = witnessed_level ; conn . query ( "UPDATE units SET witnessed_level=? WHERE unit=?" , [ witnessed_level , objUnit . unit ] , function ( ) { profiler . stop ( 'write-wl-update' ) ; cb ( ) ; } ) ; } function addWitnessesAndGoUp ( start_unit ) { profiler . start ( ) ; storage . readStaticUnitProps ( conn , start_unit , function ( props ) { profiler . stop ( 'write-wl-select-bp' ) ; var best_parent_unit = props . best_parent_unit ; var level = props . level ; if ( level === null ) throw Error ( "null level in updateWitnessedLevel" ) ; if ( level === 0 ) // genesis return setWitnessedLevel ( 0 ) ; profiler . start ( ) ; storage . readUnitAuthors ( conn , start_unit , function ( arrAuthors ) { profiler . stop ( 'write-wl-select-authors' ) ; profiler . start ( ) ; for ( var i = 0 ; i < arrAuthors . length ; i ++ ) { var address = arrAuthors [ i ] ; if ( arrWitnesses . indexOf ( address ) !== - 1 && arrCollectedWitnesses . indexOf ( address ) === - 1 ) arrCollectedWitnesses . push ( address ) ; } profiler . stop ( 'write-wl-search' ) ; ( arrCollectedWitnesses . length < constants . MAJORITY_OF_WITNESSES ) ? addWitnessesAndGoUp ( best_parent_unit ) : setWitnessedLevel ( level ) ; } ) ; } ) ; } profiler . stop ( 'write-update' ) ; addWitnessesAndGoUp ( my_best_parent_unit ) ; }
The level at which we collect at least 7 distinct witnesses while walking up the main chain from our unit. The unit itself is not counted even if it is authored by a witness
The level at which we collect at least 7 distinct witnesses while walking up the main chain from our unit . The unit itself is not counted even if it is authored by a witness