Skip to content

Commit

Permalink
the state-exporter role was fixed
Browse files Browse the repository at this point in the history
Signed-off-by: kogeler <roman.gavrilov@parity.io>
  • Loading branch information
kogeler committed Jan 4, 2024
1 parent 224c408 commit 3a5af19
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
3 changes: 3 additions & 0 deletions roles/key_inject/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion roles/key_inject/tasks/check_session_key.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion roles/key_inject/tasks/inject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion roles/key_inject/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 11 additions & 9 deletions roles/state_exporter/files/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,31 @@ 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):
# build the session key
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


Expand Down

0 comments on commit 3a5af19

Please sign in to comment.