From 1b56c4baa51c466273c935e962cd9e9d837d2fc6 Mon Sep 17 00:00:00 2001 From: kogeler <25884155+kogeler@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:57:52 +0200 Subject: [PATCH] the state-exporter role was fixed (#65) * the state-exporter role was fixed Signed-off-by: kogeler --- galaxy.yml | 2 +- roles/key_inject/defaults/main.yml | 3 +++ roles/key_inject/tasks/check_session_key.yml | 2 +- roles/key_inject/tasks/inject.yml | 2 +- roles/key_inject/tasks/main.yml | 2 +- roles/state_exporter/files/exporter.py | 20 +++++++++++--------- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/galaxy.yml b/galaxy.yml index 62fb4a4..a1138b7 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: paritytech name: chain # The version of the collection. Must be compatible with semantic versioning -version: 1.8.1 +version: 1.8.2 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/roles/key_inject/defaults/main.yml b/roles/key_inject/defaults/main.yml index 6a9a17b..d40c150 100644 --- a/roles/key_inject/defaults/main.yml +++ b/roles/key_inject/defaults/main.yml @@ -23,6 +23,9 @@ key_inject_relay_chain_rpc_port: 9944 # priv_key: "SECRET SEED" # - type: "audi" # priv_key: "SECRET SEED" +# - scheme: "ecdsa" +# type: "beef +# priv_key: "SECRET SEED" # if set to true, public part of from key_inject_relay_chain_key_list will be combined # and verified that it is present in keystore diff --git a/roles/key_inject/tasks/check_session_key.yml b/roles/key_inject/tasks/check_session_key.yml index bdeb263..58b1159 100644 --- a/roles/key_inject/tasks/check_session_key.yml +++ b/roles/key_inject/tasks/check_session_key.yml @@ -1,7 +1,7 @@ --- - name: Check session key | Generate session ansible.builtin.set_fact: - key_inject_session_key: "0x{% for key in key_inject_relay_chain_key_list %}{{ (key.priv_key | parity.chain.subkey_inspect(scheme=(key.scheme | default('sr25519')))).publicKey.replace('0x', + key_inject_session_key: "0x{% for key in key_inject_relay_chain_key_list %}{{ (key.priv_key | paritytech.chain.subkey_inspect(scheme=(key.scheme | default('sr25519')))).publicKey.replace('0x', '') }}{% endfor %}" - name: Check session key | Run rpc diff --git a/roles/key_inject/tasks/inject.yml b/roles/key_inject/tasks/inject.yml index a500e71..6467194 100644 --- a/roles/key_inject/tasks/inject.yml +++ b/roles/key_inject/tasks/inject.yml @@ -4,7 +4,7 @@ block: - name: Inject | Setting {{ item.type }} pub keys ansible.builtin.set_fact: - key_inject_pub_key: "{{ (item.priv_key | parity.chain.subkey_inspect(scheme=(item.scheme | default('sr25519')))).publicKey }}" + key_inject_pub_key: "{{ (item.priv_key | paritytech.chain.subkey_inspect(scheme=(item.scheme | default('sr25519')))).publicKey }}" - name: Inject | Check {{ item.type }} key ansible.builtin.uri: diff --git a/roles/key_inject/tasks/main.yml b/roles/key_inject/tasks/main.yml index 724b5ab..fb792f1 100644 --- a/roles/key_inject/tasks/main.yml +++ b/roles/key_inject/tasks/main.yml @@ -20,7 +20,7 @@ when: key_inject_relay_chain_key_list is defined - name: Check session key is present - ansible.builtin.include_tasks: check_seesion_key.yml + ansible.builtin.include_tasks: check_session_key.yml when: - key_inject_relay_chain_key_list is defined - key_inject_check_session_key diff --git a/roles/state_exporter/files/exporter.py b/roles/state_exporter/files/exporter.py index 22bc130..f7e8d4f 100644 --- a/roles/state_exporter/files/exporter.py +++ b/roles/state_exporter/files/exporter.py @@ -122,21 +122,23 @@ def update_metrics(): def parse_session_key(dir): # variants of key prefixes in the right order key_formats = ( - ['6772616e', '62616265', '696d6f6e', '70617261', '61756469'], - ['6772616e', '62616265', '696d6f6e', '70617261', '6173676e', '61756469']) + ['6772616e', '62616265', '696d6f6e', '70617261', '61756469'], # v1 validator keys (gran,babe,imon,para,audi) + ['6772616e', '62616265', '696d6f6e', '70617261', '6173676e', '61756469'], # v2 validator keys (gran,babe,imon,para,asgn,audi) + ['6772616e', '62616265', '696d6f6e', '70617261', '6173676e', '61756469', '62656566'], # v3 validator keys (gran,babe,imon,para,asgn,audi,beef) + ['61757261'] # collator keys (aura) + ) possible_prefixes = list(set([j for i in key_formats for j in i])) - if os.path.isdir(dir): os.chdir(dir) files = os.listdir('.') - files = [i for i in files if len(i) == 72 and i[0:8] in possible_prefixes] + files = [i for i in files if len(i) in [72, 74] and i[0:8] in possible_prefixes] if not files: return None - # find creation time of the newlest key + # find creation time of the newest key time_of_last_key = sorted(list(set([int(os.path.getmtime(i)) for i in files])))[-1] - # parse the newest public keys and them prefixes from names of files. - # creation time can have 1 second drift in theory - keys = {i[0:8]: i[8:] for i in files if int(os.path.getmtime(i)) in [time_of_last_key - 1, time_of_last_key, time_of_last_key + 1]} + # parse the newest public keys and prefix them with the names of files. + # make sure to only pick up the keys created within 60 seconds interval + keys = {i[0:8]: i[8:] for i in files if int(os.path.getmtime(i)) <= time_of_last_key and int(os.path.getmtime(i)) > time_of_last_key - 60} logger.debug('keys were found: ' + str(keys) + ' in the keystore path: ' + dir) for key_format in key_formats: if set(keys.keys()) == set(key_format): @@ -144,7 +146,7 @@ def parse_session_key(dir): session_key = '0x' + ''.join([keys[i] for i in key_format]) logger.debug('the session key was parsed: ' + session_key + ' in the keystore path: ' + dir) return(session_key) - logger.error('Error of session key parsing') + logger.error('Error parsing the session key') return None