viz-js-lib 0.12.4 → 0.12.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,292 @@
1
+ # Witness → Validator Migration
2
+
3
+ VIZ blockchain has renamed "witness" terminology to "validator" across the entire protocol stack. This document describes what changed in `viz-js-lib` and how to work with both old and new names during the transition.
4
+
5
+ ---
6
+
7
+ ## Key Principles
8
+
9
+ 1. **Integer type IDs never change.** Binary wire format is positional — field names are never written to the wire. Submitting transactions by integer ID is always safe.
10
+ 2. **`witness_api` namespace is gone.** All RPC calls must use `"validator_api"`. `witness_api` returns an error on upgraded nodes. Old method names (e.g. `get_active_witnesses`) remain as deprecated aliases *within* `validator_api` for one release cycle.
11
+ 3. **Node accepts both old and new field names in incoming transactions.** Responses use new names only.
12
+
13
+ ---
14
+
15
+ ## Changes Made in viz-js-lib
16
+
17
+ ### [`src/auth/serializer/src/operations.js`](../../src/auth/serializer/src/operations.js)
18
+
19
+ Five operations renamed. Old names re-exported as backward-compat aliases.
20
+
21
+ | Type ID | Old name | New name | Field changes |
22
+ |---|---|---|---|
23
+ | 6 | `witness_update` | `validator_update` | none |
24
+ | 7 | `account_witness_vote` | `account_validator_vote` | `witness` → `validator` |
25
+ | 8 | `account_witness_proxy` | `account_validator_proxy` | none |
26
+ | 30 | `shutdown_witness` | `shutdown_validator` | none |
27
+ | 42 | `witness_reward` | `validator_reward` | `witness` → `validator` |
28
+
29
+ Block header schema fields renamed (binary unaffected — positional):
30
+ - `witness` → `validator`, `witness_signature` → `validator_signature`
31
+
32
+ Chain properties fields renamed across all hardfork variants:
33
+
34
+ | Old field | New field | First appeared in |
35
+ |---|---|---|
36
+ | `inflation_witness_percent` | `inflation_validator_percent` | `chain_properties_hf4` |
37
+ | `witness_miss_penalty_percent` | `validator_miss_penalty_percent` | `chain_properties_hf6` |
38
+ | `witness_miss_penalty_duration` | `validator_miss_penalty_duration` | `chain_properties_hf6` |
39
+ | `witness_declaration_fee` | `validator_declaration_fee` | `chain_properties_hf9` |
40
+
41
+ All fields appear in every later variant (`hf9` carries hf4+hf6 fields; `hf13` carries hf9 fields). Old names re-exported:
42
+
43
+ ```js
44
+ module.exports.witness_update = validator_update;
45
+ module.exports.account_witness_vote = account_validator_vote;
46
+ module.exports.account_witness_proxy = account_validator_proxy;
47
+ module.exports.shutdown_witness = shutdown_validator;
48
+ module.exports.witness_reward = validator_reward;
49
+ ```
50
+
51
+ ### [`src/auth/serializer/src/types.js`](../../src/auth/serializer/src/types.js)
52
+
53
+ `static_variant.opTypeId()` accepts old operation names as aliases — `'witness_update'` still resolves to type ID 6.
54
+
55
+ ### [`src/auth/serializer/src/ChainTypes.js`](../../src/auth/serializer/src/ChainTypes.js)
56
+
57
+ Both new and old names present in `ChainTypes.operations`, pointing to the same integer IDs:
58
+
59
+ ```js
60
+ validator_update: 6, account_validator_vote: 7, account_validator_proxy: 8,
61
+ shutdown_validator: 30, validator_reward: 42,
62
+ // backward-compat aliases:
63
+ witness_update: 6, account_witness_vote: 7, account_witness_proxy: 8,
64
+ shutdown_witness: 30, witness_reward: 42,
65
+ ```
66
+
67
+ ### [`src/auth/serializer/src/serializer.js`](../../src/auth/serializer/src/serializer.js)
68
+
69
+ `Serializer.field_aliases` (new name → old name) added. `fromObject()` and `appendByteBuffer()` fall back to the old name when the new field is absent — old-format inputs are accepted transparently:
70
+
71
+ ```js
72
+ Serializer.field_aliases = {
73
+ 'validator': 'witness',
74
+ 'validator_signature': 'witness_signature',
75
+ 'inflation_validator_percent': 'inflation_witness_percent',
76
+ 'validator_miss_penalty_percent': 'witness_miss_penalty_percent',
77
+ 'validator_miss_penalty_duration':'witness_miss_penalty_duration',
78
+ 'validator_declaration_fee': 'witness_declaration_fee',
79
+ };
80
+ ```
81
+
82
+ ### [`src/broadcast/operations.js`](../../src/broadcast/operations.js)
83
+
84
+ New validator entries added alongside old witness entries. Both old and new JS method names are generated:
85
+
86
+ | Old JS method | New JS method | Note |
87
+ |---|---|---|
88
+ | `viz.broadcast.witnessUpdate()` | `viz.broadcast.validatorUpdate()` | same params |
89
+ | `viz.broadcast.accountWitnessVote(…, witness, …)` | `viz.broadcast.accountValidatorVote(…, validator, …)` | param renamed |
90
+ | `viz.broadcast.accountWitnessProxy()` | `viz.broadcast.accountValidatorProxy()` | same params |
91
+
92
+ The old `accountWitnessVote` passes `witness` as the field name; `Serializer.field_aliases` maps it to `validator` transparently at serialization time.
93
+
94
+ ### [`src/api/methods.js`](../../src/api/methods.js)
95
+
96
+ All entries use `"validator_api"`. Each renamed method has two entries — the new primary name and the old deprecated-alias name, both calling `validator_api`:
97
+
98
+ | New JS method | Old JS method (deprecated alias) |
99
+ |---|---|
100
+ | `viz.api.getActiveValidators()` | `viz.api.getActiveWitnesses()` |
101
+ | `viz.api.getValidatorSchedule()` | `viz.api.getWitnessSchedule()` |
102
+ | `viz.api.getValidators()` | `viz.api.getWitnesses()` |
103
+ | `viz.api.getValidatorByAccount()` | `viz.api.getWitnessByAccount()` |
104
+ | `viz.api.getValidatorsByVote()` | `viz.api.getWitnessesByVote()` |
105
+ | `viz.api.getValidatorsByCountedVote()` | `viz.api.getWitnessesByCountedVote()` |
106
+ | `viz.api.getValidatorCount()` | `viz.api.getWitnessCount()` |
107
+ | `viz.api.lookupValidatorAccounts()` | `viz.api.lookupWitnessAccounts()` |
108
+
109
+ `viz.api.getMinerQueue()` — name unchanged, moved to `validator_api`.
110
+
111
+ ### [`test/methods_by_version.js`](../../test/methods_by_version.js)
112
+
113
+ New validator method names added alongside old witness names in the `methods_test` array.
114
+
115
+ ---
116
+
117
+ ## Usage Guide
118
+
119
+ ### Sending Transactions
120
+
121
+ ```js
122
+ // Safest: use integer type ID — never breaks
123
+ const op = [6, { owner: 'alice', url: 'https://alice.example.com', block_signing_key: 'VIZ5hq...' }];
124
+
125
+ // New string name:
126
+ const op = ['validator_update', { owner: 'alice', url: '...', block_signing_key: '...' }];
127
+
128
+ // Old string name (resolved via alias):
129
+ const op = ['witness_update', { owner: 'alice', url: '...', block_signing_key: '...' }];
130
+ ```
131
+
132
+ ### Voting for a Validator
133
+
134
+ ```js
135
+ // New:
136
+ viz.broadcast.accountValidatorVote(privateKey, account, validatorAccount, approve, cb);
137
+
138
+ // Old (field alias handled transparently by serializer):
139
+ viz.broadcast.accountWitnessVote(privateKey, account, witnessAccount, approve, cb);
140
+ ```
141
+
142
+ ### Reading Validator Info
143
+
144
+ ```js
145
+ // New (preferred):
146
+ viz.api.getValidatorByAccount('alice', (err, result) => { ... });
147
+
148
+ // Old (deprecated alias within validator_api — works for one release cycle):
149
+ viz.api.getWitnessByAccount('alice', (err, result) => { ... });
150
+ ```
151
+
152
+ ### Chain Properties
153
+
154
+ ```js
155
+ // New field names:
156
+ const props = {
157
+ inflation_validator_percent: 1500,
158
+ validator_miss_penalty_percent: 100,
159
+ validator_miss_penalty_duration: 86400,
160
+ validator_declaration_fee: '10.000 VIZ',
161
+ };
162
+
163
+ // Old field names (still accepted via Serializer.field_aliases):
164
+ const props = {
165
+ inflation_witness_percent: 1500,
166
+ witness_miss_penalty_percent: 100,
167
+ witness_miss_penalty_duration: 86400,
168
+ witness_declaration_fee: '10.000 VIZ',
169
+ };
170
+ ```
171
+
172
+ ### Handling Renamed Fields in Node Responses (caller code)
173
+
174
+ The library relays these fields as-is from the node. After node upgrade, responses use new names. Use safe accessors:
175
+
176
+ ```js
177
+ // validator_schedule_object
178
+ const validators = schedule.current_shuffled_validators ?? schedule.current_shuffled_witnesses;
179
+
180
+ // dynamic_global_properties
181
+ const currentValidator = dgp.current_validator ?? dgp.current_witness;
182
+
183
+ // account object (from get_accounts)
184
+ const votedFor = account.validators_voted_for ?? account.witnesses_voted_for;
185
+ const votes = account.validator_votes ?? account.witness_votes;
186
+ const weight = account.validators_vote_weight ?? account.witnesses_vote_weight;
187
+
188
+ // block header — node now returns validator / validator_signature
189
+ // update any code that accessed .witness or .witness_signature on block objects
190
+ const producer = block.validator; // was block.witness
191
+ const blockSig = block.validator_signature; // was block.witness_signature
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Complete Rename Reference
197
+
198
+ ### API namespace
199
+
200
+ `witness_api` → `validator_api` (old namespace returns error on upgraded nodes).
201
+
202
+ ### API Methods
203
+
204
+ | Old name | New name |
205
+ |---|---|
206
+ | `get_active_witnesses` | `get_active_validators` |
207
+ | `get_witness_schedule` | `get_validator_schedule` |
208
+ | `get_witnesses` | `get_validators` |
209
+ | `get_witness_by_account` | `get_validator_by_account` |
210
+ | `get_witnesses_by_vote` | `get_validators_by_vote` |
211
+ | `get_witnesses_by_counted_vote` | `get_validators_by_counted_vote` |
212
+ | `get_witness_count` | `get_validator_count` |
213
+ | `lookup_witness_accounts` | `lookup_validator_accounts` |
214
+ | `get_miner_queue` | `get_miner_queue` *(name unchanged, namespace changed)* |
215
+
216
+ ### Block Header Fields
217
+
218
+ | Old | New |
219
+ |---|---|
220
+ | `witness` | `validator` |
221
+ | `witness_signature` | `validator_signature` |
222
+
223
+ ### Dynamic Global Properties
224
+
225
+ | Old | New |
226
+ |---|---|
227
+ | `current_witness` | `current_validator` |
228
+
229
+ ### Account Object (`get_accounts` response)
230
+
231
+ | Old | New |
232
+ |---|---|
233
+ | `witnesses_voted_for` | `validators_voted_for` |
234
+ | `witnesses_vote_weight` | `validators_vote_weight` |
235
+ | `witness_votes` | `validator_votes` |
236
+
237
+ ### `validator_schedule_object` Fields
238
+
239
+ | Old | New |
240
+ |---|---|
241
+ | `current_shuffled_witnesses` | `current_shuffled_validators` |
242
+ | `num_scheduled_witnesses` | `num_scheduled_validators` |
243
+
244
+ ### Chain Properties Fields
245
+
246
+ | Old | New | In structs |
247
+ |---|---|---|
248
+ | `inflation_witness_percent` | `inflation_validator_percent` | hf4, hf6, hf9, hf13 |
249
+ | `witness_miss_penalty_percent` | `validator_miss_penalty_percent` | hf6, hf9, hf13 |
250
+ | `witness_miss_penalty_duration` | `validator_miss_penalty_duration` | hf6, hf9, hf13 |
251
+ | `witness_declaration_fee` | `validator_declaration_fee` | hf9, hf13 |
252
+
253
+ ### `get_config` Response Keys
254
+
255
+ | Old | New |
256
+ |---|---|
257
+ | `CHAIN_HARDFORK_REQUIRED_WITNESSES` | `CHAIN_HARDFORK_REQUIRED_VALIDATORS` |
258
+ | `CHAIN_MAX_ACCOUNT_WITNESS_VOTES` | `CHAIN_MAX_ACCOUNT_VALIDATOR_VOTES` |
259
+ | `CHAIN_MAX_WITNESSES` | `CHAIN_MAX_VALIDATORS` |
260
+ | `CHAIN_MAX_SUPPORT_WITNESSES` | `CHAIN_MAX_SUPPORT_VALIDATORS` |
261
+ | `CHAIN_MAX_TOP_WITNESSES` | `CHAIN_MAX_TOP_VALIDATORS` |
262
+ | `CHAIN_MAX_WITNESS_URL_LENGTH` | `CHAIN_MAX_VALIDATOR_URL_LENGTH` |
263
+
264
+ ---
265
+
266
+ ## What NEVER Changes
267
+
268
+ | Item | Reason |
269
+ |---|---|
270
+ | Integer type IDs (6, 7, 8, 30, 42) | Binary wire format uses integer indices |
271
+ | Binary serialization order | Field names not written to binary; only positional values |
272
+ | `block_signing_key`, `url`, `approve`, `proxy` | Describe data, not the role |
273
+ | Signing authority level (`active`) | Unchanged |
274
+ | Null key `VIZ1111111111111111111111111111111114T1Anm` | Same null key format |
275
+
276
+ ---
277
+
278
+ ## Migration Phases
279
+
280
+ **Phase A — current (node upgraded):**
281
+ - Use `validator_api` for all RPC calls — `witness_api` returns error
282
+ - Use new operation and field names in new code
283
+ - Old operation string names resolved via alias maps (library handles transparently)
284
+ - Old field names in fromObject/appendByteBuffer accepted via `Serializer.field_aliases`
285
+ - Old method names work as deprecated aliases within `validator_api`
286
+
287
+ **Phase B — cleanup (after deprecated aliases removed from node):**
288
+ - Remove old-name method entries from `methods.js`
289
+ - Remove `module.exports.witness_*` alias exports from `operations.js`
290
+ - Remove `WITNESS_ALIAS_MAP` from `types.js`
291
+ - Remove old names from `ChainTypes.js`
292
+ - Remove `Serializer.field_aliases`
@@ -0,0 +1,140 @@
1
+ # Witness → Validator Migration
2
+
3
+ ## Key Design Decisions
4
+ - Integer type IDs (6, 7, 8, 30, 42) NEVER change
5
+ - Binary wire format is unaffected (field order, not names)
6
+ - Library outputs new names by default, accepts old names as aliases
7
+ - Broadcast methods: generate BOTH `validatorUpdate()` and `witnessUpdate()` aliases
8
+ - API methods: register BOTH old and new names
9
+
10
+ ## Task 1: Add operation name alias map — `src/auth/serializer/src/types.js`
11
+
12
+ Modify `static_variant` to support alias lookup:
13
+
14
+ ```js
15
+ // Add alias map at top of static_variant function
16
+ const WITNESS_ALIAS_MAP = {
17
+ 'witness_update': 'validator_update',
18
+ 'account_witness_vote': 'account_validator_vote',
19
+ 'account_witness_proxy': 'account_validator_proxy',
20
+ 'shutdown_witness': 'shutdown_validator',
21
+ 'witness_reward': 'validator_reward',
22
+ };
23
+ ```
24
+
25
+ In `opTypeId(value)`: after the existing loop fails to find a match, check `WITNESS_ALIAS_MAP[value]` and iterate again with the mapped name.
26
+
27
+ ## Task 2: Rename operations in serializer — `src/auth/serializer/src/operations.js`
28
+
29
+ ### Operation Serializer renames (5 items):
30
+ - `let witness_update` → `let validator_update` + `Serializer("validator_update", ...)`
31
+ - `let account_witness_vote` → `let account_validator_vote` + `Serializer("account_validator_vote", ...)`
32
+ - `let account_witness_proxy` → `let account_validator_proxy` + `Serializer("account_validator_proxy", ...)`
33
+ - `let shutdown_witness` → `let shutdown_validator` + `Serializer("shutdown_validator", ...)`
34
+ - `let witness_reward` → `let validator_reward` + `Serializer("validator_reward", ...)`
35
+
36
+ ### Field renames inside operations:
37
+ - `account_validator_vote`: field `witness` → `validator`
38
+ - `validator_reward`: field `witness` → `validator`
39
+
40
+ ### Block header field renames (with backward compat note):
41
+ - `signed_block`: `witness` → `validator`, `witness_signature` → `validator_signature`
42
+ - `block_header`: `witness` → `validator`
43
+ - `signed_block_header`: `witness` → `validator`, `witness_signature` → `validator_signature`
44
+
45
+ ### Chain properties field renames (in chain_properties_hf4, hf6, hf9, hf13):
46
+ - `inflation_witness_percent` → `inflation_validator_percent`
47
+ - `witness_miss_penalty_percent` → `validator_miss_penalty_percent`
48
+ - `witness_miss_penalty_duration` → `validator_miss_penalty_duration`
49
+ - `witness_declaration_fee` → `validator_declaration_fee`
50
+
51
+ ### Update `operation.st_operations` array:
52
+ Replace old variable references with new ones.
53
+
54
+ ### Add `module.exports` aliases:
55
+ Export old names as aliases pointing to new Serializers (e.g., `module.exports.witness_update = validator_update`).
56
+
57
+ ## Task 3: Update ChainTypes — `src/auth/serializer/src/ChainTypes.js`
58
+
59
+ Rename operation entries + add alias entries:
60
+ ```js
61
+ validator_update: 6,
62
+ account_validator_vote: 7,
63
+ account_validator_proxy: 8,
64
+ shutdown_validator: 30,
65
+ validator_reward: 42,
66
+ // Aliases for backward compatibility
67
+ witness_update: 6,
68
+ account_witness_vote: 7,
69
+ account_witness_proxy: 8,
70
+ shutdown_witness: 30,
71
+ witness_reward: 42,
72
+ ```
73
+
74
+ ## Task 4: Rename broadcast operations — `src/broadcast/operations.js`
75
+
76
+ ### Rename operation entries:
77
+ - `"operation": "witness_update"` → `"operation": "validator_update"`
78
+ - `"operation": "account_witness_vote"` → `"operation": "account_validator_vote"`, param `"witness"` → `"validator"`
79
+ - `"operation": "account_witness_proxy"` → `"operation": "account_validator_proxy"`
80
+
81
+ ### Add duplicate entries with old names:
82
+ Keep old operation entries as well so both `viz.broadcast.witnessUpdate()` and `viz.broadcast.validatorUpdate()` are generated.
83
+
84
+ ## Task 5: Add new API methods — `src/api/methods.js`
85
+
86
+ ### Rename all witness_api references:
87
+ - `"api": "witness_api"` → `"api": "validator_api"`
88
+
89
+ ### Rename method entries (keep old ones too):
90
+ Add new entries with validator names alongside existing witness ones:
91
+ - `get_active_validators` + keep `get_active_witnesses`
92
+ - `get_validator_schedule` + keep `get_witness_schedule`
93
+ - `get_validators` + keep `get_witnesses`
94
+ - `get_validator_by_account` + keep `get_witness_by_account`
95
+ - `get_validators_by_vote` + keep `get_witnesses_by_vote`
96
+ - `get_validators_by_counted_vote` + keep `get_witnesses_by_counted_vote`
97
+ - `get_validator_count` + keep `get_witness_count`
98
+ - `lookup_validator_accounts` + keep `lookup_witness_accounts`
99
+
100
+ ## Task 6: Serializer `fromObject` field alias support — `src/auth/serializer/src/serializer.js`
101
+
102
+ Add a static field alias map for renamed fields:
103
+ ```js
104
+ Serializer.field_aliases = {
105
+ validator: 'witness', // for account_validator_vote
106
+ validator_signature: 'witness_signature', // for block headers
107
+ inflation_validator_percent: 'inflation_witness_percent',
108
+ validator_miss_penalty_percent: 'witness_miss_penalty_percent',
109
+ validator_miss_penalty_duration: 'witness_miss_penalty_duration',
110
+ validator_declaration_fee: 'witness_declaration_fee',
111
+ };
112
+ ```
113
+
114
+ In `fromObject()`: when `serialized_object[field]` is undefined, check if there's an alias for the field and try the old name. This allows old-node responses to deserialize correctly.
115
+
116
+ Same fallback in `appendByteBuffer()` for the case where the input object uses old field names.
117
+
118
+ ## Task 7: Update test references — `test/methods_by_version.js`
119
+
120
+ Add new validator method names alongside old witness ones:
121
+ - `"get_active_validators"`, `"get_validator_by_account"`, etc.
122
+ - Keep old names in the list too
123
+
124
+ ## Task 8: Verify
125
+
126
+ - Run ESLint on all modified files
127
+ - Run `npm run build-node` to verify compilation
128
+ - Review the generated broadcast method names work for both old and new
129
+
130
+ ## Files Modified (summary)
131
+
132
+ | File | Changes |
133
+ |------|---------|
134
+ | `src/auth/serializer/src/types.js` | Alias map in `static_variant` |
135
+ | `src/auth/serializer/src/operations.js` | Rename 5 serializers + fields + chain props + block headers |
136
+ | `src/auth/serializer/src/ChainTypes.js` | Rename + alias entries |
137
+ | `src/auth/serializer/src/serializer.js` | Field alias support in `fromObject`/`appendByteBuffer` |
138
+ | `src/broadcast/operations.js` | Rename + duplicate old entries |
139
+ | `src/api/methods.js` | Add validator API methods + keep witness ones |
140
+ | `test/methods_by_version.js` | Add validator method names |