Improve wallet sync performance
This commit is contained in:
parent
966b5bb989
commit
6f183f7eee
|
@ -5262,7 +5262,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"electron-osx-sign": {
|
"electron-osx-sign": {
|
||||||
"version": "github:electron/electron-osx-sign#877226b5198f2ed9661129ea56a1ea048c4c55ae",
|
"version": "github:electron/electron-osx-sign#6ba45b2deec3f4f3629010645f92e6506df133ee",
|
||||||
"from": "github:electron/electron-osx-sign#master",
|
"from": "github:electron/electron-osx-sign#master",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
|
@ -613,6 +613,7 @@ const Farmer = props => {
|
||||||
const classes = props.classes;
|
const classes = props.classes;
|
||||||
|
|
||||||
const checkRewards = useCallback(async () => {
|
const checkRewards = useCallback(async () => {
|
||||||
|
console.log("Checking rewards");
|
||||||
let totalChia = BigInt(0);
|
let totalChia = BigInt(0);
|
||||||
let biggestHeight = 0;
|
let biggestHeight = 0;
|
||||||
for (let wallet of wallets) {
|
for (let wallet of wallets) {
|
||||||
|
@ -624,6 +625,7 @@ const Farmer = props => {
|
||||||
if (tx.additions.length < 1) {
|
if (tx.additions.length < 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
console.log("Checking tx", tx);
|
||||||
// Height here is filled into the whole 256 bits (32 bytes) of the parent
|
// Height here is filled into the whole 256 bits (32 bytes) of the parent
|
||||||
let hexHeight = arr_to_hex(
|
let hexHeight = arr_to_hex(
|
||||||
big_int_to_array(BigInt(tx.confirmed_at_index), 32)
|
big_int_to_array(BigInt(tx.confirmed_at_index), 32)
|
||||||
|
|
|
@ -55,7 +55,7 @@ from src.util.hash import std_hash
|
||||||
from src.util.ints import uint32, uint64, uint128
|
from src.util.ints import uint32, uint64, uint128
|
||||||
from src.util.merkle_set import MerkleSet
|
from src.util.merkle_set import MerkleSet
|
||||||
from src.util.path import mkdir, path_from_root
|
from src.util.path import mkdir, path_from_root
|
||||||
from src.types.peer_info import PeerInfo, TimestampedPeerInfo
|
from src.types.peer_info import PeerInfo
|
||||||
|
|
||||||
OutboundMessageGenerator = AsyncGenerator[OutboundMessage, None]
|
OutboundMessageGenerator = AsyncGenerator[OutboundMessage, None]
|
||||||
|
|
||||||
|
@ -1725,11 +1725,7 @@ class FullNode:
|
||||||
) -> OutboundMessageGenerator:
|
) -> OutboundMessageGenerator:
|
||||||
if self.global_connections is None:
|
if self.global_connections is None:
|
||||||
return
|
return
|
||||||
tmp_connected_peers = self.global_connections.get_full_node_peerinfos()
|
connected_peers = self.global_connections.get_full_node_peerinfos()
|
||||||
connected_peers = [
|
|
||||||
TimestampedPeerInfo(peer.host, peer.port, uint64(0))
|
|
||||||
for peer in tmp_connected_peers
|
|
||||||
]
|
|
||||||
unconnected_peers = self.global_connections.peers.get_peers(
|
unconnected_peers = self.global_connections.peers.get_peers(
|
||||||
recent_threshold=24 * 60 * 60
|
recent_threshold=24 * 60 * 60
|
||||||
)
|
)
|
||||||
|
|
|
@ -177,6 +177,24 @@ class WalletPuzzleStore:
|
||||||
|
|
||||||
return row is not None
|
return row is not None
|
||||||
|
|
||||||
|
async def one_of_puzzle_hashes_exists(self, puzzle_hashes: List[bytes32]) -> bool:
|
||||||
|
"""
|
||||||
|
Checks if one of the passed puzzle_hashes is present in the db.
|
||||||
|
"""
|
||||||
|
if len(puzzle_hashes) < 1:
|
||||||
|
return False
|
||||||
|
puzzle_hashes_db = tuple([ph.hex() for ph in puzzle_hashes])
|
||||||
|
formatted_str = (
|
||||||
|
f"SELECT * from derivation_paths WHERE puzzle_hash in "
|
||||||
|
f'({"?," * (len(puzzle_hashes_db) - 1)}?) LIMIT 1'
|
||||||
|
)
|
||||||
|
cursor = await self.db_connection.execute(formatted_str, puzzle_hashes_db)
|
||||||
|
|
||||||
|
row = await cursor.fetchone()
|
||||||
|
await cursor.close()
|
||||||
|
|
||||||
|
return row is not None
|
||||||
|
|
||||||
async def index_for_pubkey(self, pubkey: G1Element) -> Optional[uint32]:
|
async def index_for_pubkey(self, pubkey: G1Element) -> Optional[uint32]:
|
||||||
"""
|
"""
|
||||||
Returns derivation paths for the given pubkey.
|
Returns derivation paths for the given pubkey.
|
||||||
|
|
|
@ -790,17 +790,22 @@ class WalletStateManager:
|
||||||
self.block_records[block.header_hash] = block
|
self.block_records[block.header_hash] = block
|
||||||
await self.wallet_store.add_block_record(block, False)
|
await self.wallet_store.add_block_record(block, False)
|
||||||
|
|
||||||
async with self.puzzle_store.lock:
|
# If one of these new additions is ours, generate more puzzle hashes
|
||||||
for addition in block.additions:
|
phs: List[bytes32] = [addition.puzzle_hash for addition in block.additions]
|
||||||
record = await self.puzzle_store.get_derivation_record_for_puzzle_hash(
|
block_includes_our_tx: bool = await self.puzzle_store.one_of_puzzle_hashes_exists(
|
||||||
addition.puzzle_hash.hex()
|
phs
|
||||||
)
|
)
|
||||||
if record is None:
|
if block_includes_our_tx:
|
||||||
continue
|
async with self.puzzle_store.lock:
|
||||||
index = record.index
|
for addition in block.additions:
|
||||||
await self.puzzle_store.set_used_up_to(index)
|
record = await self.puzzle_store.get_derivation_record_for_puzzle_hash(
|
||||||
|
addition.puzzle_hash.hex()
|
||||||
await self.create_more_puzzle_hashes()
|
)
|
||||||
|
if record is None:
|
||||||
|
continue
|
||||||
|
index = record.index
|
||||||
|
await self.puzzle_store.set_used_up_to(index)
|
||||||
|
await self.create_more_puzzle_hashes()
|
||||||
|
|
||||||
# Genesis case
|
# Genesis case
|
||||||
if self.lca is None:
|
if self.lca is None:
|
||||||
|
|
|
@ -67,6 +67,18 @@ class TestPuzzleStore:
|
||||||
await db.add_derivation_paths(derivation_recs)
|
await db.add_derivation_paths(derivation_recs)
|
||||||
|
|
||||||
assert await db.puzzle_hash_exists(derivation_recs[0].puzzle_hash) is True
|
assert await db.puzzle_hash_exists(derivation_recs[0].puzzle_hash) is True
|
||||||
|
|
||||||
|
phs_1 = [derivation_recs[0].puzzle_hash]
|
||||||
|
phs_2 = [32 * bytes([1]), derivation_recs[0].puzzle_hash]
|
||||||
|
phs_3 = [derivation_recs[0].puzzle_hash, 32 * bytes([1])]
|
||||||
|
phs_4 = [32 * bytes([1]), 32 * bytes([2])]
|
||||||
|
phs_5 = []
|
||||||
|
assert await db.one_of_puzzle_hashes_exists(phs_1) is True
|
||||||
|
assert await db.one_of_puzzle_hashes_exists(phs_2) is True
|
||||||
|
assert await db.one_of_puzzle_hashes_exists(phs_3) is True
|
||||||
|
assert await db.one_of_puzzle_hashes_exists(phs_4) is False
|
||||||
|
assert await db.one_of_puzzle_hashes_exists(phs_5) is False
|
||||||
|
|
||||||
assert await db.index_for_pubkey(derivation_recs[4].pubkey) == 2
|
assert await db.index_for_pubkey(derivation_recs[4].pubkey) == 2
|
||||||
assert await db.index_for_puzzle_hash(derivation_recs[2].puzzle_hash) == 1
|
assert await db.index_for_puzzle_hash(derivation_recs[2].puzzle_hash) == 1
|
||||||
assert await db.wallet_info_for_puzzle_hash(
|
assert await db.wallet_info_for_puzzle_hash(
|
||||||
|
|
Loading…
Reference in New Issue