anchor.diff:  -define(ok_leaf,     2).
   -define(fail_leaf,   3).
   -define(fail_inner,  4).
  --define(omit,       -1). % NOTE: MUST NOT interfere with merkle_tree:mt_node_key()!
  -
  --type merkle_cmp_result()  :: ?ok_inner | ?ok_leaf | ?fail_leaf | ?fail_inner.
  --type merkle_cmp_request() :: merkle_tree:mt_node_key() | ?omit.
  +
  +-type merkle_cmp_result()  :: ?ok_inner | 
  +                              ?ok_leaf | 
  +                              {?fail_leaf, merkle_tree:mt_node_key()} | 
  +                              ?fail_inner.
  +-type merkle_cmp_request() :: 
  +          merkle_tree:mt_node_key() | 
  +          {NodesToOmit::pos_integer(), LeafHash::merkle_tree:mt_node_key()}.
   
   -type request() :: 
       {start, method(), DestKey::recon_dest()} |
  
positive.code:                                       Res,
                                        lists:reverse(Childs, RTree));
          true -> 
              NewReq = lists:duplicate(BS, ?omit),
              p_process_tree_cmp_result(TR, TN, BS, Stats,
                                        lists:append(NewReq, Req), [Node | Res], RTree)
      end.
  
  %% @doc Gets all leaves in the given merkle node list (recursively).
  -spec merkle_get_sync_leaves(Nodes::NodeL, LeafAcc::NodeL,
                               NLSyncAcc::non_neg_integer())
          -> {ToSync::NodeL, NLSync::non_neg_integer()} when
                    is_subtype(NodeL,  [merkle_tree:mt_node()]).
  merkle_get_sync_leaves([], ToSyncAcc, NLSyncAcc) ->
      {ToSyncAcc, NLSyncAcc};
  merkle_get_sync_leaves([Node | Rest], ToSyncAcc, NLSyncAcc) ->
      case merkle_tree:is_leaf(Node) of
          true  ->
              merkle_get_sync_leaves(Rest, [Node | ToSyncAcc], NLSyncAcc + 1);
          false ->
              merkle_get_sync_leaves(
                lists:append(merkle_tree:get_childs(Node), Rest),
                ToSyncAcc, NLSyncAcc)
      end.
  
  %% @doc Starts a single resolve request for all given leave nodes by joining
  %%      their intervals.
  %%      Returns the number of resolve requests (requests with feedback count 2).
  -spec resolve_leaves([merkle_tree:mt_node()], Dest::comm:mypid(),
                       rrepair:session_id(), OwnerLocal::comm:erl_local_pid())
          -> 0..2.
  resolve_leaves([], _Dest, _SID, _OwnerL) -> 0;
  resolve_leaves(Nodes, Dest, SID, OwnerL) ->
      resolve_leaves(Nodes, Dest, SID, OwnerL, intervals:empty(), 0).
  
  % @doc Returns number of caused resolve requests (requests with feedback count 2).
  -spec resolve_leaves([merkle_tree:mt_node()], Dest::comm:mypid(),
                       rrepair:session_id(), OwnerLocal::comm:erl_local_pid(),
                       Interval::intervals:interval(), Items::non_neg_integer())
          -> 0..2.
  resolve_leaves([Node | Rest], Dest, SID, OwnerL, Interval, Items) ->
      LeafInterval = merkle_tree:get_interval(Node),
      IntervalNew = intervals:union(Interval, LeafInterval),
      ItemsNew = Items + merkle_tree:get_item_count(Node),
      resolve_leaves(Rest, Dest, SID, OwnerL, IntervalNew, ItemsNew);
  resolve_leaves([], Dest, SID, OwnerL, Interval, Items) ->
      Options = [{feedback_request, comm:make_global(OwnerL)}],
      case intervals:is_empty(Interval) of
          true -> 0;
  
negative.code:         case merkle_tree:get_interval(Tree) =:= art:get_interval(Art) of
              true ->
                  {ASyncLeafs, NComp, NSkip, NLSync} =
                      art_get_sync_leafs([merkle_tree:get_root(Tree)], Art,
                                          [], 0, 0, 0),
                  ResolveCalled = resolve_leafs(ASyncLeafs, DestPid, SID, OwnerL),
                  rr_recon_stats:inc([{tree_nodesCompared, NComp},
                                      {tree_compareSkipped, NSkip},
                                      {tree_leafsSynced, NLSync},
  