Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vegacapsule does not return latest eth key for node #404

Open
jgsbennett opened this issue Jul 27, 2023 · 0 comments
Open

Vegacapsule does not return latest eth key for node #404

jgsbennett opened this issue Jul 27, 2023 · 0 comments
Assignees

Comments

@jgsbennett
Copy link
Contributor

There are some system tests which rotate node keys, and which would love it if vegacapsule could return up-to-date information about ethereum keys for nodes, so that they can send appropriate commands to rotate in future. Sadly, currently vegacapsule always returns the original keys in the information about the node. The upshot of this, is that you can only run affected tests once in a network lifetime, and running again would require a network restart, which is pretty tedious (and makes debugging issues painful).

It would be lovely if vegacapsule could instead return whatever the current eth key is.

Affected tests are like this one:

    @pytest.mark.network_infra
    @pytest.mark.ethereum_key_rotation
    def test_ethereum_key_rotation_nodewallet_to_clef(context):
        """
        Spec Ref - https://github.com/vegaprotocol/specs/blob/master/protocol/0067-KEYS-key_management.md
        Ticket Ref - https://github.com/vegaprotocol/system-tests/issues/926

        Karel has made the changes for the key rotation in the vega repo branch - eth-key-rotation-fix
        Please make sure this branch has been merged

        To see the current list of accounts in clef use the below command
        curl -H 'Content-Type: application/json' -X POST --data '{"id": 1, "jsonrpc": "2.0", "method": "account_list"}' http://127.0.0.1:8550
        In order to create a new ethereum key in clef use the below command
        This will need to be coded in here and the hard coding removed
        curl -H 'Content-Type: application/json' -X POST --data '{"id": 1, "jsonrpc": "2.0", "method": "account_new"}' http://127.0.0.1:8550

        Ethereum key - multisig (0067-KEYS-001)
        A Vega network is running with 3 validators, v1,v2,v3 with Ethereum keys k1, k2, k3_old; each with equal tendermint and multisig weight.
        Validator v3 has ethereum multisig public key k3_old. They submit a transaction to replace by ethereum multisig public key k3_new.
        The network issues a signature bundle to update that can be submitted to the ethereum multisig contract to update the key there.
        This is submitted to ethereum; the multisig contract is updated.
        Vega nodes receive the event confirming the key has been updated.
        Party p now issues a withdrawal transaction. A withdrawal bundle is created utilizing k1,k2,k3_new.
        Party p submits the withdrawal bundle to ethereum; multisig contract accepts it and transfers the funds on the ethereum chain.

        """
        # First select the node that we want to do the ethereum key rotation for
        # Then get the ethereum keys and run the rotation

        # obtain node details
        node_to_rotate = 1
        node = Network.list_nodes(mode="validator")[node_to_rotate]
        ethereum_original_key = node.get_ethereum_address()
        node_id = node.get_node_id()
        node_idx = node.get_index()
        logging.info(f"Rotating key on validator with ethereum_original_key={ethereum_original_key} node_idx={node_idx}")
        node_wallet_pk = [v["pubKey"] for v in networkMod.get_node_details() if v["id"] == node_id][0]

        logging.info(f"Rotating key node_idx {node_idx}")
        logging.info(f"Rotating key node_id {node_id}")
        logging.info(f"Rotating key node pubkey {node_wallet_pk}")

        # obtain current clef accounts - use last entry for test as target to rotate to
        accounts = networkMod.return_clef_accounts()
        logging.info(f"Rotating key clef accounts {accounts}")
        ethereum_new_key = list(filter(lambda x: x != ethereum_original_key.lower(), accounts))[-1]
        logging.info(f"Rotating key on validator - rotating key {ethereum_original_key} ---> {ethereum_new_key}")

        logging.info(f"Rotating key resetting epoch to 10s")
        utils.reset_epoch(context, "30s")
        # fresh epoch to ensure we get the epoch_seq set correctly for the trx
        logging.info(f"Rotating key on validator - pausing for new epoch")
        utils.pause_until_new_epoch()

        submitter_priv_key, submitter = networkMod.eth_generate_keypair()
        submitter = get_w3().to_checksum_address(submitter)

        vega_commands.import_ethereum_node_wallet(node_details=node, ethereum_key=ethereum_new_key)
        target_block, _ = send_ethereuem_rotation_command(node, ethereum_original_key, submitter)
        logging.info(f"Rotating key on validator - submitting trx - target_block {target_block}")
        vega_commands.rotate_eth_key(node, ethereum_original_key, target_block, submitter)
        epoch_seq = networkMod.getEpochData().epoch.seq

        logging.info(f"Rotating key on validator - submitted trx - target_block={target_block} now waiting....")
        utils.pause_for_n_blocks(target_block=target_block)

        # confirm rotation
>       networkMod.confirm_ethereum_key_rotation(
            node_idx,
            node_wallet_pk,
            get_w3().to_checksum_address(ethereum_original_key),
            get_w3().to_checksum_address(ethereum_new_key),
            target_block,
        )

tests/wallet/vega_key_rotation_test.py:159:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
modules/networkMod/networkMod.py:2412: in confirm_ethereum_key_rotation
    check_key_rotation_from_events(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

event_type = 'EthereumKeyRotation', max_wait = 20
node_id = '669b5463b7970cabfeb131e02a4ff35e839b0bc0668f2d7e762da0f5d8a53521'
old_pubkey = '0x4D2f33dA6f9ea4EF420e95449c50Ce188857ACf0', new_pubkey = '0xafCfF78a888A8D05e43612a9d918D8B2F054a4Eb'
block_height = 5021

    def check_key_rotation_from_events(
        event_type=None, max_wait=20, node_id=None, old_pubkey=None, new_pubkey=None, block_height=None
    ):
        key_rotation_events = utils.scan_events(
            busEventTypeDict.get(event_type)["Name"],
            tmout=time.time() + max_wait,
            search_list=[
                node_id,
                old_pubkey,
                new_pubkey,
                str(block_height),
            ],
            rows_reqd=1,
        )

        # Assert the data
>       assert (
            len(key_rotation_events) > 0
        ), f"No rotation event found containing {node_id} {old_pubkey} {new_pubkey} {block_height}"
E       AssertionError: No rotation event found containing 669b5463b7970cabfeb131e02a4ff35e839b0bc0668f2d7e762da0f5d8a53521 0x4D2f33dA6f9ea4EF420e95449c50Ce188857ACf0 0xafCfF78a888A8D05e43612a9d918D8B2F054a4Eb 5021
E       assert 0 > 0
E        +  where 0 = len([])

modules/networkMod/networkMod.py:2456: AssertionError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

3 participants