-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: de-duplicate payloads from persisted beacon blocks #6029
Closed
Closed
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
5d0f20d
WIP with FullOrBlindedSignedBeaconBlock
dapplion 607b8ab
fix(repositories): block type only change to FullOrBlinded
matthewkeil ccb61d2
Draft consumer points
dapplion 2be6b6b
fix: update IBeaconChain and clear error in beaconBlocksByRoot
matthewkeil 19c8031
wip: TODOs. remove commit
matthewkeil cbc892d
fix: rough out to get building
matthewkeil d6ccd9d
feat: move utils to fullOrBlindedBlock.ts
matthewkeil 178399c
feat: build out fullOrBlindedBlock.ts
matthewkeil 15f1125
feat: implement consumers of fullOrBlindedBlock.ts
matthewkeil 788a992
test: fullOrBlindedBlock and add mocks
matthewkeil c140289
feat: block reassembly as generator
matthewkeil 574c8ea
feat: make getBlockHeaders blinded safe
matthewkeil 120ad32
test: debugging fullOrBlindedBlock
matthewkeil 1ca3957
fix: bellatrix reassembleBlindedOrFullToFullBytes
matthewkeil bfea252
fix: capella reassembleBlindedOrFullToFullBytes
matthewkeil 9e9dff4
test: debug fullOrBlindedBlock.ts
matthewkeil 6626aaf
test: fix mocks and get mocks/block modifying for minimal and mainnet
matthewkeil 3b67b2b
refactor: rename blindedBlockToFullBytes in chain/interface
matthewkeil 935ad02
test: fix mocks and get mocks/block modifying for minimal and mainnet
matthewkeil a3dcbfb
feat: pull payload from execution layer
matthewkeil f89d715
chore: fix lint issues
matthewkeil 90c453f
chore: fix check-types error
matthewkeil 615e92e
fix: use toHexString for executionEngine call
matthewkeil 5f0d231
fix: optional chain to fix .timestamp access error
matthewkeil 19332e6
refactor: ensure "blindedOrFullBlock" to function names
matthewkeil 1c4dcb9
test: add byteArrayEqualsThrowBadIndexes
matthewkeil 147baee
refactor: standardize function names
matthewkeil 21211e7
test: perf of not converting serialized
matthewkeil e377d22
refactor: update comment to be more clear
matthewkeil b48e3a8
refactor(beacon-node): make fullOrBlinded function names all consistent
matthewkeil cf81755
fix: add any in beacon-node/test/unit/fullOrBlindedBlock.test for che…
matthewkeil 1d6c713
refactor: remove commented mocks that were updated
matthewkeil 04d4065
chore: fix lint error
matthewkeil 55786b3
refactor: simplify TransactionAndWithdrawals type
matthewkeil bc8ae5d
fix: remove comments making sure there are tests for fullOrBlinded in…
matthewkeil 7840577
refactor: export chainConfig for use in tests that consume the mockBl…
matthewkeil fc02931
test: update workflow with new containers
matthewkeil ddb40af
test: revert workflow to original container versions
matthewkeil 73bd529
feat: throw Eth1Error for invalid payload body
matthewkeil ecaf7f6
fix: convert all json to ssz fixtures
matthewkeil a2edbc1
fix: remove serialized blind/unblind code paths
matthewkeil 4082549
chore: fix lint error
matthewkeil d1998ff
refactor: clean up fullOrBlindedBlock
matthewkeil 2d00248
fix: debugged test:sim:multifork
matthewkeil 16ece98
fix: debug broken test:sim:deneb
matthewkeil 222a000
fix(workflows): comment out broken sim tests for now
matthewkeil c36a0c9
fix: rebase conflicts/updates
matthewkeil 09e10b8
Merge branch 'unstable' into mkeil/dedup-beacon-block-2
matthewkeil 798098e
feat: update types for FullOrBlindedBeaconBlock
matthewkeil ec0970c
feat: add FullOrBlindedSignedBeaconBlock to types
matthewkeil d4e8b9f
fix: update PR for new types PR
matthewkeil d5a07e6
Fix the types
nazarhussain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ import { | |
isBlindedBeaconBlock, | ||
BeaconBlock, | ||
SignedBeaconBlock, | ||
FullOrBlindedSignedBeaconBlock, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we reintroduce this type? Based on discussion in type refactor we don't want this type |
||
ExecutionPayload, | ||
BlindedBeaconBlock, | ||
BlindedBeaconBlockBody, | ||
|
@@ -47,6 +48,14 @@ import {Clock, ClockEvent, IClock} from "../util/clock.js"; | |
import {ensureDir, writeIfNotExist} from "../util/file.js"; | ||
import {isOptimisticBlock} from "../util/forkChoice.js"; | ||
import {BufferPool} from "../util/bufferPool.js"; | ||
import { | ||
blindedOrFullBlockToFull, | ||
deserializeFullOrBlindedSignedBeaconBlock, | ||
getEth1BlockHashFromSerializedBlock, | ||
serializeFullOrBlindedSignedBeaconBlock, | ||
} from "../util/fullOrBlindedBlock.js"; | ||
import {ExecutionPayloadBody} from "../execution/engine/types.js"; | ||
import {Eth1Error, Eth1ErrorCode} from "../eth1/errors.js"; | ||
import {BlockProcessor, ImportBlockOpts} from "./blocks/index.js"; | ||
import {ChainEventEmitter, ChainEvent} from "./emitter.js"; | ||
import { | ||
|
@@ -510,7 +519,11 @@ export class BeaconChain implements IBeaconChain { | |
if (block) { | ||
const data = await this.db.block.get(fromHexString(block.blockRoot)); | ||
if (data) { | ||
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized: false}; | ||
return { | ||
block: await this.blindedOrFullBlockToFull(data), | ||
executionOptimistic: isOptimisticBlock(block), | ||
finalized: false, | ||
}; | ||
} | ||
} | ||
// A non-finalized slot expected to be found in the hot db, could be archived during | ||
|
@@ -519,7 +532,7 @@ export class BeaconChain implements IBeaconChain { | |
} | ||
|
||
const data = await this.db.blockArchive.get(slot); | ||
return data && {block: data, executionOptimistic: false, finalized: true}; | ||
return data && {block: await this.blindedOrFullBlockToFull(data), executionOptimistic: false, finalized: true}; | ||
} | ||
|
||
async getBlockByRoot( | ||
|
@@ -529,7 +542,11 @@ export class BeaconChain implements IBeaconChain { | |
if (block) { | ||
const data = await this.db.block.get(fromHexString(root)); | ||
if (data) { | ||
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized: false}; | ||
return { | ||
block: await this.blindedOrFullBlockToFull(data), | ||
executionOptimistic: isOptimisticBlock(block), | ||
finalized: false, | ||
}; | ||
} | ||
// If block is not found in hot db, try cold db since there could be an archive cycle happening | ||
// TODO: Add a lock to the archiver to have deterministic behavior on where are blocks | ||
|
@@ -574,6 +591,28 @@ export class BeaconChain implements IBeaconChain { | |
return this.produceBlockWrapper<BlockType.Blinded>(BlockType.Blinded, blockAttributes); | ||
} | ||
|
||
async blindedOrFullBlockToFull(block: FullOrBlindedSignedBeaconBlock): Promise<SignedBeaconBlock> { | ||
const info = this.config.getForkInfo(block.message.slot); | ||
return blindedOrFullBlockToFull( | ||
this.config, | ||
info.seq, | ||
block, | ||
await this.getTransactionsAndWithdrawals(info.seq, toHexString(block.message.body.eth1Data.blockHash)) | ||
); | ||
} | ||
|
||
async blindedOrFullBlockToFullBytes(forkSeq: ForkSeq, block: Uint8Array): Promise<Uint8Array> { | ||
return serializeFullOrBlindedSignedBeaconBlock( | ||
this.config, | ||
blindedOrFullBlockToFull( | ||
this.config, | ||
forkSeq, | ||
deserializeFullOrBlindedSignedBeaconBlock(this.config, block), | ||
await this.getTransactionsAndWithdrawals(forkSeq, toHexString(getEth1BlockHashFromSerializedBlock(block))) | ||
) | ||
); | ||
} | ||
|
||
async produceBlockWrapper<T extends BlockType>( | ||
blockType: T, | ||
{ | ||
|
@@ -803,6 +842,23 @@ export class BeaconChain implements IBeaconChain { | |
} | ||
} | ||
|
||
private async getTransactionsAndWithdrawals( | ||
forkSeq: ForkSeq, | ||
blockHash: string | ||
): Promise<Partial<ExecutionPayloadBody>> { | ||
if (forkSeq < ForkSeq.bellatrix) { | ||
return {}; | ||
} | ||
const [payload] = await this.executionEngine.getPayloadBodiesByHash([blockHash]); | ||
if (!payload) { | ||
throw new Eth1Error( | ||
{code: Eth1ErrorCode.INVALID_PAYLOAD_BODY, blockHash}, | ||
"payload body not found by eth1 engine" | ||
); | ||
} | ||
return payload; | ||
} | ||
|
||
/** | ||
* Regenerate state for attestation verification, this does not happen with default chain option of maxSkipSlots = 32 . | ||
* However, need to handle just in case. Lodestar doesn't support multiple regen state requests for attestation verification | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its cleaner to extend blockToHeader to accept full or blinded,
also then the root above can be calulated from the header returned by hashtree root of the blockheader ... it should be more efficient since body won't be merklized twice