-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.js
198 lines (167 loc) · 6.75 KB
/
util.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
function maybe_change_analysis() {
should_merge = merge_selection();
// Necessary when we change the grouping before having done an analysis
if (!current_nodes || !current_orgs) {
return;
}
if (last_merge_state != should_merge) {
last_merge_state = should_merge;
analyze_and_update_results_box();
}
}
const div = document.getElementById('results-box');
function create_title_in_div(text) {
var b = document.createElement("b");
b.innerHTML = text;
div.append(b);
div.append(document.createElement("br"));
}
function create_buttons_in_div(title, short_results, results, tooltip) {
var btn = document.createElement("button");
btn.setAttribute('class', 'collapsible tooltip');
var tip = document.createElement('div');
tip.setAttribute('class', 'tooltiptext');
tip.innerHTML = tooltip;
btn.appendChild(tip);
var main = document.createElement("b");
main.innerHTML = title;
btn.appendChild(main);
var label = document.createTextNode(short_results);
btn.appendChild(label);
btn.addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
var output = document.getElementById("results-box");
output.appendChild(btn);
var inner_div = document.createElement("div");
inner_div.setAttribute('class', 'content');
output.appendChild(inner_div);
var paragraph = document.createElement("P");
paragraph.setAttribute('id', 'par');
var copy_btn = document.createElement("button");
copy_btn.setAttribute('class', 'copyButton');
copy_btn.setAttribute('title', 'Copy');
copy_btn.innerHTML = "⎘";
copy_btn.addEventListener("click", function() {
var textarea = document.createElement('textarea');
textarea.id = 'temp_element';
textarea.style.height = 0;
document.body.appendChild(textarea);
textarea.value = this.nextElementSibling.innerText;
var selector = document.querySelector('#temp_element');
selector.select();
document.execCommand('copy');
document.body.removeChild(textarea);
});
paragraph.appendChild(copy_btn);
var myDiv = document.createElement("div");
myDiv.id = 'myDiv';
myDiv.innerHTML = results;
paragraph.appendChild(myDiv);
inner_div.appendChild(paragraph);
}
/*
* Different function for symmetric top tier because
* - short_results is bold
* - non-bold text after short_results
* - Results are written in a <pre> (JSON)
*/
function create_buttons_in_div_alter(title, short_results, sub_results, results, tooltip) {
var btn = document.createElement("button");
btn.setAttribute('class', 'collapsible tooltip');
var tip = document.createElement('div');
tip.setAttribute('class', 'tooltiptext');
tip.innerHTML = tooltip;
btn.appendChild(tip);
var text = document.createTextNode(title);
btn.appendChild(text);
var bold = document.createElement("b");
bold.innerHTML = short_results;
btn.appendChild(bold);
text = document.createTextNode(sub_results);
btn.appendChild(text);
btn.addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
var output = document.getElementById("results-box");
output.appendChild(btn);
var inner_div = document.createElement("div");
inner_div.setAttribute('class', 'content');
output.appendChild(inner_div);
var paragraph = document.createElement("P");
paragraph.setAttribute('id', 'par');
var copy_btn = document.createElement("button");
copy_btn.setAttribute('class', 'copyButton');
copy_btn.setAttribute('title', 'Copy');
copy_btn.innerHTML = "⎘";
copy_btn.addEventListener("click", function() {
var textarea = document.createElement('textarea');
textarea.id = 'temp_element';
textarea.style.height = 0;
document.body.appendChild(textarea);
textarea.value = this.nextElementSibling.innerText;
var selector = document.querySelector('#temp_element');
selector.select();
document.execCommand('copy');
document.body.removeChild(textarea);
});
paragraph.appendChild(copy_btn);
var myDiv = document.createElement("pre");
myDiv.id = 'myDiv';
myDiv.innerHTML = results;
paragraph.appendChild(myDiv);
inner_div.appendChild(paragraph);
}
function clear_results_box() {
while(div.firstChild) {
div.removeChild(div.firstChild);
};
}
function show_results_box_title(timestamp, stellarbeat_timestamp) {
create_title_in_div("Results for " + timestamp + " (data from Stellarbeat has timestamp " + stellarbeat_timestamp + ")");
}
function show_mqs_results(mqs, mqs_len, has_quorum_intersection) {
var mqs_output = JSON.stringify(mqs, null, 4);
var mqs_tooltip = "Minimal sets of nodes that are sufficient to reach agreement.";
if (has_quorum_intersection) {
create_buttons_in_div("quorums |", " We found " + mqs_len + " minimal quorums. All quorums intersect 👍", mqs_output, mqs_tooltip);
} else {
create_buttons_in_div("quorums |", " We found " + mqs_len + " minimal quorums. Some quorums don't intersect 👎 Safety severely threatened for some nodes! (Also, the remaining results here might not make much sense.)", mqs_output, mqs_tooltip);
}
}
function show_mbs_results(mbs, mbs_len, mbs_min) {
var mbs_output = JSON.stringify(mbs, null, 4);
var mbs_tooltip = "Control over any of these sets is sufficient to compromise the liveness of all nodes and to censor future transactions.";
create_buttons_in_div("blocking sets |", " We found "+ mbs_len + " minimal blocking sets. The smallest one has size " + mbs_min + ".", mbs_output, mbs_tooltip);
}
function show_mss_results(mss, mss_len, mss_min) {
var mss_output = JSON.stringify(mss, null, 4);
var mss_tooltip = "Control over any of these sets is sufficient to compromise safety by undermining the quorum intersection of at least two quorums.";
create_buttons_in_div("splitting sets |", " We found "+ mss_len + " minimal splitting sets. The smallest one has size " + mss_min + ".", mss_output, mss_tooltip);
}
function show_tt_results(tt, tt_len, symm_tt) {
var tt = [JSON.stringify(tt)];
var tt_tooltip = "These are the nodes out of which all minimal quorums, minimal blocking sets and minimal splitting sets are formed.";
create_buttons_in_div("top tier 👑 |", " There are " + tt_len + " nodes in the top tier.", tt, tt_tooltip);
if (symm_tt) {
symm_tt_string = JSON.stringify(symm_tt, null, 4);
var sc_tooltip = "All top tier nodes have identical quorum sets."
create_buttons_in_div_alter("The top tier is", " symmetric", ".", symm_tt_string, sc_tooltip);
}
}
// let a few milliseconds pass just so, so that the browser can redraw
function tick() {
return new Promise(r => setTimeout(r, 1));
}