@lodestar/state-transition 2.1.0-dev.7fecddd274 → 2.1.0-dev.83de993334

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.
Files changed (45) hide show
  1. package/lib/lightClient/spec/utils.d.ts +0 -1
  2. package/lib/lightClient/spec/utils.d.ts.map +1 -1
  3. package/lib/lightClient/spec/utils.js +3 -3
  4. package/lib/lightClient/spec/utils.js.map +1 -1
  5. package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
  6. package/lib/lightClient/spec/validateLightClientUpdate.js +2 -5
  7. package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
  8. package/lib/rewards/blockRewards.d.ts.map +1 -1
  9. package/lib/rewards/blockRewards.js +16 -5
  10. package/lib/rewards/blockRewards.js.map +1 -1
  11. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  12. package/lib/stateView/beaconStateView.js +4 -2
  13. package/lib/stateView/beaconStateView.js.map +1 -1
  14. package/lib/stateView/interface.d.ts +1 -1
  15. package/lib/stateView/interface.d.ts.map +1 -1
  16. package/lib/stateView/nativeBeaconStateView.d.ts +1 -3
  17. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
  18. package/lib/stateView/nativeBeaconStateView.js +2 -2
  19. package/lib/stateView/nativeBeaconStateView.js.map +1 -1
  20. package/lib/testUtils/util.d.ts.map +1 -1
  21. package/lib/testUtils/util.js +1 -0
  22. package/lib/testUtils/util.js.map +1 -1
  23. package/lib/util/index.d.ts +1 -1
  24. package/lib/util/index.d.ts.map +1 -1
  25. package/lib/util/index.js +1 -1
  26. package/lib/util/index.js.map +1 -1
  27. package/lib/util/loadState/loadValidator.d.ts +2 -1
  28. package/lib/util/loadState/loadValidator.d.ts.map +1 -1
  29. package/lib/util/loadState/loadValidator.js +3 -6
  30. package/lib/util/loadState/loadValidator.js.map +1 -1
  31. package/lib/util/sszBytes.d.ts +3 -1
  32. package/lib/util/sszBytes.d.ts.map +1 -1
  33. package/lib/util/sszBytes.js +12 -0
  34. package/lib/util/sszBytes.js.map +1 -1
  35. package/package.json +10 -10
  36. package/src/lightClient/spec/utils.ts +3 -3
  37. package/src/lightClient/spec/validateLightClientUpdate.ts +2 -5
  38. package/src/rewards/blockRewards.ts +18 -5
  39. package/src/stateView/beaconStateView.ts +4 -2
  40. package/src/stateView/interface.ts +1 -1
  41. package/src/stateView/nativeBeaconStateView.ts +2 -6
  42. package/src/testUtils/util.ts +1 -0
  43. package/src/util/index.ts +1 -0
  44. package/src/util/loadState/loadValidator.ts +5 -6
  45. 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
- if (validatorBytes.byteLength === 0) {
71
- throw Error(`Validator index ${index} out of range`);
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;
@@ -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">