-
Notifications
You must be signed in to change notification settings - Fork 9
/
config_utils.fc
73 lines (67 loc) · 2.98 KB
/
config_utils.fc
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
;; next three functions return information about current validator set (config param #34)
;; they are borrowed from config-code.fc
(cell, int, cell) get_current_vset() inline_ref {
var vset = config_param(34);
var cs = begin_parse(vset);
;; validators_ext#12 utime_since:uint32 utime_until:uint32
;; total:(## 16) main:(## 16) { main <= total } { main >= 1 }
;; total_weight:uint64
throw_unless(40, cs~load_uint(8) == 0x12);
cs~skip_bits(32 + 32 + 16 + 16);
var (total_weight, dict) = (cs~load_uint(64), cs~load_dict());
cs.end_parse();
return (vset, total_weight, dict);
}
(slice, int) get_validator_descr(int idx) inline_ref {
var (vset, total_weight, dict) = get_current_vset();
var (value, _) = dict.udict_get?(16, idx);
return (value, total_weight);
}
(int, int) unpack_validator_descr(slice cs) inline {
;; ed25519_pubkey#8e81278a pubkey:bits256 = SigPubKey;
;; validator#53 public_key:SigPubKey weight:uint64 = ValidatorDescr;
;; validator_addr#73 public_key:SigPubKey weight:uint64 adnl_addr:bits256 = ValidatorDescr;
throw_unless(41, (cs~load_uint(8) & ~ 0x20) == 0x53);
throw_unless(41, cs~load_uint(32) == 0x8e81278a);
return (cs~load_uint(256), cs~load_uint(64));
}
(slice) elector_address() {
var elector = config_param(1).begin_parse().preload_uint(256);
return begin_cell()
.store_uint(4, 3).store_uint(0xff, 8).store_uint(elector, 256)
.end_cell()
.begin_parse();
}
(slice) config_address() {
var config = config_param(0).begin_parse().preload_uint(256);
return begin_cell()
.store_uint(4, 3).store_uint(0xff, 8).store_uint(config, 256)
.end_cell()
.begin_parse();
}
(int, int, int) stake_lock_durations() {
slice validation_params = config_param(15).begin_parse();
int validators_elected_for = validation_params~load_uint(32);
validation_params~load_bits(64);
int stake_held_for = validation_params~load_uint(32);
slice set_params = config_param(34).begin_parse();
set_params~load_bits(8);
int utime_since = set_params~load_uint(32);
return (validators_elected_for, stake_held_for, utime_since);
}
(int) max_recommended_punishment_for_validator_misbehaviour(int stake) {
slice recommendation = config_param(40).begin_parse();
(int _1,
int flat_fine, int prop_fine,
int severity_flat_mult, int severity_prop_mult,
int _2,
int long_flat_mult, int long_prop_mult) =
( recommendation~load_uint(8),
recommendation~load_grams(), recommendation~load_uint(32),
recommendation~load_uint(16), recommendation~load_uint(16),
recommendation~load_uint(16),
recommendation~load_uint(16), recommendation~load_uint(16));
int suggested_fine = (flat_fine * severity_flat_mult >> 8) * long_flat_mult >> 8;
int suggested_fine_part = (prop_fine * severity_prop_mult >> 8) * long_prop_mult >> 8;
return min(stake, suggested_fine + muldiv(stake, suggested_fine_part, 1 << 32)); ;; elector-code.fc:L529
}