@lodestar/state-transition 1.44.0-dev.6ef8199cfa → 1.44.0-dev.79c77e2e57

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 (44) 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/stateView/beaconStateView.d.ts +1 -0
  17. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  18. package/lib/stateView/beaconStateView.js +8 -0
  19. package/lib/stateView/beaconStateView.js.map +1 -1
  20. package/lib/stateView/interface.d.ts +26 -0
  21. package/lib/stateView/interface.d.ts.map +1 -1
  22. package/lib/stateView/interface.js.map +1 -1
  23. package/lib/stateView/nativeBeaconStateView.d.ts +226 -0
  24. package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -0
  25. package/lib/stateView/nativeBeaconStateView.js +698 -0
  26. package/lib/stateView/nativeBeaconStateView.js.map +1 -0
  27. package/lib/stateView/stateViewFactory.d.ts.map +1 -1
  28. package/lib/stateView/stateViewFactory.js +2 -0
  29. package/lib/stateView/stateViewFactory.js.map +1 -1
  30. package/lib/util/gloas.d.ts +14 -0
  31. package/lib/util/gloas.d.ts.map +1 -1
  32. package/lib/util/gloas.js +24 -0
  33. package/lib/util/gloas.js.map +1 -1
  34. package/package.json +7 -8
  35. package/src/block/processDepositRequest.ts +2 -1
  36. package/src/block/processOperations.ts +3 -2
  37. package/src/cache/epochCache.ts +10 -7
  38. package/src/epoch/processPendingDeposits.ts +2 -0
  39. package/src/epoch/processProposerLookahead.ts +8 -1
  40. package/src/stateView/beaconStateView.ts +8 -0
  41. package/src/stateView/interface.ts +30 -0
  42. package/src/stateView/nativeBeaconStateView.ts +893 -0
  43. package/src/stateView/stateViewFactory.ts +2 -0
  44. package/src/util/gloas.ts +28 -0
@@ -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);
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