Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: Enable wallet import on pruned nodes #16037

Closed
wants to merge 4 commits into from

Conversation

promag
Copy link
Member

@promag promag commented May 16, 2019

Before this change importwallet fails if any block is pruned. This PR makes it possible to importwallet if all required blocks aren't pruned. This is possible because the dump format includes key timestamps.

src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
@gmaxwell
Copy link
Contributor

The block lookup should be using findFirstBlockWithTime (see RescanFromTime) and allow some slop, because miners could have wrong clocks and users could have wrong clocks, TIMESTAMP_WINDOW, (again see RescanFromTime). This is particularly important for birthdays because installing the software and instantly generating a key, handing it out, and getting paid is a perfectly sensible sequence of events.

Otherwise-- Concept ACK on doing this!

@promag
Copy link
Member Author

promag commented May 16, 2019

I think the best place to test this is in feature_prunning.py, not wallet_dump.py, WDYT?

@maflcko
Copy link
Member

maflcko commented May 16, 2019

Jup. And ideally feature_pruning should run with and without the wallet compiled in, so you can either guard it in feature_pruning behind the test framework check for the wallet or add a new test wallet_pruning.

@promag promag force-pushed the 2019-05-importwallet-pruned branch from 90101d2 to 1b35d83 Compare May 16, 2019 22:52
@promag promag changed the title rpc: Fail importwallet only if a required block is pruned rpc: Early fail import(wallet,multi) when a required block is pruned May 17, 2019
@promag promag force-pushed the 2019-05-importwallet-pruned branch from 1b35d83 to 4a2285f Compare May 17, 2019 14:29
@promag
Copy link
Member Author

promag commented May 17, 2019

Updated to include the same check in importmulti.

@maflcko
Copy link
Member

maflcko commented May 17, 2019

Updated to include the same check in importmulti.

How does that change the error message? Also, the import will happen before the check in importmuli, whereas in importwallet it will happen after.

@promag promag force-pushed the 2019-05-importwallet-pruned branch from 4a2285f to 9066b21 Compare May 17, 2019 17:34
@promag
Copy link
Member Author

promag commented May 17, 2019

the import will happen before the check in importmuli, whereas in importwallet it will happen after.

Now also checking before importing on importmulti.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

utACK 9066b21

Good stuff

src/wallet/rpcdump.cpp Outdated Show resolved Hide resolved
@promag
Copy link
Member Author

promag commented May 17, 2019

Thanks for the review. I'm going to test these changes and add a release note. I'm leaning towards a new test file like you suggested.

BTW is there's a way to change the .blk maximum size?

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 28, 2019

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #17266 (util: Rename DecodeDumpTime to ParseISO8601DateTime by elichai)
  • #17261 (Make ScriptPubKeyMan an actual interface and the wallet to have multiple by achow101)
  • #17260 (Split some CWallet functions into new LegacyScriptPubKeyMan by achow101)
  • #16546 ([WIP] External signer support - Wallet Box edition by Sjors)
  • #16528 ([WIP] Native Descriptor Wallets (take 2) by achow101)

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.

@Sjors
Copy link
Member

Sjors commented Aug 6, 2019

Concept ACK. Travis unhappy.

Suggest renaming the PR to "[rpc] enable wallet import on pruned nodes"

@promag promag force-pushed the 2019-05-importwallet-pruned branch from 6cd0add to cffd615 Compare August 6, 2019 16:02
@promag promag changed the title rpc: Early fail import(wallet,multi) when a required block is pruned rpc: Enable wallet import on pruned nodes Aug 6, 2019
@promag
Copy link
Member Author

promag commented Aug 7, 2019

@Sjors happy travis, and reworded like you suggested, thanks.

static void EnsureBlockDataFromTime(interfaces::Chain::Lock& locked_chain, int64_t timestamp)
{
const Optional<int> height = locked_chain.findFirstBlockWithTimeAndHeight(timestamp - TIMESTAMP_WINDOW, 0, nullptr);
if (height && !locked_chain.haveBlockOnDisk(*height)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we fail if any blocks after this one are pruned too?

Copy link
Member Author

@promag promag Sep 9, 2019

Choose a reason for hiding this comment

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

Is that possible? I mean, if block X is available then X+1 is also available?

Copy link
Member

Choose a reason for hiding this comment

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

Blocks are pruned as entire files, so it's possible block X is in the same file as block X+2, and we don't want to prune block X+2, but we do want to prune block X+1. This can result in block X+1 being pruned before block X.

scripts.push_back(std::pair<CScript, int64_t>(script, birth_time));
}
}
file.close();
if (pwallet->chain().havePruned()) {
Copy link
Member

Choose a reason for hiding this comment

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

Should just check this inside EnsureBlockDataFromTime

@DrahtBot
Copy link
Contributor

Needs rebase

@@ -101,6 +101,14 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver,
}
}

static void EnsureBlockDataFromTime(interfaces::Chain::Lock& locked_chain, int64_t timestamp)
{
const Optional<int> height = locked_chain.findFirstBlockWithTimeAndHeight(timestamp - TIMESTAMP_WINDOW, 0, nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

1 similar comment
@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@maflcko
Copy link
Member

maflcko commented Mar 21, 2022

Marked "up for grabs"

@fanquake
Copy link
Member

Closing given #24865 is open.

@fanquake fanquake closed this Apr 26, 2022
achow101 added a commit that referenced this pull request Dec 16, 2022
564b580 test: Introduce MIN_BLOCKS_TO_KEEP constant (Aurèle Oulès)
71d9a7c test: Wallet imports on pruned nodes (Aurèle Oulès)
e6906fc rpc: Enable wallet import on pruned nodes (Aurèle Oulès)

Pull request description:

  Reopens #16037

  I have rebased the PR, addressed the comments of the original PR and added a functional test.

  > Before this change importwallet fails if any block is pruned. This PR makes it possible to importwallet if all required blocks aren't pruned. This is possible because the dump format includes key timestamps.

  For reviewers:
  `python test/functional/wallet_pruning.py --nocleanup` will generate a large blockchain (~700MB) that can be used to manually test wallet imports on a pruned node. Node0 is not pruned, while node1 is.

ACKs for top commit:
  kouloumos:
    ACK 564b580
  achow101:
    reACK 564b580
  furszy:
    ACK 564b580
  w0xlt:
    ACK 564b580

Tree-SHA512: b345a6c455fcb6581cdaa5f7a55d79e763a55cb08c81d66be5b12794985d79cd51b9b39bdcd0f7ba0a2a2643e9b2ddc49310ff03d16b430df2f74e990800eabf
@bitcoin bitcoin locked and limited conversation to collaborators Apr 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants