@lodestar/state-transition 1.38.0 → 1.39.0-dev.0321dbcf04

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 (131) hide show
  1. package/lib/block/index.js +2 -2
  2. package/lib/block/index.js.map +1 -1
  3. package/lib/block/isValidIndexedAttestation.d.ts +6 -5
  4. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  5. package/lib/block/isValidIndexedAttestation.js +9 -10
  6. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  7. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  8. package/lib/block/processAttestationPhase0.js +1 -1
  9. package/lib/block/processAttestationPhase0.js.map +1 -1
  10. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  11. package/lib/block/processAttestationsAltair.js +1 -1
  12. package/lib/block/processAttestationsAltair.js.map +1 -1
  13. package/lib/block/processAttesterSlashing.d.ts +4 -2
  14. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  15. package/lib/block/processAttesterSlashing.js +5 -4
  16. package/lib/block/processAttesterSlashing.js.map +1 -1
  17. package/lib/block/processBlsToExecutionChange.d.ts +3 -1
  18. package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
  19. package/lib/block/processBlsToExecutionChange.js +7 -11
  20. package/lib/block/processBlsToExecutionChange.js.map +1 -1
  21. package/lib/block/processProposerSlashing.d.ts +5 -2
  22. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  23. package/lib/block/processProposerSlashing.js +7 -5
  24. package/lib/block/processProposerSlashing.js.map +1 -1
  25. package/lib/block/processRandao.js +2 -2
  26. package/lib/block/processRandao.js.map +1 -1
  27. package/lib/block/processSyncCommittee.d.ts +4 -1
  28. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  29. package/lib/block/processSyncCommittee.js +7 -6
  30. package/lib/block/processSyncCommittee.js.map +1 -1
  31. package/lib/block/processVoluntaryExit.d.ts.map +1 -1
  32. package/lib/block/processVoluntaryExit.js +2 -1
  33. package/lib/block/processVoluntaryExit.js.map +1 -1
  34. package/lib/block/processWithdrawals.d.ts +3 -3
  35. package/lib/block/processWithdrawals.d.ts.map +1 -1
  36. package/lib/block/processWithdrawals.js +152 -105
  37. package/lib/block/processWithdrawals.js.map +1 -1
  38. package/lib/cache/epochCache.d.ts +0 -3
  39. package/lib/cache/epochCache.d.ts.map +1 -1
  40. package/lib/cache/epochCache.js +0 -3
  41. package/lib/cache/epochCache.js.map +1 -1
  42. package/lib/cache/stateCache.d.ts +1 -0
  43. package/lib/cache/stateCache.d.ts.map +1 -1
  44. package/lib/cache/stateCache.js.map +1 -1
  45. package/lib/index.d.ts +2 -1
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js +2 -0
  48. package/lib/index.js.map +1 -1
  49. package/lib/rewards/attestationsRewards.d.ts +6 -0
  50. package/lib/rewards/attestationsRewards.d.ts.map +1 -0
  51. package/lib/rewards/attestationsRewards.js +113 -0
  52. package/lib/rewards/attestationsRewards.js.map +1 -0
  53. package/lib/rewards/blockRewards.d.ts +13 -0
  54. package/lib/rewards/blockRewards.d.ts.map +1 -0
  55. package/lib/rewards/blockRewards.js +95 -0
  56. package/lib/rewards/blockRewards.js.map +1 -0
  57. package/lib/rewards/index.d.ts +4 -0
  58. package/lib/rewards/index.d.ts.map +1 -0
  59. package/lib/rewards/index.js +4 -0
  60. package/lib/rewards/index.js.map +1 -0
  61. package/lib/rewards/syncCommitteeRewards.d.ts +6 -0
  62. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -0
  63. package/lib/rewards/syncCommitteeRewards.js +36 -0
  64. package/lib/rewards/syncCommitteeRewards.js.map +1 -0
  65. package/lib/signatureSets/attesterSlashings.d.ts +6 -5
  66. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  67. package/lib/signatureSets/attesterSlashings.js +11 -8
  68. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  69. package/lib/signatureSets/blsToExecutionChange.d.ts +1 -2
  70. package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
  71. package/lib/signatureSets/blsToExecutionChange.js +2 -2
  72. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  73. package/lib/signatureSets/index.d.ts +5 -3
  74. package/lib/signatureSets/index.d.ts.map +1 -1
  75. package/lib/signatureSets/index.js +10 -10
  76. package/lib/signatureSets/index.js.map +1 -1
  77. package/lib/signatureSets/indexedAttestation.d.ts +7 -6
  78. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  79. package/lib/signatureSets/indexedAttestation.js +12 -9
  80. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  81. package/lib/signatureSets/proposer.d.ts +7 -6
  82. package/lib/signatureSets/proposer.d.ts.map +1 -1
  83. package/lib/signatureSets/proposer.js +14 -13
  84. package/lib/signatureSets/proposer.js.map +1 -1
  85. package/lib/signatureSets/proposerSlashings.d.ts +5 -4
  86. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  87. package/lib/signatureSets/proposerSlashings.js +8 -6
  88. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  89. package/lib/signatureSets/randao.d.ts +4 -3
  90. package/lib/signatureSets/randao.d.ts.map +1 -1
  91. package/lib/signatureSets/randao.js +7 -6
  92. package/lib/signatureSets/randao.js.map +1 -1
  93. package/lib/signatureSets/voluntaryExits.d.ts +6 -5
  94. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  95. package/lib/signatureSets/voluntaryExits.js +11 -9
  96. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  97. package/lib/stateTransition.js +1 -1
  98. package/lib/stateTransition.js.map +1 -1
  99. package/lib/util/execution.d.ts +2 -7
  100. package/lib/util/execution.d.ts.map +1 -1
  101. package/lib/util/execution.js +7 -25
  102. package/lib/util/execution.js.map +1 -1
  103. package/package.json +14 -11
  104. package/src/block/index.ts +1 -1
  105. package/src/block/isValidIndexedAttestation.ts +25 -12
  106. package/src/block/processAttestationPhase0.ts +10 -1
  107. package/src/block/processAttestationsAltair.ts +7 -1
  108. package/src/block/processAttesterSlashing.ts +20 -5
  109. package/src/block/processBlsToExecutionChange.ts +13 -14
  110. package/src/block/processProposerSlashing.ts +21 -6
  111. package/src/block/processRandao.ts +2 -2
  112. package/src/block/processSyncCommittee.ts +18 -6
  113. package/src/block/processVoluntaryExit.ts +4 -1
  114. package/src/block/processWithdrawals.ts +230 -135
  115. package/src/cache/epochCache.ts +0 -3
  116. package/src/cache/stateCache.ts +1 -0
  117. package/src/index.ts +2 -2
  118. package/src/rewards/attestationsRewards.ts +200 -0
  119. package/src/rewards/blockRewards.ts +147 -0
  120. package/src/rewards/index.ts +3 -0
  121. package/src/rewards/syncCommitteeRewards.ts +59 -0
  122. package/src/signatureSets/attesterSlashings.ts +19 -10
  123. package/src/signatureSets/blsToExecutionChange.ts +2 -3
  124. package/src/signatureSets/index.ts +18 -12
  125. package/src/signatureSets/indexedAttestation.ts +30 -12
  126. package/src/signatureSets/proposer.ts +22 -14
  127. package/src/signatureSets/proposerSlashings.ts +14 -12
  128. package/src/signatureSets/randao.ts +17 -7
  129. package/src/signatureSets/voluntaryExits.ts +19 -11
  130. package/src/stateTransition.ts +1 -1
  131. package/src/util/execution.ts +8 -29
@@ -1,23 +1,28 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
2
3
  import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
3
- import {CachedBeaconStateAllForks} from "../types.js";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
5
  import {computeSigningRoot} from "../util/index.js";
5
6
  import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
6
7
 
7
8
  export function verifyProposerSignature(
8
- state: CachedBeaconStateAllForks,
9
+ config: BeaconConfig,
10
+ index2pubkey: Index2PubkeyCache,
9
11
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
10
12
  ): boolean {
11
- const signatureSet = getBlockProposerSignatureSet(state, signedBlock);
13
+ const signatureSet = getBlockProposerSignatureSet(config, index2pubkey, signedBlock);
12
14
  return verifySignatureSet(signatureSet);
13
15
  }
14
16
 
15
17
  export function getBlockProposerSignatureSet(
16
- state: CachedBeaconStateAllForks,
18
+ config: BeaconConfig,
19
+ index2pubkey: Index2PubkeyCache,
17
20
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
18
21
  ): ISignatureSet {
19
- const {config, epochCtx} = state;
20
- const domain = config.getDomain(state.slot, DOMAIN_BEACON_PROPOSER, signedBlock.message.slot);
22
+ // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
23
+ // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
24
+ const blockSlot = signedBlock.message.slot;
25
+ const domain = config.getDomain(blockSlot, DOMAIN_BEACON_PROPOSER, blockSlot);
21
26
 
22
27
  const blockType = isBlindedBeaconBlock(signedBlock.message)
23
28
  ? config.getPostBellatrixForkTypes(signedBlock.message.slot).BlindedBeaconBlock
@@ -25,37 +30,40 @@ export function getBlockProposerSignatureSet(
25
30
 
26
31
  return {
27
32
  type: SignatureSetType.single,
28
- pubkey: epochCtx.index2pubkey[signedBlock.message.proposerIndex],
33
+ pubkey: index2pubkey[signedBlock.message.proposerIndex],
29
34
  signingRoot: computeSigningRoot(blockType, signedBlock.message, domain),
30
35
  signature: signedBlock.signature,
31
36
  };
32
37
  }
33
38
 
34
39
  export function getBlockHeaderProposerSignatureSetByParentStateSlot(
35
- parentState: CachedBeaconStateAllForks,
40
+ config: BeaconConfig,
41
+ index2pubkey: Index2PubkeyCache,
42
+ parentStateSlot: Slot,
36
43
  signedBlockHeader: phase0.SignedBeaconBlockHeader
37
44
  ) {
38
- return getBlockHeaderProposerSignatureSet(parentState, signedBlockHeader, parentState.slot);
45
+ return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, parentStateSlot);
39
46
  }
40
47
 
41
48
  export function getBlockHeaderProposerSignatureSetByHeaderSlot(
42
- headState: CachedBeaconStateAllForks,
49
+ config: BeaconConfig,
50
+ index2pubkey: Index2PubkeyCache,
43
51
  signedBlockHeader: phase0.SignedBeaconBlockHeader
44
52
  ) {
45
- return getBlockHeaderProposerSignatureSet(headState, signedBlockHeader, signedBlockHeader.message.slot);
53
+ return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, signedBlockHeader.message.slot);
46
54
  }
47
55
 
48
56
  function getBlockHeaderProposerSignatureSet(
49
- state: CachedBeaconStateAllForks,
57
+ config: BeaconConfig,
58
+ index2pubkey: Index2PubkeyCache,
50
59
  signedBlockHeader: phase0.SignedBeaconBlockHeader,
51
60
  domainSlot: Slot
52
61
  ): ISignatureSet {
53
- const {config, epochCtx} = state;
54
62
  const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
55
63
 
56
64
  return {
57
65
  type: SignatureSetType.single,
58
- pubkey: epochCtx.index2pubkey[signedBlockHeader.message.proposerIndex],
66
+ pubkey: index2pubkey[signedBlockHeader.message.proposerIndex],
59
67
  signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeader, signedBlockHeader.message, domain),
60
68
  signature: signedBlockHeader.signature,
61
69
  };
@@ -1,26 +1,24 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
2
- import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
3
- import {CachedBeaconStateAllForks} from "../types.js";
3
+ import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
5
  import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
5
6
 
6
7
  /**
7
8
  * Extract signatures to allow validating all block signatures at once
8
9
  */
9
10
  export function getProposerSlashingSignatureSets(
10
- state: CachedBeaconStateAllForks,
11
+ config: BeaconConfig,
12
+ index2pubkey: Index2PubkeyCache,
13
+ stateSlot: Slot,
11
14
  proposerSlashing: phase0.ProposerSlashing
12
15
  ): ISignatureSet[] {
13
- const {epochCtx} = state;
14
- const pubkey = epochCtx.index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
16
+ const pubkey = index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
15
17
 
16
18
  // In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
17
19
  // clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
18
20
  return [proposerSlashing.signedHeader1, proposerSlashing.signedHeader2].map((signedHeader): ISignatureSet => {
19
- const domain = state.config.getDomain(
20
- state.slot,
21
- DOMAIN_BEACON_PROPOSER,
22
- Number(signedHeader.message.slot as bigint)
23
- );
21
+ const domain = config.getDomain(stateSlot, DOMAIN_BEACON_PROPOSER, Number(signedHeader.message.slot as bigint));
24
22
 
25
23
  return {
26
24
  type: SignatureSetType.single,
@@ -32,10 +30,14 @@ export function getProposerSlashingSignatureSets(
32
30
  }
33
31
 
34
32
  export function getProposerSlashingsSignatureSets(
35
- state: CachedBeaconStateAllForks,
33
+ config: BeaconConfig,
34
+ index2pubkey: Index2PubkeyCache,
36
35
  signedBlock: SignedBeaconBlock
37
36
  ): ISignatureSet[] {
37
+ // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
38
+ // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
39
+ const blockSlot = signedBlock.message.slot;
38
40
  return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
39
- getProposerSlashingSignatureSets(state, proposerSlashing)
41
+ getProposerSlashingSignatureSets(config, index2pubkey, blockSlot, proposerSlashing)
40
42
  );
41
43
  }
@@ -1,6 +1,7 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_RANDAO} from "@lodestar/params";
2
3
  import {BeaconBlock, ssz} from "@lodestar/types";
3
- import {CachedBeaconStateAllForks} from "../types.js";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
5
  import {
5
6
  ISignatureSet,
6
7
  SignatureSetType,
@@ -9,22 +10,31 @@ import {
9
10
  verifySignatureSet,
10
11
  } from "../util/index.js";
11
12
 
12
- export function verifyRandaoSignature(state: CachedBeaconStateAllForks, block: BeaconBlock): boolean {
13
- return verifySignatureSet(getRandaoRevealSignatureSet(state, block));
13
+ export function verifyRandaoSignature(
14
+ config: BeaconConfig,
15
+ index2pubkey: Index2PubkeyCache,
16
+ block: BeaconBlock
17
+ ): boolean {
18
+ return verifySignatureSet(getRandaoRevealSignatureSet(config, index2pubkey, block));
14
19
  }
15
20
 
16
21
  /**
17
22
  * Extract signatures to allow validating all block signatures at once
18
23
  */
19
- export function getRandaoRevealSignatureSet(state: CachedBeaconStateAllForks, block: BeaconBlock): ISignatureSet {
20
- const {epochCtx} = state;
24
+ export function getRandaoRevealSignatureSet(
25
+ config: BeaconConfig,
26
+ index2pubkey: Index2PubkeyCache,
27
+ block: BeaconBlock
28
+ ): ISignatureSet {
21
29
  // should not get epoch from epochCtx
22
30
  const epoch = computeEpochAtSlot(block.slot);
23
- const domain = state.config.getDomain(state.slot, DOMAIN_RANDAO, block.slot);
31
+ // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
32
+ // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
33
+ const domain = config.getDomain(block.slot, DOMAIN_RANDAO, block.slot);
24
34
 
25
35
  return {
26
36
  type: SignatureSetType.single,
27
- pubkey: epochCtx.index2pubkey[block.proposerIndex],
37
+ pubkey: index2pubkey[block.proposerIndex],
28
38
  signingRoot: computeSigningRoot(ssz.Epoch, epoch, domain),
29
39
  signature: block.body.randaoReveal,
30
40
  };
@@ -1,5 +1,6 @@
1
- import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
2
- import {CachedBeaconStateAllForks} from "../types.js";
1
+ import {BeaconConfig} from "@lodestar/config";
2
+ import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {
4
5
  ISignatureSet,
5
6
  SignatureSetType,
@@ -9,36 +10,43 @@ import {
9
10
  } from "../util/index.js";
10
11
 
11
12
  export function verifyVoluntaryExitSignature(
12
- state: CachedBeaconStateAllForks,
13
+ config: BeaconConfig,
14
+ index2pubkey: Index2PubkeyCache,
15
+ stateSlot: Slot,
13
16
  signedVoluntaryExit: phase0.SignedVoluntaryExit
14
17
  ): boolean {
15
- return verifySignatureSet(getVoluntaryExitSignatureSet(state, signedVoluntaryExit));
18
+ return verifySignatureSet(getVoluntaryExitSignatureSet(config, index2pubkey, stateSlot, signedVoluntaryExit));
16
19
  }
17
20
 
18
21
  /**
19
22
  * Extract signatures to allow validating all block signatures at once
20
23
  */
21
24
  export function getVoluntaryExitSignatureSet(
22
- state: CachedBeaconStateAllForks,
25
+ config: BeaconConfig,
26
+ index2pubkey: Index2PubkeyCache,
27
+ stateSlot: Slot,
23
28
  signedVoluntaryExit: phase0.SignedVoluntaryExit
24
29
  ): ISignatureSet {
25
- const {epochCtx} = state;
26
- const slot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
27
- const domain = state.config.getDomainForVoluntaryExit(state.slot, slot);
30
+ const messageSlot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
31
+ const domain = config.getDomainForVoluntaryExit(stateSlot, messageSlot);
28
32
 
29
33
  return {
30
34
  type: SignatureSetType.single,
31
- pubkey: epochCtx.index2pubkey[signedVoluntaryExit.message.validatorIndex],
35
+ pubkey: index2pubkey[signedVoluntaryExit.message.validatorIndex],
32
36
  signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
33
37
  signature: signedVoluntaryExit.signature,
34
38
  };
35
39
  }
36
40
 
37
41
  export function getVoluntaryExitsSignatureSets(
38
- state: CachedBeaconStateAllForks,
42
+ config: BeaconConfig,
43
+ index2pubkey: Index2PubkeyCache,
39
44
  signedBlock: SignedBeaconBlock
40
45
  ): ISignatureSet[] {
46
+ // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
47
+ // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
48
+ const blockSlot = signedBlock.message.slot;
41
49
  return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
42
- getVoluntaryExitSignatureSet(state, voluntaryExit)
50
+ getVoluntaryExitSignatureSet(config, index2pubkey, blockSlot, voluntaryExit)
43
51
  );
44
52
  }
@@ -111,7 +111,7 @@ export function stateTransition(
111
111
  postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
112
112
 
113
113
  // Verify proposer signature only
114
- if (verifyProposer && !verifyProposerSignature(postState, signedBlock)) {
114
+ if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.index2pubkey, signedBlock)) {
115
115
  throw new Error("Invalid block signature");
116
116
  }
117
117
 
@@ -31,51 +31,30 @@ export function isExecutionEnabled(state: BeaconStateExecutions, block: BeaconBl
31
31
  return true;
32
32
  }
33
33
 
34
- // Throws if not post-bellatrix block. A fork-guard in isExecutionEnabled() prevents this from happening
34
+ // Throws if not post-bellatrix block. A fork-guard before isExecutionEnabled() prevents this from happening
35
35
  const payload = getFullOrBlindedPayload(block);
36
- // Note: spec says to check all payload is zero-ed. However a state-root cannot be zero for any non-empty payload
37
- // TODO: Consider comparing with the payload root if this assumption is not correct.
38
- // return !byteArrayEquals(payload.stateRoot, ZERO_HASH);
39
36
 
40
- // UPDATE: stateRoot comparision should have been enough with zero hash, but spec tests were failing
41
- // Revisit this later to fix specs and make this efficient
42
37
  return isExecutionPayload(payload)
43
38
  ? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
44
39
  : !ssz.bellatrix.ExecutionPayloadHeader.equals(
45
40
  state.latestExecutionPayloadHeader,
46
- // TODO: Performance
47
41
  ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
48
42
  );
49
43
  }
50
44
 
51
- /**
52
- * Merge block is the SINGLE block that transitions from POW to POS.
53
- * state has no execution data AND this block has execution data
54
- */
55
- export function isMergeTransitionBlock(state: BeaconStateExecutions, body: bellatrix.BeaconBlockBody): boolean {
56
- return (
57
- !isMergeTransitionComplete(state) &&
58
- !ssz.bellatrix.ExecutionPayload.equals(body.executionPayload, ssz.bellatrix.ExecutionPayload.defaultValue())
59
- );
60
- }
61
-
62
45
  /**
63
46
  * Merge is complete when the state includes execution layer data:
64
- * state.latestExecutionPayloadHeader NOT EMPTY
47
+ * state.latestExecutionPayloadHeader NOT EMPTY or state is post-capella
65
48
  */
66
49
  export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
67
- if (!isCapellaStateType(state)) {
68
- return !ssz.bellatrix.ExecutionPayloadHeader.equals(
69
- (state as BeaconStateBellatrix).latestExecutionPayloadHeader,
70
- // TODO: Performance
71
- ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
72
- );
50
+ if (isCapellaStateType(state)) {
51
+ // All networks have completed the merge transition before capella
52
+ return true;
73
53
  }
74
54
 
75
- return !ssz.capella.ExecutionPayloadHeader.equals(
76
- state.latestExecutionPayloadHeader,
77
- // TODO: Performance
78
- ssz.capella.ExecutionPayloadHeader.defaultValue()
55
+ return !ssz.bellatrix.ExecutionPayloadHeader.equals(
56
+ (state as BeaconStateBellatrix).latestExecutionPayloadHeader,
57
+ ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
79
58
  );
80
59
  }
81
60