Merge branch 'beta-1.4' of github.com:Chia-Network/chia-blockchain into wallet-tests

This commit is contained in:
Mariano Sorgente 2020-04-28 12:37:01 +09:00
commit d88fa32746
No known key found for this signature in database
GPG Key ID: 0F866338C369278C
8 changed files with 76 additions and 55 deletions

View File

@ -4,7 +4,7 @@ We are happy that you are taking a look at the code for Chia, a proof of space a
A lot of fascinating new cryptography and blockchain concepts are used and implemented here.
This repo includes the code for the Chia full node, farmer, and timelord (in src), which are all written in python.
It also includes a verifiable delay function implementation under lib/chiavdf (in c/c++), and a proof of space implementation under lib/chiapos.
It also includes a verifiable delay function implementation that it imports from the [chiavdf repo](https://github.com/Chia-Network/chiavdf) (in c/c++), and a proof of space implementation that it imports from the [chiapos repo](https://github.com/Chia-Network/chiapos). BLS signatures are imported from the [bls-signatures repo](https://github.com/Chia-Network/bls-signatures) as blspy. There is an additional dependency on the [chiabip158 repo](https://github.com/Chia-Network/chiabip158). For major platforms, binary and source wheels are shipped to PyPI from each dependent repo and then chia-blockchain can pip install those from PyPI or they can be prepackaged as is done for the Windows installer. On unsupported ploatforms, pip will fall back to the source distributions to be compiled locally.
If you want to learn more about this project, read the [wiki](https://github.com/Chia-Network/chia-blockchain/wiki), or check out the [green paper](https://www.chia.net/assets/ChiaGreenPaper.pdf).

View File

@ -22,8 +22,12 @@ if ($LastExitCode) { exit $LastExitCode }
.\build-bundle.ps1
if ($LastExitCode) { exit $LastExitCode }
Write-Host "Succesfully built Chia installer for $env:version"
Write-Host "Successfully built Chia installer for $env:version"
New-Item -ItemType Directory -Path "$finalDir"
Copy-Item "$buildDir\*.msi" "$finalDir\" -Force
Copy-Item "$buildDir\*.exe" "$finalDir\" -Force
Copy-Item ".\blockchain\*.whl" "$blockchainDir\wheels" -Force
dir ".\blockchain\*.whl"
# Put a .zip of windows-wheels in Artifacts
Compress-Archive -Path ".\blockchain" -DestinationPath "$finalDir\windows-wheels.zip" -Force

View File

@ -21,9 +21,9 @@ def main():
key_config_filename = config_path_for_filename(root_path, "keys.yaml")
parser = argparse.ArgumentParser(description="Chia plotting script.")
parser.add_argument("-k", "--size", help="Plot size", type=int, default=20)
parser.add_argument("-k", "--size", help="Plot size", type=int, default=26)
parser.add_argument(
"-n", "--num_plots", help="Number of plots", type=int, default=10
"-n", "--num_plots", help="Number of plots", type=int, default=1
)
parser.add_argument("-i", "--index", help="First plot index", type=int, default=0)
parser.add_argument(

View File

@ -158,8 +158,11 @@ class Harvester:
raise ValueError(
f"Invalid challenge size {challenge_size}, 32 was expected"
)
all_responses = []
for filename, prover in self.provers.items():
async def lookup_challenge(
filename: Path, prover: DiskProver
) -> List[harvester_protocol.ChallengeResponse]:
all_responses: List[harvester_protocol.ChallengeResponse] = []
try:
quality_strings = prover.get_qualities_for_challenge(
new_challenge.challenge_hash
@ -187,12 +190,21 @@ class Harvester:
new_challenge.challenge_hash, quality_str, prover.get_size()
)
all_responses.append(response)
for response in all_responses:
yield OutboundMessage(
NodeType.FARMER,
Message("challenge_response", response),
Delivery.RESPOND,
)
return all_responses
awaitables = [
lookup_challenge(filename, prover)
for filename, prover in self.provers.items()
]
# Concurrently executes all lookups on disk, to take advantage of multiple disk parallelism
for sublist_awaitable in asyncio.as_completed(awaitables):
for response in await sublist_awaitable:
yield OutboundMessage(
NodeType.FARMER,
Message("challenge_response", response),
Delivery.RESPOND,
)
@api_request
async def request_proof_of_space(

View File

@ -293,20 +293,3 @@ class WalletPuzzleStore:
return uint32(row[0])
return None
async def get_unused_derivation_path_for_wallet(
self, wallet_id: int
) -> Optional[uint32]:
"""
Returns the first unused derivation path by derivation_index.
"""
cursor = await self.db_connection.execute(
f"SELECT MIN(derivation_index) FROM derivation_paths WHERE used=0 and wallet_id={wallet_id};"
)
row = await cursor.fetchone()
await cursor.close()
if row is not None and row[0] is not None:
return uint32(row[0])
return None

View File

@ -207,48 +207,41 @@ class WalletStateManager:
private = self.private_key.private_child(index_for_puzzlehash).get_private_key()
return pubkey, private
async def create_more_puzzle_hashes(
self, from_zero: bool = False, for_wallet: Any = None
):
async def create_more_puzzle_hashes(self, from_zero: bool = False):
"""
For all wallets in the user store, generates the first few puzzle hashes so
that we can restore the wallet from only the private keys.
"""
targets = list(self.wallets.keys())
if for_wallet is None:
targets = list(self.wallets.keys())
else:
targets = [for_wallet]
unused: Optional[uint32] = await self.puzzle_store.get_unused_derivation_path()
if unused is None:
# This handles the case where the database has entries but they have all been used
unused = await self.puzzle_store.get_last_derivation_path()
if unused is None:
# This handles the case where the database is empty
unused = uint32(0)
to_generate = 100
for wallet_id in targets:
target_wallet = self.wallets[wallet_id]
unused: Optional[
uint32
] = await self.puzzle_store.get_unused_derivation_path_for_wallet(wallet_id)
last: Optional[
uint32
] = await self.puzzle_store.get_last_derivation_path_for_wallet(wallet_id)
if target_wallet.wallet_info.type == WalletType.COLOURED_COIN:
to_generate = 100
else:
to_generate = 500
start_index = 0
derivation_paths: List[DerivationRecord] = []
if last is None:
assert unused is None
if unused is not None:
assert last is not None
if last is not None:
start_index = last + 1
to_generate -= last - unused
# If the key was replaced (from_zero=True), we should generate the puzzle hashes for the new key
end = start_index + to_generate
if from_zero:
start_index = 0
for index in range(start_index, end):
for index in range(start_index, unused + to_generate):
pubkey: PublicKey = self.get_public_key(uint32(index))
puzzle: Program = target_wallet.puzzle_for_pk(bytes(pubkey))
puzzlehash: bytes32 = puzzle.get_tree_hash()
@ -266,8 +259,8 @@ class WalletStateManager:
)
await self.puzzle_store.add_derivation_paths(derivation_paths)
if from_zero and unused is not None and unused > 0:
await self.puzzle_store.set_used_up_to(uint32(unused - 1))
if unused > 0:
await self.puzzle_store.set_used_up_to(uint32(unused - 1))
async def get_unused_derivation_record(self, wallet_id: uint32) -> DerivationRecord:
"""
@ -279,9 +272,9 @@ class WalletStateManager:
# If we have no unused public keys, we will create new ones
unused: Optional[
uint32
] = await self.puzzle_store.get_unused_derivation_path_for_wallet(wallet_id)
] = await self.puzzle_store.get_unused_derivation_path()
if unused is None:
await self.create_more_puzzle_hashes(for_wallet=wallet_id)
await self.create_more_puzzle_hashes()
# Now we must have unused public keys
unused = await self.puzzle_store.get_unused_derivation_path()
@ -1340,7 +1333,7 @@ class WalletStateManager:
async def add_new_wallet(self, wallet: Any, id: int):
self.wallets[uint32(id)] = wallet
await self.create_more_puzzle_hashes(for_wallet=id)
await self.create_more_puzzle_hashes()
async def get_spendable_coins_for_wallet(
self, wallet_id: int

View File

@ -27,6 +27,7 @@ from src.simulator.simulator_constants import test_constants
from src.simulator.simulator_protocol import FarmNewBlockProtocol
from src.util.config import load_config_cli, load_config
from src.util.ints import uint64
from src.types.sized_bytes import bytes32
from src.util.logging import initialize_logging
from src.wallet.util.wallet_types import WalletType
from src.wallet.rl_wallet.rl_wallet import RLWallet

View File

@ -133,7 +133,11 @@ class TestWalletSimulator:
await self.time_out_assert(15, cc_wallet.get_confirmed_balance, 100)
await self.time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100)
<<<<<<< HEAD
assert cc_wallet.cc_info.my_core is not None
=======
assert cc_wallet.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
colour = cc_wallet_puzzles.get_genesis_from_core(cc_wallet.cc_info.my_core)
cc_wallet_2: CCWallet = await CCWallet.create_wallet_for_cc(
@ -236,7 +240,11 @@ class TestWalletSimulator:
await self.time_out_assert(15, cc_wallet.get_confirmed_balance, 100)
await self.time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100)
<<<<<<< HEAD
assert cc_wallet.cc_info.my_core is not None
=======
assert cc_wallet.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
colour = cc_wallet_puzzles.get_genesis_from_core(cc_wallet.cc_info.my_core)
cc_wallet_2: CCWallet = await CCWallet.create_wallet_for_cc(
@ -296,7 +304,11 @@ class TestWalletSimulator:
await self.time_out_assert(15, cc_wallet.get_confirmed_balance, 100)
await self.time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100)
<<<<<<< HEAD
assert cc_wallet.cc_info.my_core is not None
=======
assert cc_wallet.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
colour = cc_wallet_puzzles.get_genesis_from_core(cc_wallet.cc_info.my_core)
cc_wallet_2: CCWallet = await CCWallet.create_wallet_for_cc(
@ -384,7 +396,11 @@ class TestWalletSimulator:
await self.time_out_assert(15, cc_wallet.get_confirmed_balance, 100)
await self.time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100)
<<<<<<< HEAD
assert cc_wallet.cc_info.my_core is not None
=======
assert cc_wallet.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
colour = cc_wallet_puzzles.get_genesis_from_core(cc_wallet.cc_info.my_core)
cc_wallet_2: CCWallet = await CCWallet.create_wallet_for_cc(
@ -458,7 +474,11 @@ class TestWalletSimulator:
await self.time_out_assert(15, red_wallet.get_confirmed_balance, 100)
await self.time_out_assert(15, red_wallet.get_unconfirmed_balance, 100)
<<<<<<< HEAD
assert red_wallet.cc_info.my_core is not None
=======
assert red_wallet.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
red = cc_wallet_puzzles.get_genesis_from_core(red_wallet.cc_info.my_core)
await full_node_1.farm_new_block(FarmNewBlockProtocol(ph2))
@ -471,7 +491,11 @@ class TestWalletSimulator:
for i in range(1, num_blocks):
await full_node_1.farm_new_block(FarmNewBlockProtocol(ph))
<<<<<<< HEAD
assert blue_wallet_2.cc_info.my_core is not None
=======
assert blue_wallet_2.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
blue = cc_wallet_puzzles.get_genesis_from_core(blue_wallet_2.cc_info.my_core)
red_wallet_2: CCWallet = await CCWallet.create_wallet_for_cc(
@ -576,7 +600,11 @@ class TestWalletSimulator:
await self.time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100)
await self.time_out_assert(15, cc_wallet.get_confirmed_balance, 100)
<<<<<<< HEAD
assert cc_wallet.cc_info.my_core is not None
=======
assert cc_wallet.cc_info.my_core
>>>>>>> efc3113afac720de5e9da011cff5d96cdc96cf1c
colour = cc_wallet_puzzles.get_genesis_from_core(cc_wallet.cc_info.my_core)
cc_wallet_2: CCWallet = await CCWallet.create_wallet_for_cc(