anchor.diff:  %--- API CALLS HELPER FUNCTIONS ------------------------------------------------
   
   %% Adds or update a peer; called in the caller's process.
  --spec api_add_peer(inet:ip_address() | undefined, peer_info(), boolean()) -> ok.
  -api_add_peer(SourceAddr0, PeerInfo, IsTrusted) ->
  -    case peer(PeerInfo, IsTrusted) of
  -        {error, nxdomain} ->
  -            #{ host := Host } = PeerInfo,
  -            epoch_sync:info("Peer ~p - failed to resolve hostname ~p; "
  -                            "retrying later", [ppp(PeerInfo), Host]),
  -            gen_server:cast(?MODULE, {resolve_peer, SourceAddr0,
  -                                      PeerInfo, IsTrusted});
  -        {ok, Peer} ->
  -            SourceAddr = case SourceAddr0 of
  -                undefined -> Peer#peer.address;
  -                _ -> SourceAddr0
  -            end,
  -            gen_server:cast(?MODULE, {add_peer, SourceAddr, Peer})
  -    end.
  +%% We should not block the caller, so we just spawn to make this happen in 
  +%% the background. If the process silently fails in the background, we 
  +%% will be able to detect that in the logs since we won't be able to
  +%% connect.
  +-spec async_add_peer(inet:ip_address() | undefined, peer_info(), boolean()) -> ok.
  +async_add_peer(SourceAddr0, #{ host := Host} = PeerInfo, IsTrusted) ->
  +    spawn(fun() ->
  +             case inet:getaddr(to_list(Host), inet) of
  +                 {error, nxdomain} ->
  +                     epoch_sync:info("Peer ~p - failed to resolve hostname ~p; "
  +                                     "retrying later", [ppp(PeerInfo), Host]),
  +                     gen_server:cast(?MODULE, {resolve_peer, SourceAddr0,
  +                                               PeerInfo, IsTrusted});
  +                 {ok, Addr} when SourceAddr0 == undefined ->
  +                     epoch_sync:info("PEER undefined address ~p ~p -> ~p", [Host, SourceAddr0, Addr]),
  +                     Peer = peer(Addr, PeerInfo, IsTrusted),
  +                     gen_server:cast(?MODULE, {add_peer, Addr, Peer});
  +                 {ok, Addr} when SourceAddr0 =/= undefined ->
  +                     %% IP address has changed
  +                     epoch_sync:info("IP address of peer changed ~p ~p -> ~p", [Host, SourceAddr0, Addr]),
  +                     Peer = peer(Addr, PeerInfo, IsTrusted),
  +                     gen_server:cast(?MODULE, {add_peer, SourceAddr0, Peer})
  +             end
  +          end), 
  +    ok.
   
   -spec count(connections | inbound | outbound | blocked | peers
               | verified | unverified | available | standby | hostnames, state())
  
positive.code: %% Handles event adding a new peer to the pool.
  -spec on_add_peer(inet:ip_address(), peer(), state()) -> state().
  on_add_peer(SourceAddr, Peer, State0) ->
      State = maybe_unblock(State0),
      PeerId  = peer_id(Peer),
      #peer{ pubkey = PPK, address = PA, port = PP } = Peer,
      case is_local(PeerId, State) orelse is_blocked(PeerId, State) of
  
negative.code: peer_info(#peer{ host = H, port = P, pubkey = PK }) ->
      #{ host => H, port => P, pubkey => PK }.
  
  %% Creates a peer record from peer's information and resolved address.
  -spec peer(inet:ip_address(), peer_info(), boolean()) -> peer().
  peer(PeerAddr, PeerInfo, IsTrusted) ->
  