forked from stellar/stellar-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_of_2019_05_29_stellar_quorum_sets_stellarbeat_satoshipay_de_example.py
49 lines (37 loc) · 2.32 KB
/
copy_of_2019_05_29_stellar_quorum_sets_stellarbeat_satoshipay_de_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""Copy of 2019-05-29 Stellar quorum sets stellarbeat/satoshipay-de example
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1cbCXatyQOEmMaNBSCVT1pMyh3QYpww4d
"""
!pip install stellar-observatory==1.0.1
!pip install typing
#@title Default title text
import stellarobservatory
def analyze_network(nodes, seed_public_key):
"""Checks the quorums with all nodes the seed node depends on"""
nodes_by_public_key = stellarobservatory.nodes.get_nodes_by_public_key(nodes)
dependencies = stellarobservatory.nodes.get_node_dependencies(nodes_by_public_key, seed_public_key)
print('dependencies: {0} ({1})'.format(len(dependencies), stellarobservatory.nodes.convert_public_keys_to_names(nodes_by_public_key, dependencies)))
quorum_candidates = stellarobservatory.utils.sets.powerset(dependencies)
print('# quorum candidates: {0}'.format(len(quorum_candidates)))
quorum_slices_by_public_key = {
dependency: stellarobservatory.quorum.generate_quorum_slices(
stellarobservatory.quorum.get_normalized_qset_definition(nodes_by_public_key[dependency])
)
for dependency in dependencies
}
quorums = [candidate for candidate in quorum_candidates if candidate and stellarobservatory.quorum.is_quorum(quorum_slices_by_public_key, candidate)]
print('# quorums: {0}'.format(len(quorums)))
intersection, quorum_a, quorum_b = stellarobservatory.quorum.get_minimal_quorum_intersection(quorums)
if intersection is not None:
print('Quorums have quorum intersection with minimal intersection size {0}'.format(len(intersection)))
print('Minimum intersection example:')
print('Intersection: {0}'.format(stellarobservatory.nodes.convert_public_keys_to_names(nodes_by_public_key, intersection)))
else:
print('No quorum intersection!')
print('Quorum A: {0}'.format(stellarobservatory.nodes.convert_public_keys_to_names(nodes_by_public_key, quorum_a)))
print('Quorum B: {0}'.format(stellarobservatory.nodes.convert_public_keys_to_names(nodes_by_public_key, quorum_b)))
nodes = stellarobservatory.nodes.get_nodes_from_stellarbeat()
public_key_satoshipay_de = 'GC5SXLNAM3C4NMGK2PXK4R34B5GNZ47FYQ24ZIBFDFOCU6D4KBN4POAE'
analyze_network(nodes, public_key_satoshipay_de)