Skip to content

Conversation

junderw
Copy link
Contributor

@junderw junderw commented Jan 29, 2022

fixes #24188 (also see #22762 (comment))
When downgrading, a peers.dat with a future version that has a minimum
required version larger than the downgraded Bitcoin Core version would cause an InitError.

This commit changes this behavior to overwrite the existing peers.dat with
a new empty one.

@junderw
Copy link
Contributor Author

junderw commented Jan 29, 2022

Part of the reason why I am using strncmp is because AddrMan (AddrManImpl) -> Unserialize might be called somewhere else, so I didn't want to touch it.

I should probably re-work AddrManImpl to use a new exception class that wraps around std::ios_base::failure and only throw exception in the case of version mismatch... but I wanted to get feedback first.

@maflcko
Copy link
Member

maflcko commented Jan 29, 2022

Yeah, I think it should be thrown directly where the version is read

@DrahtBot DrahtBot added the P2P label Jan 29, 2022
@junderw
Copy link
Contributor Author

junderw commented Jan 29, 2022

Fixed.

Also, 2 jobs on the first commit's CI have been running for 10 hours... is this caused by my strncmp?

@junderw
Copy link
Contributor Author

junderw commented Jan 30, 2022

On second look, I wonder if we should also LogPrintf the e.what() right before we LogPrintf "Creating new peers.dat..."?

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 96c9d9c

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO should be squashed

@junderw
Copy link
Contributor Author

junderw commented Feb 6, 2022

Squashed.

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, w/ some thoughts for improvement (can be followups)

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 11, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24312 (addrman: Log too low compat value by MarcoFalke)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@junderw junderw changed the title p2p: Avoid InitError when downgrading peers.dat WIP: p2p: Avoid InitError when downgrading peers.dat Feb 20, 2022
@maflcko maflcko added this to the 23.0 milestone Feb 21, 2022
@maflcko
Copy link
Member

maflcko commented Feb 21, 2022

Assigned 23.0

@michaelfolkson
Copy link

@junderw: Can you explain why you made this WIP? One of multiple considerations for whether it should be included in the 23.0 milestone or not.

@junderw junderw changed the title WIP: p2p: Avoid InitError when downgrading peers.dat p2p: Avoid InitError when downgrading peers.dat Feb 24, 2022
@junderw
Copy link
Contributor Author

junderw commented Feb 24, 2022

Sorry, I misunderstood. I made it WIP because I thought I still hadn't finished all the outstanding issues with the PR.

After reviewing my own commit I understand I was just confused.

There's a spelling error I'll fix right now.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 772c9ba

nit:

  1. Not sure about squashing of some commits or the order and type
  2. Suggestion by @luke-jr still not addressed to change peer to peers

@junderw
Copy link
Contributor Author

junderw commented Feb 24, 2022

Unrelated test failed for some reason.

@ghost
Copy link

ghost commented Feb 24, 2022

Unrelated test failed for some reason.

I don't think that's an issue

Maybe you can follow 1 or 2 or both:

  1. Squash commits according to docs
  2. Have 2 commits:
    1st commit: net (src/addrman.h , src/addrman.cpp and src/addrdb.cpp)
    
    2nd commit: test (test/functional/feature_addrman.py)
    

fixes bitcoin#24188
When downgrading, a peers.dat with a future version that has a minimum
required version larger than the downgraded version would cause an InitError.

This commit changes this behavior to overwrite the existing peers.dat with
a new empty one, while creating a backup in peers.dat.bak.
@junderw
Copy link
Contributor Author

junderw commented Feb 25, 2022

Squashed all commits into one.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK d41ed32

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK d41ed32

@maflcko maflcko merged commit b00b60e into bitcoin:master Feb 25, 2022
@michaelfolkson
Copy link

Sorry for the confusion @junderw :) Great to see this has been merged. Thanks!

@junderw junderw deleted the fixes/24188 branch February 25, 2022 11:34
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 25, 2022
d41ed32 p2p: Avoid InitError when downgrading peers.dat (junderw)

Pull request description:

  fixes bitcoin#24188 (also see bitcoin#22762 (comment))
  When downgrading, a peers.dat with a future version that has a minimum
  required version larger than the downgraded Bitcoin Core version would cause an InitError.

  This commit changes this behavior to overwrite the existing peers.dat with
  a new empty one.

ACKs for top commit:
  prayank23:
    reACK bitcoin@d41ed32
  kallewoof:
    reACK d41ed32

Tree-SHA512: c8e625fe36ce0b1aab6c8ef7241c8954038bb856f2de27bdc4814dc9a60e51be28815c7d77d0f96eace49687a0cea02deb713978bbd3a5add742f50a675f2a40
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 21, 2022
Summary:
```
When downgrading, a peers.dat with a future version that has a minimum required version larger than the downgraded version would cause an InitError.

This commit changes this behavior to overwrite the existing peers.dat with a new empty one, while creating a backup in peers.dat.bak.
```

Backport of [[bitcoin/bitcoin#24201 | core#24201]].

This can't be used with the recent v4 format update but will make for a better UX if the peers.dat format is changed in the future.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D12348
@bitcoin bitcoin locked and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid InitError when downgrading peers.dat
6 participants