- 
                Notifications
    
You must be signed in to change notification settings  - Fork 86
 
sync_peer option to specify preferred nodes #1319
base: master
Are you sure you want to change the base?
Changes from 1 commit
08574df
              6ac2b84
              62a2276
              fe40e7a
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -879,21 +879,29 @@ reset_ledger_to_snap(Hash, Height, State) -> | |||||
| snapshot_sync(State1#state{snapshot_info=SnapInfo}). | ||||||
| 
     | 
||||||
| start_sync(#state{blockchain = Chain, swarm_tid = SwarmTID} = State) -> | ||||||
| case get_random_peer(SwarmTID) of | ||||||
| Peer = get_configured_or_random_peer(SwarmTID), | ||||||
| case Peer of | ||||||
| no_peers -> | ||||||
| %% try again later when there's peers | ||||||
| schedule_sync(State); | ||||||
| RandomPeer -> | ||||||
| {Pid, Ref} = start_block_sync(SwarmTID, Chain, RandomPeer, [], <<>>), | ||||||
| Peer -> | ||||||
| {Pid, Ref} = start_block_sync(SwarmTID, Chain, Peer, [], <<>>), | ||||||
| lager:info("new block sync starting with Pid: ~p, Ref: ~p, Peer: ~p", | ||||||
| [Pid, Ref, RandomPeer]), | ||||||
| [Pid, Ref, Peer]), | ||||||
| State#state{sync_pid = Pid, sync_ref = Ref} | ||||||
| end. | ||||||
| 
     | 
||||||
| get_configured_or_random_peer(SwarmTID) -> | ||||||
| case get_configured_sync_peer(SwarmTID) of | ||||||
| undefined-> get_random_peer(SwarmTID); | ||||||
                
       | 
||||||
| undefined-> get_random_peer(SwarmTID); | |
| undefined -> get_random_peer(SwarmTID); | 
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ConfiguredPeers -> | |
| ConfiguredPeers when is_list(ConfiguredPeers) -> | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we're validating, we should check [P | _] when is_list(P) to make sure it is a list of strings, also should gracefully fail back to random so the node will still try to sync if the config is pooched.
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this "cutting the deck" of configured peers so to speak? just a cheaper version of shuffling the list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. We only need one peer, the rest of the list is only used if the chosen one fails to connect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slick solution 👍
Uh oh!
There was an error while loading. Please reload this page.