-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: rough out fixture building functions
- Loading branch information
1 parent
46b5ddc
commit d9fa635
Showing
8 changed files
with
377 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; | ||
import {ssz, altair} from "@lodestar/types"; | ||
import {BlockGenerationOptionsPhase0, generatePhase0BeaconBlocks} from "./phase0.js"; | ||
import {generateSignature} from "./utils.js"; | ||
|
||
export function generateSyncAggregate( | ||
state: CachedBeaconStateAllForks, | ||
block: altair.BeaconBlock | ||
): altair.SyncAggregate { | ||
return { | ||
syncCommitteeBits: ssz.altair.SyncCommitteeBits.defaultValue(), | ||
syncCommitteeSignature: generateSignature(), | ||
}; | ||
} | ||
|
||
export interface BlockGenerationOptionsAltair extends BlockGenerationOptionsPhase0 {} | ||
|
||
export function generateAltairBeaconBlocks( | ||
state: CachedBeaconStateAllForks, | ||
count: number, | ||
opts?: BlockGenerationOptionsAltair | ||
): altair.BeaconBlock[] { | ||
const blocks = generatePhase0BeaconBlocks(state, count, opts) as altair.BeaconBlock[]; | ||
for (const block of blocks) { | ||
block.body.syncAggregate = generateSyncAggregate(state, block); | ||
} | ||
return blocks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {ssz, bellatrix} from "@lodestar/types"; | ||
import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; | ||
import {BlockGenerationOptionsAltair, generateAltairBeaconBlocks} from "./altair.js"; | ||
|
||
export function generateBellatrixExecutionPayload(): bellatrix.ExecutionPayload { | ||
return { | ||
baseFeePerGas: BigInt(0), | ||
blockHash: new Uint8Array(), | ||
blockNumber: 0, | ||
extraData: new Uint8Array(), | ||
feeRecipient: new Uint8Array(), | ||
gasLimit: 0, | ||
gasUsed: 0, | ||
logsBloom: new Uint8Array(), | ||
parentHash: new Uint8Array(), | ||
prevRandao: new Uint8Array(), | ||
receiptsRoot: new Uint8Array(), | ||
stateRoot: new Uint8Array(), | ||
timestamp: 0, | ||
transactions: [ssz.bellatrix.Transaction.defaultValue()], | ||
}; | ||
} | ||
|
||
export interface BlockGenerationOptionsBellatrix extends BlockGenerationOptionsAltair {} | ||
|
||
export function generateBellatrixBeaconBlocks( | ||
state: CachedBeaconStateAllForks, | ||
count: number, | ||
opts?: BlockGenerationOptionsBellatrix | ||
): bellatrix.BeaconBlock[] { | ||
const blocks = generateAltairBeaconBlocks(state, count, opts) as bellatrix.BeaconBlock[]; | ||
for (const block of blocks) { | ||
block.body.executionPayload = generateBellatrixExecutionPayload(); | ||
} | ||
return blocks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import crypto from "node:crypto"; | ||
import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; | ||
import {capella, deneb} from "@lodestar/types"; | ||
import {MAX_BLOBS_PER_BLOCK} from "@lodestar/params"; | ||
import {generateCapellaBeaconBlocks, BlockGenerationOptionsCapella} from "./capella.js"; | ||
|
||
export function generateDenebExecutionPayload(payload: capella.ExecutionPayload): deneb.ExecutionPayload { | ||
return { | ||
...payload, | ||
blobGasUsed: BigInt(0), | ||
excessBlobGas: BigInt(0), | ||
}; | ||
} | ||
|
||
export function generateKzgCommitments(count: number): deneb.BlobKzgCommitments { | ||
return Array.from({length: count}, () => Uint8Array.from(crypto.randomBytes(48))); | ||
} | ||
|
||
export interface BlockGenerationOptionsDeneb extends BlockGenerationOptionsCapella { | ||
numKzgCommitments: number; | ||
} | ||
|
||
export function generateDenebBeaconBlocks( | ||
state: CachedBeaconStateAllForks, | ||
count: number, | ||
opts?: BlockGenerationOptionsDeneb | ||
): capella.BeaconBlock[] { | ||
const blocks = generateCapellaBeaconBlocks(state, count, opts) as deneb.BeaconBlock[]; | ||
for (const block of blocks) { | ||
block.body.executionPayload = generateDenebExecutionPayload(block.body.executionPayload); | ||
block.body.blobKzgCommitments = generateKzgCommitments(opts?.numKzgCommitments ?? MAX_BLOBS_PER_BLOCK); | ||
} | ||
return blocks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {deneb, electra} from "@lodestar/types"; | ||
import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; | ||
import {BlockGenerationOptionsDeneb, generateDenebBeaconBlocks} from "./deneb.js"; | ||
|
||
export function generateElectraExecutionPayload(payload: deneb.ExecutionPayload): electra.ExecutionPayload { | ||
return { | ||
...payload, | ||
depositRequests: [], | ||
withdrawalRequests: [], | ||
consolidationRequests: [], | ||
}; | ||
} | ||
|
||
export interface BlockGenerationOptionsElectra extends BlockGenerationOptionsDeneb {} | ||
|
||
export function generateElectraBeaconBlocks( | ||
state: CachedBeaconStateAllForks, | ||
count: number, | ||
opts?: BlockGenerationOptionsElectra | ||
): electra.BeaconBlock[] { | ||
const blocks = generateDenebBeaconBlocks(state, count, opts) as electra.BeaconBlock[]; | ||
for (const block of blocks) { | ||
block.body.executionPayload = generateElectraExecutionPayload(block.body.executionPayload); | ||
} | ||
return blocks; | ||
} |
Oops, something went wrong.