@lodestar/state-transition 2.1.0-dev.c63474c8f3 → 2.1.0-dev.cb75242aef
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.
- package/lib/lightClient/spec/utils.d.ts +0 -1
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +3 -3
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js +2 -5
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/rewards/blockRewards.d.ts.map +1 -1
- package/lib/rewards/blockRewards.js +16 -5
- package/lib/rewards/blockRewards.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +4 -2
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +1 -1
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +1 -3
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +2 -2
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +1 -0
- package/lib/testUtils/util.js.map +1 -1
- package/lib/util/index.d.ts +1 -1
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -1
- package/lib/util/index.js.map +1 -1
- package/lib/util/loadState/loadValidator.d.ts +2 -1
- package/lib/util/loadState/loadValidator.d.ts.map +1 -1
- package/lib/util/loadState/loadValidator.js +3 -6
- package/lib/util/loadState/loadValidator.js.map +1 -1
- package/lib/util/sszBytes.d.ts +3 -1
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +12 -0
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +9 -9
- package/src/lightClient/spec/utils.ts +3 -3
- package/src/lightClient/spec/validateLightClientUpdate.ts +2 -5
- package/src/rewards/blockRewards.ts +18 -5
- package/src/stateView/beaconStateView.ts +4 -2
- package/src/stateView/interface.ts +1 -1
- package/src/stateView/nativeBeaconStateView.ts +2 -6
- package/src/testUtils/util.ts +1 -0
- package/src/util/index.ts +1 -0
- package/src/util/loadState/loadValidator.ts +5 -6
- package/src/util/sszBytes.ts +18 -1
|
@@ -46,7 +46,8 @@ function getSameFields(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Extract and deserialize validator effective balances from state bytes
|
|
49
|
+
* Extract and deserialize validator effective balances from state bytes,
|
|
50
|
+
* an index not in the validator registry has an effective balance of 0
|
|
50
51
|
*/
|
|
51
52
|
export function getEffectiveBalancesFromStateBytes(
|
|
52
53
|
config: ChainForkConfig,
|
|
@@ -67,11 +68,9 @@ export function getEffectiveBalancesFromStateBytes(
|
|
|
67
68
|
|
|
68
69
|
for (const index of validatorIndices) {
|
|
69
70
|
const validatorBytes = validatorsBytes.subarray(index * validatorSize, (index + 1) * validatorSize);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const validator = ssz.phase0.Validator.deserialize(validatorBytes);
|
|
74
|
-
effectiveBalances.push(validator.effectiveBalance);
|
|
71
|
+
effectiveBalances.push(
|
|
72
|
+
validatorBytes.byteLength === 0 ? 0 : ssz.phase0.Validator.deserialize(validatorBytes).effectiveBalance
|
|
73
|
+
);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
return effectiveBalances;
|
package/src/util/sszBytes.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {EFFECTIVE_BALANCE_INCREMENT, ForkAll, ForkSeq} from "@lodestar/params";
|
|
3
|
-
import {Epoch, SSZTypesFor, Slot, ssz} from "@lodestar/types";
|
|
3
|
+
import {Epoch, SSZTypesFor, Slot, phase0, ssz} from "@lodestar/types";
|
|
4
4
|
import {bytesToInt} from "@lodestar/utils";
|
|
5
5
|
|
|
6
6
|
const UINT64_SIZE = 8;
|
|
@@ -136,6 +136,23 @@ export function getValidatorPubkeyFromStateBytes(
|
|
|
136
136
|
return stateBytes.subarray(start, start + PUBKEY_SIZE);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
/** Returns null if the index is not in the registry. */
|
|
140
|
+
export function getValidatorFromStateBytes(
|
|
141
|
+
config: ChainForkConfig,
|
|
142
|
+
stateBytes: Uint8Array,
|
|
143
|
+
index: number
|
|
144
|
+
): phase0.Validator | null {
|
|
145
|
+
const range = getValidatorsRangeFromStateBytes(stateBytes, getStateTypeFromBytes(config, stateBytes));
|
|
146
|
+
if (range === null) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const start = range.start + index * VALIDATOR_BYTES_SIZE;
|
|
150
|
+
if (index < 0 || start >= range.end) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return ssz.phase0.Validator.deserialize(stateBytes.subarray(start, start + VALIDATOR_BYTES_SIZE));
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
function getValidatorsRangeFromStateBytes(
|
|
140
157
|
stateBytes: Uint8Array,
|
|
141
158
|
stateType: SSZTypesFor<ForkAll, "BeaconState">
|