Correct bitwise fork-choice rule.
This commit is contained in:
		
							parent
							
								
									20d7407faa
								
							
						
					
					
						commit
						13c957bef7
					
				| @ -192,7 +192,7 @@ where | ||||
|         } | ||||
|         // Check if there is a clear block winner at this height. If so return it.
 | ||||
|         for (hash, votes) in current_votes.iter() { | ||||
|             if *votes >= total_vote_count / 2 { | ||||
|             if *votes > total_vote_count / 2 { | ||||
|                 // we have a clear winner, return it
 | ||||
|                 return Some(*hash); | ||||
|             } | ||||
| @ -371,7 +371,10 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<T> { | ||||
|             // if there are no children, we are done, return the current_head
 | ||||
|             let children = match self.children.get(¤t_head) { | ||||
|                 Some(children) => children.clone(), | ||||
|                 None => return Ok(current_head), | ||||
|                 None => { | ||||
|                     debug!("Head found: {}", current_head); | ||||
|                     return Ok(current_head); | ||||
|                 } | ||||
|             }; | ||||
| 
 | ||||
|             // logarithmic lookup blocks to see if there are obvious winners, if so,
 | ||||
| @ -391,7 +394,7 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<T> { | ||||
|                 step /= 2; | ||||
|             } | ||||
|             if step > 0 { | ||||
|                 trace!("Found clear winner in log lookup"); | ||||
|                 trace!("Found clear winner: {}", current_head); | ||||
|             } | ||||
|             // if our skip lookup failed and we only have one child, progress to that child
 | ||||
|             else if children.len() == 1 { | ||||
|  | ||||
| @ -35,3 +35,31 @@ test_cases: | ||||
|     - b3: 3 | ||||
|   heads: | ||||
|     - id: 'b2' | ||||
| - blocks: | ||||
|     - id: 'b0' | ||||
|       parent: 'b0' | ||||
|     - id: 'b1' | ||||
|       parent: 'b0' | ||||
|     - id: 'b2' | ||||
|       parent: 'b0' | ||||
|     - id: 'b3' | ||||
|       parent: 'b1' | ||||
|     - id: 'b4' | ||||
|       parent: 'b1' | ||||
|     - id: 'b5' | ||||
|       parent: 'b1' | ||||
|     - id: 'b6' | ||||
|       parent: 'b2' | ||||
|     - id: 'b7' | ||||
|       parent: 'b6' | ||||
|   weights: | ||||
|     - b0: 0 | ||||
|     - b1: 3 | ||||
|     - b2: 2 | ||||
|     - b3: 1 | ||||
|     - b4: 1 | ||||
|     - b5: 1 | ||||
|     - b6: 2 | ||||
|     - b7: 2 | ||||
|   heads: | ||||
|     - id: 'b4' | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user