Skip to content

Commit

Permalink
make claiming fees possible for all VNs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 17, 2024
1 parent 704d886 commit a917317
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Collections/validator_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def add_validator_node(self, vn_id: int):
return
self.validator_nodes[vn_id] = ValidatorNode(base_node.grpc_port, wallet.grpc_port, vn_id, self.get_addresses())

def register(self):
def register(self, claim_public_key: str):
print("Waiting for wallet balance", end=".")
for vn_id in self.validator_nodes:
while wallet.grpc_client.get_balance().available_balance == 0:
time.sleep(1)
print(".", end="")
self.validator_nodes[vn_id].register(local_ip)
self.validator_nodes[vn_id].register(local_ip, claim_public_key)
# Uncomment next line if you want to have only one registeration per block
# miner.mine(1)
print("done")
Expand Down
15 changes: 15 additions & 0 deletions Processes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ def get_active_validator_nodes(self, height: int):
request = base_node_pb2.GetActiveValidatorNodesRequest(height=height)
return self.stub.GetActiveValidatorNodes(request)

def search_utxos(self, commitments: list[bytes]):
request = base_node_pb2.SearchUtxosRequest(commitments=commitments)
return self.stub.SearchUtxos(request)

def get_signature(self, public_nonce: str | bytes, signature: str | bytes) -> types_pb2.Signature:
if type(public_nonce) == str:
public_nonce = bytes.fromhex(public_nonce)
if type(signature) == str:
signature = bytes.fromhex(signature)
return types_pb2.Signature(public_nonce=public_nonce, signature=signature)

def search_kernels(self, signatures: list[types_pb2.Signature]):
request = base_node_pb2.SearchKernelsRequest(signatures=signatures)
return self.stub.SearchKernels(request)


class BaseNode(CommonExec):
def __init__(self):
Expand Down
3 changes: 3 additions & 0 deletions Processes/dan_wallet_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def auth(self):
def keys_list(self):
return self.call("keys.list")

def keys_create(self, specific_index: Optional[int] = None):
return self.call("keys.create", {"specific_index": specific_index})

def accounts_create(self, name: str, custom_access_rules: Any = None, fee: Optional[int] = None, is_default: bool = True, key_id: Optional[int] = None):
id = stats.start_run("accounts.create")
res = self.call("accounts.create", [name, custom_access_rules, fee, is_default, key_id])
Expand Down
40 changes: 26 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,6 @@ def check_executable(bins_folder: str, file_name: str):
miner.start(base_node.grpc_port, wallet.grpc_port, local_ip)
# Mine some blocks
miner.mine((SPAWN_VNS + SPAWN_INDEXERS + SPAWN_WALLETS) * 2 + 13) # Make sure we have enough funds
# Start VNs
print_step("CREATING VNS")
for vn_id in range(SPAWN_VNS):
validator_nodes.add_validator_node(vn_id)
validator_nodes.wait_for_sync()

print_step("REGISTER THE VNS")
# Register VNs
validator_nodes.register()

if SPAWN_INDEXERS > 0:
print_step("STARTING INDEXERS")
Expand All @@ -361,10 +352,10 @@ def spawn_indexer(id: int):
time.sleep(1)
# force the indexer to connect to a VN. It will not find this substate, but it needs to contact the VN
# to start comms
try:
indexers[id].jrpc_client.get_substate("component_d082c9cfb6507e302d5e252f43f4c008924648fc9bff18eaca5820a87808fc42", 0)
except:
pass
# try:
# indexers[id].jrpc_client.get_substate("component_d082c9cfb6507e302d5e252f43f4c008924648fc9bff18eaca5820a87808fc42", 0)
# except:
# pass

for id in range(SPAWN_INDEXERS):
threads.add(spawn_indexer, (id,))
Expand Down Expand Up @@ -403,6 +394,24 @@ def create_wallet(dwallet_id: int, indexer_jrpc: int, signaling_server_jrpc: int

threads.wait()

# Create a new key so we register all VNs to this public key and then create TestAccount_0 for it. So we can claim the fees.
dan_wallets[0].jrpc_client.auth()
new_key = dan_wallets[0].jrpc_client.keys_create()
if not new_key:
raise Exception("Failed to create a key")
claim_public_key : str = new_key["public_key"]
new_key_id : str = new_key["id"]

# Start VNs
print_step("CREATING VNS")
for vn_id in range(SPAWN_VNS):
validator_nodes.add_validator_node(vn_id)
validator_nodes.wait_for_sync()

print_step("REGISTER THE VNS")
# Register VNs
validator_nodes.register(claim_public_key)

miner.mine(23)
validator_nodes.wait_for_sync()
indexers.wait_for_sync()
Expand Down Expand Up @@ -454,7 +463,10 @@ def create_account(i: int, amount: int):
name = {"Name": f"TestAccount_{i}"}
dan_wallet_jrpc = dan_wallets[i % SPAWN_WALLETS].jrpc_client
print(f"Account {name["Name"]} creation started")
dan_wallet_jrpc.create_free_test_coins(name, amount)
if i == 0:
dan_wallet_jrpc.create_free_test_coins(name, amount, key_id = int(new_key_id))
else:
dan_wallet_jrpc.create_free_test_coins(name, amount)
print(f"Account {name["Name"]} created")

threads.set_semaphore_limit(1)
Expand Down

0 comments on commit a917317

Please sign in to comment.