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

the state-exporter role was fixed #65

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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