Skip to content

Add fallback trying of both known and new peers#555

Open
randomlogin wants to merge 2 commits into2140-dev:masterfrom
randomlogin:peer-persistance-fix
Open

Add fallback trying of both known and new peers#555
randomlogin wants to merge 2 commits into2140-dev:masterfrom
randomlogin:peer-persistance-fix

Conversation

@randomlogin
Copy link
Contributor

@randomlogin randomlogin commented Mar 18, 2026

Encountered on regtest. Probably not common for a live network as we hopefully can easily find a new peer.

Previously it was the following:

    pub(crate) fn select(&self) -> Option<Record> {
        if self.tried.is_empty() && self.new.is_empty() {
            return None;
        }
        let use_tried: bool = rand::random();
        if use_tried && !self.tried.is_empty() {
            return self.tried.select();
        }
        self.new.select()
    }

If tried.is_empty() = false and new.is_empty() = true we skip the first if, then we randomly choose use_tried = false then we skip the second if down to self.new.select() which fails as new.is_empty() = true.

Effectively this means if we cannot find a new peer there is a 50% chance we would not use the known ones and fail.

Not sure if we need a distinct test for that.

AddressBook randomly choses use new or known peers, previously we didn't
fallback to the known if we chose the new ones and the new happened to be
empty.
@randomlogin randomlogin deleted the peer-persistance-fix branch March 18, 2026 02:01
@randomlogin randomlogin restored the peer-persistance-fix branch March 18, 2026 02:02
@randomlogin randomlogin reopened this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant