Skip to content

Add fallback trying of both known and new peers#555

Merged
rustaceanrob merged 1 commit into2140-dev:masterfrom
randomlogin:peer-persistance-fix
Mar 18, 2026
Merged

Add fallback trying of both known and new peers#555
rustaceanrob merged 1 commit into2140-dev:masterfrom
randomlogin:peer-persistance-fix

Conversation

@randomlogin
Copy link
Copy Markdown
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.

@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
@rustaceanrob
Copy link
Copy Markdown
Collaborator

Please squash these into a single commit

@rustaceanrob
Copy link
Copy Markdown
Collaborator

Can we remove this test. I'm convinced this resolves the problem and further this is a regtest-only issue.

@randomlogin randomlogin force-pushed the peer-persistance-fix branch from c4a2d19 to 49b2a32 Compare March 18, 2026 13:12
@randomlogin randomlogin reopened this Mar 18, 2026
@randomlogin randomlogin force-pushed the peer-persistance-fix branch from d4e1081 to e096884 Compare March 18, 2026 13:16
@rustaceanrob
Copy link
Copy Markdown
Collaborator

ACK e096884

Thanks

@rustaceanrob rustaceanrob merged commit a9419f5 into 2140-dev:master Mar 18, 2026
10 checks passed
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.

2 participants