@lodestar/state-transition 1.44.0-dev.552cdce8d0 → 1.44.0-dev.5a822af737

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 (56) hide show
  1. package/lib/block/processDepositRequest.d.ts.map +1 -1
  2. package/lib/block/processDepositRequest.js +2 -1
  3. package/lib/block/processDepositRequest.js.map +1 -1
  4. package/lib/block/processOperations.d.ts.map +1 -1
  5. package/lib/block/processOperations.js +3 -2
  6. package/lib/block/processOperations.js.map +1 -1
  7. package/lib/cache/epochCache.d.ts.map +1 -1
  8. package/lib/cache/epochCache.js +10 -7
  9. package/lib/cache/epochCache.js.map +1 -1
  10. package/lib/epoch/processPendingDeposits.d.ts.map +1 -1
  11. package/lib/epoch/processPendingDeposits.js +4 -3
  12. package/lib/epoch/processPendingDeposits.js.map +1 -1
  13. package/lib/epoch/processProposerLookahead.d.ts.map +1 -1
  14. package/lib/epoch/processProposerLookahead.js +7 -2
  15. package/lib/epoch/processProposerLookahead.js.map +1 -1
  16. package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
  17. package/lib/slot/upgradeStateToGloas.js +2 -1
  18. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  19. package/lib/stateView/beaconStateView.d.ts +4 -1
  20. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  21. package/lib/stateView/beaconStateView.js +14 -0
  22. package/lib/stateView/beaconStateView.js.map +1 -1
  23. package/lib/stateView/interface.d.ts +29 -1
  24. package/lib/stateView/interface.d.ts.map +1 -1
  25. package/lib/stateView/interface.js.map +1 -1
  26. package/lib/stateView/nativeBeaconStateView.d.ts +230 -0
  27. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -0
  28. package/lib/stateView/nativeBeaconStateView.js +717 -0
  29. package/lib/stateView/nativeBeaconStateView.js.map +1 -0
  30. package/lib/stateView/stateViewFactory.d.ts.map +1 -1
  31. package/lib/stateView/stateViewFactory.js +2 -0
  32. package/lib/stateView/stateViewFactory.js.map +1 -1
  33. package/lib/util/epochShuffling.js +1 -1
  34. package/lib/util/epochShuffling.js.map +1 -1
  35. package/lib/util/gloas.d.ts +14 -0
  36. package/lib/util/gloas.d.ts.map +1 -1
  37. package/lib/util/gloas.js +24 -0
  38. package/lib/util/gloas.js.map +1 -1
  39. package/lib/util/shuffling.d.ts +2 -2
  40. package/lib/util/shuffling.d.ts.map +1 -1
  41. package/lib/util/shuffling.js +4 -3
  42. package/lib/util/shuffling.js.map +1 -1
  43. package/package.json +7 -8
  44. package/src/block/processDepositRequest.ts +2 -1
  45. package/src/block/processOperations.ts +3 -2
  46. package/src/cache/epochCache.ts +10 -7
  47. package/src/epoch/processPendingDeposits.ts +2 -0
  48. package/src/epoch/processProposerLookahead.ts +8 -1
  49. package/src/slot/upgradeStateToGloas.ts +2 -1
  50. package/src/stateView/beaconStateView.ts +17 -0
  51. package/src/stateView/interface.ts +33 -0
  52. package/src/stateView/nativeBeaconStateView.ts +915 -0
  53. package/src/stateView/stateViewFactory.ts +2 -0
  54. package/src/util/epochShuffling.ts +1 -1
  55. package/src/util/gloas.ts +28 -0
  56. package/src/util/shuffling.ts +4 -3
