Fix error in VDF server

This commit is contained in:
Mariano Sorgente 2020-02-06 19:56:00 -05:00
parent 672234a105
commit 893e2198fd
No known key found for this signature in database
GPG Key ID: 0F866338C369278C
8 changed files with 28 additions and 20 deletions

View File

@ -22,6 +22,7 @@ jobs:
run: |
brew update && brew install gmp boost || echo ""
sh install.sh
sh install_timelord.sh
- name: Test proof of space
run: |
cd lib/chiapos

View File

@ -16,9 +16,6 @@ void CreateAndWriteProof(integer D, form x, int64_t num_iterations, WesolowskiCa
PrintInfo("Got stop signal before completing the proof!");
return ;
}
// Write "WESO" marker
boost::asio::write(sock, boost::asio::buffer("WESO", 4));
// Writes the number of iterations
std::vector<unsigned char> bytes = ConvertIntegerToBytes(integer(num_iterations), 8);
@ -32,9 +29,11 @@ void CreateAndWriteProof(integer D, form x, int64_t num_iterations, WesolowskiCa
bytes.insert(bytes.end(), proof_size.begin(), proof_size.end());
bytes.insert(bytes.end(), result.proof.begin(), result.proof.end());
std::string str_result = BytesToStr(bytes);
std::string str_result = "WESO" + BytesToStr(bytes);
std::lock_guard<std::mutex> lock(socket_mutex);
PrintInfo("Generated proof = " + str_result);;
// Write "WESO" marker
// boost::asio::write(sock, boost::asio::buffer("WESO", 4));
boost::asio::write(sock, boost::asio::buffer(str_result.c_str(), str_result.size()));
}

View File

@ -13,9 +13,7 @@ def create_puzzlehash_for_pk(pub_key: BLSPublicKey) -> bytes32:
def signature_for_coinbase(coin: Coin, pool_private_key: blspy.PrivateKey):
message_hash = blspy.Util.hash256(bytes(coin))
return BLSSignature(
bytes(pool_private_key.sign_prepend_prehashed(message_hash))
)
return BLSSignature(bytes(pool_private_key.sign_prepend_prehashed(message_hash)))
def sign_coinbase_coin(coin: Coin, private_key: blspy.PrivateKey):

View File

@ -264,7 +264,7 @@ class ChiaServer:
try:
await connection.send(message)
except (RuntimeError, TimeoutError, OSError,) as e:
self.log.error(
self.log.warning(
f"Cannot write to {connection}, already closed. Error {e}."
)
self.global_connections.close(connection, True)

View File

@ -268,12 +268,14 @@ class Timelord:
# TODO: change protocol to use bytes and same ProofOfTime format (instead of hex)
# Reads 16 bytes of hex, for the 8 byte iterations
bytes_read = await reader.readexactly(16)
print("bytes read:", bytes_read)
iterations_needed = uint64(
int.from_bytes(
bytes.fromhex(bytes_read.decode()), "big", signed=True
)
)
bytes_read = await reader.readexactly(16)
print("bytes read2:", bytes_read)
# Reads 16 bytes of hex, for the 8 byte y_size
y_size = uint64(
int.from_bytes(

View File

@ -43,16 +43,19 @@ test_constants["GENESIS_BLOCK"] = bytes(
async def setup_full_node(db_name, port, introducer_port=None, dic={}):
# SETUP
test_constants_copy = test_constants.copy()
for k in dic.keys():
test_constants[k] = dic[k]
test_constants_copy[k] = dic[k]
store_1 = await FullNodeStore.create(Path(db_name))
await store_1._clear_database()
unspent_store_1 = await UnspentStore.create(Path(db_name))
await unspent_store_1._clear_database()
mempool_1 = Mempool(unspent_store_1, dic)
b_1: Blockchain = await Blockchain.create(unspent_store_1, store_1, test_constants)
await store_1.add_block(FullBlock.from_bytes(test_constants["GENESIS_BLOCK"]))
b_1: Blockchain = await Blockchain.create(
unspent_store_1, store_1, test_constants_copy
)
await store_1.add_block(FullBlock.from_bytes(test_constants_copy["GENESIS_BLOCK"]))
config = load_config("config.yaml", "full_node")
if introducer_port is not None:
@ -158,8 +161,8 @@ async def setup_two_nodes(dic={}):
Setup and teardown of two full nodes, with blockchains and separate DBs.
"""
node_iters = [
setup_full_node("blockchain_test.db", 21234, dic={}),
setup_full_node("blockchain_test_2.db", 21235, dic={}),
setup_full_node("blockchain_test.db", 21234, dic=dic),
setup_full_node("blockchain_test_2.db", 21235, dic=dic),
]
fn1, s1 = await node_iters[0].__anext__()

View File

@ -1,5 +1,6 @@
import asyncio
import pytest
import time
from tests.setup_nodes import setup_full_system
@ -12,12 +13,16 @@ def event_loop():
class TestSimulation:
@pytest.fixture(scope="function")
async def simulation(self):
async for _ in setup_full_system({"DIFFICULTY_STARTING": 1}):
async for _ in setup_full_system():
yield _
@pytest.mark.asyncio
async def test_simulation_1(self, simulation):
node1, node2 = simulation
await asyncio.sleep(60)
tip_heights = [t.height for t in node1.blockchain.get_tips()]
start = time.time()
while time.time() - start < 100:
if max([h.height for h in node1.blockchain.get_current_tips()]) > 10:
return
await asyncio.sleep(1)
tip_heights = [t.height for t in node1.blockchain.get_current_tips()]
assert max(tip_heights) > 5

View File

@ -59,10 +59,10 @@ class WalletTool:
map(
lambda child: hash
== puzzle_for_pk(
self.extended_secret_key.public_child(child)
.get_public_key()
.serialize()
).get_hash(),
self.extended_secret_key.public_child(child)
.get_public_key()
.serialize()
).get_hash(),
reversed(range(self.next_address)),
)
)