@@ -1930,18 +1930,23 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1930
1930
1931
1931
ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
1932
1932
int64_t nTime = GetTimeMicros ();
1933
+ bool anchor = false ;
1933
1934
bool fFeeler = false ;
1934
1935
1935
1936
// Determine what type of connection to open. Opening
1936
- // OUTBOUND_FULL_RELAY connections gets the highest priority until we
1937
+ // BLOCK_RELAY connections to addresses from anchors.dat gets the highest
1938
+ // priority. Then we open OUTBOUND_FULL_RELAY priority until we
1937
1939
// meet our full-relay capacity. Then we open BLOCK_RELAY connection
1938
1940
// until we hit our block-relay-only peer limit.
1939
1941
// GetTryNewOutboundPeer() gets set when a stale tip is detected, so we
1940
1942
// try opening an additional OUTBOUND_FULL_RELAY connection. If none of
1941
1943
// these conditions are met, check the nNextFeeler timer to decide if
1942
1944
// we should open a FEELER.
1943
1945
1944
- if (nOutboundFullRelay < m_max_outbound_full_relay) {
1946
+ if (!m_anchors.empty () && (nOutboundBlockRelay < m_max_outbound_block_relay)) {
1947
+ conn_type = ConnectionType::BLOCK_RELAY;
1948
+ anchor = true ;
1949
+ } else if (nOutboundFullRelay < m_max_outbound_full_relay) {
1945
1950
// OUTBOUND_FULL_RELAY
1946
1951
} else if (nOutboundBlockRelay < m_max_outbound_block_relay) {
1947
1952
conn_type = ConnectionType::BLOCK_RELAY;
@@ -1962,6 +1967,17 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1962
1967
int nTries = 0 ;
1963
1968
while (!interruptNet)
1964
1969
{
1970
+ if (anchor && !m_anchors.empty ()) {
1971
+ const CAddress addr = m_anchors.back ();
1972
+ m_anchors.pop_back ();
1973
+ if (!addr.IsValid () || IsLocal (addr) || !IsReachable (addr) ||
1974
+ !HasAllDesirableServiceFlags (addr.nServices ) ||
1975
+ setConnected.count (addr.GetGroup (addrman.m_asmap ))) continue ;
1976
+ addrConnect = addr;
1977
+ LogPrint (BCLog::NET, " Trying to make an anchor connection to %s\n " , addrConnect.ToString ());
1978
+ break ;
1979
+ }
1980
+
1965
1981
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
1966
1982
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
1967
1983
// already-connected network ranges, ...) before trying new addrman addresses.
0 commit comments