@@ -31,6 +31,7 @@ type NativeOpts = {
31
31
  export function createBeaconStateView(opts: NodeJSOpts | NativeOpts): IBeaconStateView {
32
32
  if (opts.useNative) {
33
33
  throw new Error("Native (Zig) BeaconStateView not yet implemented");
34
+ // TODO: return a new instance of NativeBeaconStateView
34
35
  }
35
36
  const {anchorState, config, pubkeyCache} = opts;
36
37
  const cachedState = createCachedBeaconState(anchorState, {config, pubkeyCache}, {skipSyncPubkeys: true});
@@ -69,6 +70,7 @@ type RegenNativeOpts = {
69
70
  export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts | RegenNativeOpts): IBeaconStateView {
70
71
  if (opts.useNative) {
71
72
  throw new Error("Native (Zig) BeaconStateView not yet implemented");
73
+ // TODO: return a new instance of NativeBeaconStateView
72
74
  }
73
75
  const {config, stateBytes} = opts;
74
76
  const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
@@ -124,7 +124,7 @@ export async function computeEpochShufflingAsync(
124
124
  }
125
125
 
126
126
  export function calculateDecisionRoot(state: BeaconStateAllForks, epoch: Epoch): RootHex {
127
- const pivotSlot = computeStartSlotAtEpoch(epoch - 1) - 1;
127
+ const pivotSlot = Math.max(GENESIS_SLOT, computeStartSlotAtEpoch(epoch - 1) - 1);
128
128
  return toRootHex(getBlockRootAtSlot(state, pivotSlot));
129
129
  }
130
130
 
package/src/util/gloas.ts CHANGED
@@ -73,6 +73,34 @@ export function isActiveBuilder(builder: gloas.Builder, finalizedEpoch: Epoch):
73
73
  return builder.depositEpoch < finalizedEpoch && builder.withdrawableEpoch === FAR_FUTURE_EPOCH;
74
74
  }
75
75
 
76
+ /**
77
+ * Compute the gas limit that satisfies the EIP-1559 adjustment rule from `parentGasLimit`,
78
+ * clamping `targetGasLimit` into the allowed window of `±max(parentGasLimit / 1024, 1) - 1`.
79
+ *
80
+ * From https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md
81
+ */
82
+ export function getExpectedGasLimit(parentGasLimit: number, targetGasLimit: number): number {
83
+ const maxGasLimitDifference = Math.max(Math.floor(parentGasLimit / 1024), 1) - 1;
84
+
85
+ if (targetGasLimit > parentGasLimit) {
86
+ const gasDiff = targetGasLimit - parentGasLimit;
87
+ return parentGasLimit + Math.min(gasDiff, maxGasLimitDifference);
88
+ }
89
+
90
+ const gasDiff = parentGasLimit - targetGasLimit;
91
+ return parentGasLimit - Math.min(gasDiff, maxGasLimitDifference);
92
+ }
93
+
94
+ /**
95
+ * Check if `gasLimit` is compatible with `targetGasLimit` under the EIP-1559 transition rule
96
+ * from `parentGasLimit`. The bid must hit `targetGasLimit` when the target is within one
97
+ * adjustment step of the parent, otherwise it must hit the clamped boundary.
98
+ * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.8/specs/gloas/builder.md#new-is_gas_limit_target_compatible
99
+ */
100
+ export function isGasLimitTargetCompatible(parentGasLimit: number, gasLimit: number, targetGasLimit: number): boolean {
101
+ return gasLimit === getExpectedGasLimit(parentGasLimit, targetGasLimit);
102
+ }
103
+
76
104
  /**
77
105
  * Get the total pending balance to withdraw for a builder (from withdrawals + payments).
78
106
  * Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-get_pending_balance_to_withdraw_for_builder
@@ -21,8 +21,8 @@ import {EpochShuffling} from "./epochShuffling.js";
21
21
  * Computed for the requested epoch, not `state.epoch`, so it is correct when `state` is one
22
22
  * epoch off the requested epoch (e.g. serving next-epoch duties from the current state).
23
23
  *
24
- * Returns `null` when the genesis block decides its own shuffling (caller falls back to the
25
- * genesis block root).
24
+ * Returns `null` when the decision block is not in the state's past (the genesis block decides
25
+ * its own shuffling, or it has not been produced yet); caller supplies the fallback.
26
26
  */
27
27
  export function proposerShufflingDecisionRoot(
28
28
  fork: ForkName,
@@ -30,7 +30,8 @@ export function proposerShufflingDecisionRoot(
30
30
  proposalEpoch: Epoch
31
31
  ): Root | null {
32
32
  const decisionSlot = proposerShufflingDecisionSlot(fork, proposalEpoch);
33
- if (state.slot === decisionSlot) {
33
+ // Return null when the decision block is not in the state's past or the getBlockRootAtSlot() api will throw
34
+ if (decisionSlot >= state.slot) {
34
35
  return null;
35
36
  }
36
37
  return state.getBlockRootAtSlot(decisionSlot);