Fixed the wallet db rename from v2/v1 to v2_r1.

Removed vestigial code for dealing with the lite wallet db now that
we're syncing v2_r1 from scratch.
This commit is contained in:
Jeff Cruikshank
2022-07-19 15:12:01 -07:00
parent 416337ef8f
commit 3dfc3707da
3 changed files with 69 additions and 19 deletions
-3
View File
@@ -2,8 +2,5 @@ import os
from pathlib import Path
DEFAULT_ROOT_PATH = Path(os.path.expanduser(os.getenv("CHIA_ROOT", "~/.chia/mainnet"))).resolve()
STANDALONE_ROOT_PATH = Path(
os.path.expanduser(os.getenv("CHIA_STANDALONE_WALLET_ROOT", "~/.chia/standalone_wallet"))
).resolve()
DEFAULT_KEYS_ROOT_PATH = Path(os.path.expanduser(os.getenv("CHIA_KEYS_ROOT", "~/.chia_keys"))).resolve()
+18 -14
View File
@@ -48,7 +48,6 @@ from chia.types.weight_proof import SubEpochData, WeightProof
from chia.util.byte_types import hexstr_to_bytes
from chia.util.chunks import chunks
from chia.util.config import WALLET_PEERS_PATH_KEY_DEPRECATED
from chia.util.default_root import STANDALONE_ROOT_PATH
from chia.util.ints import uint32, uint64
from chia.util.keychain import Keychain, KeyringIsLocked
from chia.util.path import mkdir, path_from_root
@@ -70,6 +69,23 @@ from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_state_manager import WalletStateManager
def get_wallet_db_path(root_path: Path, config: Dict[str, Any], key_fingerprint: str) -> Path:
"""
Construct a path to the wallet db. Uses config values and the wallet key's fingerprint to
determine the wallet db filename.
"""
db_path_replaced: str = (
config["database_path"].replace("CHALLENGE", config["selected_network"]).replace("KEY", key_fingerprint)
)
# "v2_r1" is the current wallet db version identifier
if "v2_r1" not in db_path_replaced:
db_path_replaced = db_path_replaced.replace("v2", "v2_r1").replace("v1", "v2_r1")
path: Path = path_from_root(root_path, db_path_replaced)
return path
class WalletNode:
key_config: Dict
config: Dict
@@ -195,21 +211,9 @@ class WalletNode:
if self.config.get("enable_profiler", False):
asyncio.create_task(profile_task(self.root_path, "wallet", self.log))
db_path_key_suffix = str(private_key.get_g1().get_fingerprint())
db_path_replaced: str = (
self.config["database_path"]
.replace("CHALLENGE", self.config["selected_network"])
.replace("KEY", db_path_key_suffix)
)
path = path_from_root(self.root_path, db_path_replaced.replace("v1", "v2_r1"))
path: Path = get_wallet_db_path(self.root_path, self.config, str(private_key.get_g1().get_fingerprint()))
mkdir(path.parent)
standalone_path = path_from_root(STANDALONE_ROOT_PATH, f"{db_path_replaced.replace('v2_r1', 'v1')}_new")
if not path.exists():
if standalone_path.exists():
self.log.info(f"Copying wallet db from {standalone_path} to {path}")
path.write_bytes(standalone_path.read_bytes())
assert self.server is not None
self.wallet_state_manager = await WalletStateManager.create(
private_key,
+51 -2
View File
@@ -1,6 +1,7 @@
import asyncio
import time
from typing import List, Tuple
from pathlib import Path
from typing import Any, Dict, List, Tuple
import pytest
@@ -18,7 +19,7 @@ from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.util.wallet_types import AmountWithPuzzlehash
from chia.wallet.wallet_node import WalletNode
from chia.wallet.wallet_node import WalletNode, get_wallet_db_path
from chia.wallet.wallet_state_manager import WalletStateManager
from tests.pools.test_pool_rpc import wallet_is_synced
from tests.time_out_assert import time_out_assert, time_out_assert_not_none
@@ -910,3 +911,51 @@ class TestWalletSimulator:
await time_out_assert(5, wallet.get_confirmed_balance, funds - AMOUNT_TO_SEND)
await time_out_assert(5, wallet.get_unconfirmed_balance, funds - AMOUNT_TO_SEND)
def test_get_wallet_db_path_v2_r1() -> None:
root_path: Path = Path("/x/y/z/.chia/mainnet")
config: Dict[str, Any] = {
"database_path": "wallet/db/blockchain_wallet_v2_r1_CHALLENGE_KEY.sqlite",
"selected_network": "mainnet",
}
fingerprint: str = "1234567890"
wallet_db_path: Path = get_wallet_db_path(root_path, config, fingerprint)
assert wallet_db_path == Path("/x/y/z/.chia/mainnet/wallet/db/blockchain_wallet_v2_r1_mainnet_1234567890.sqlite")
def test_get_wallet_db_path_v2() -> None:
root_path: Path = Path("/x/y/z/.chia/mainnet")
config: Dict[str, Any] = {
"database_path": "wallet/db/blockchain_wallet_v2_CHALLENGE_KEY.sqlite",
"selected_network": "mainnet",
}
fingerprint: str = "1234567890"
wallet_db_path: Path = get_wallet_db_path(root_path, config, fingerprint)
assert wallet_db_path == Path("/x/y/z/.chia/mainnet/wallet/db/blockchain_wallet_v2_r1_mainnet_1234567890.sqlite")
def test_get_wallet_db_path_v1() -> None:
root_path: Path = Path("/x/y/z/.chia/mainnet")
config: Dict[str, Any] = {
"database_path": "wallet/db/blockchain_wallet_v1_CHALLENGE_KEY.sqlite",
"selected_network": "mainnet",
}
fingerprint: str = "1234567890"
wallet_db_path: Path = get_wallet_db_path(root_path, config, fingerprint)
assert wallet_db_path == Path("/x/y/z/.chia/mainnet/wallet/db/blockchain_wallet_v2_r1_mainnet_1234567890.sqlite")
def test_get_wallet_db_path_testnet() -> None:
root_path: Path = Path("/x/y/z/.chia/testnet")
config: Dict[str, Any] = {
"database_path": "wallet/db/blockchain_wallet_v2_CHALLENGE_KEY.sqlite",
"selected_network": "testnet",
}
fingerprint: str = "1234567890"
wallet_db_path: Path = get_wallet_db_path(root_path, config, fingerprint)
assert wallet_db_path == Path("/x/y/z/.chia/testnet/wallet/db/blockchain_wallet_v2_r1_testnet_1234567890.sqlite")