-
Notifications
You must be signed in to change notification settings - Fork 610
chore(vc): p2p message cleanup + attestaion + proposal types #7733
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
Merged
Maddiaa0
merged 13 commits into
master
from
md/08-01-chore_vc_p2p_message_cleanup_attestaion_proposal_types
Aug 6, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bca15df
chore(vc): p2p message cleanup + attestaion + proposal types
Maddiaa0 ef09584
Merge branch 'master' into md/08-01-chore_vc_p2p_message_cleanup_atte…
Maddiaa0 1fc8c24
chore: baseHashType refactor
Maddiaa0 6f8bcbf
chore: reorg files to prevent circ
Maddiaa0 13d3a64
fmt
Maddiaa0 0a782fc
Merge branch 'master' into md/08-01-chore_vc_p2p_message_cleanup_atte…
Maddiaa0 d1a5bea
chore: add base hash type to node deserializer
Maddiaa0 0748ba4
chore: update pxe client
Maddiaa0 13eb3d3
fix
Maddiaa0 8074139
fix: formatting
Maddiaa0 1b1bbf0
fix
Maddiaa0 69b51cd
review
Maddiaa0 cde82f4
Merge branch 'master' into md/08-01-chore_vc_p2p_message_cleanup_atte…
Maddiaa0 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
22 changes: 22 additions & 0 deletions
22
yarn-project/circuit-types/src/p2p/block_attestation.test.ts
This file contains hidden or 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,22 @@ | ||
| // Serde test for the block attestation type | ||
| import { makeHeader } from '@aztec/circuits.js/testing'; | ||
|
|
||
| import { BlockAttestation } from './block_attestation.js'; | ||
|
|
||
| const makeBlockAttestation = (): BlockAttestation => { | ||
| const blockHeader = makeHeader(1); | ||
| const signature = Buffer.alloc(64, 1); | ||
|
|
||
| return new BlockAttestation(blockHeader, signature); | ||
| }; | ||
|
|
||
| describe('Block Attestation serialization / deserialization', () => { | ||
| it('Should serialize / deserialize', () => { | ||
| const attestation = makeBlockAttestation(); | ||
|
|
||
| const serialized = attestation.toBuffer(); | ||
| const deserialized = BlockAttestation.fromBuffer(serialized); | ||
|
|
||
| expect(deserialized).toEqual(attestation); | ||
| }); | ||
| }); |
This file contains hidden or 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,48 @@ | ||
| import { Header } from '@aztec/circuits.js'; | ||
| import { BaseHashType } from '@aztec/foundation/hash'; | ||
| import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; | ||
|
|
||
| import { Gossipable } from './gossipable.js'; | ||
| import { TopicType, createTopicString } from './topic_type.js'; | ||
|
|
||
| export class BlockAttestationHash extends BaseHashType { | ||
| constructor(hash: Buffer) { | ||
| super(hash); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * BlockAttestation | ||
| * | ||
| * A validator that has attested to seeing the contents of a block | ||
| * will produce a block attestation over the header of the block | ||
| */ | ||
| export class BlockAttestation extends Gossipable { | ||
| static override p2pTopic: string; | ||
|
|
||
| constructor( | ||
| /** The block header the attestation is made over */ | ||
| public readonly header: Header, | ||
| /** The signature of the block attester */ | ||
| public readonly signature: Buffer, | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| static { | ||
| this.p2pTopic = createTopicString(TopicType.block_attestation); | ||
| } | ||
|
|
||
| override p2pMessageIdentifier(): BaseHashType { | ||
| return BlockAttestationHash.fromField(this.header.hash()); | ||
| } | ||
|
|
||
| toBuffer(): Buffer { | ||
| return serializeToBuffer([this.header, this.signature.length, this.signature]); | ||
| } | ||
|
|
||
| static fromBuffer(buf: Buffer | BufferReader): BlockAttestation { | ||
| const reader = BufferReader.asReader(buf); | ||
| return new BlockAttestation(reader.readObject(Header), reader.readBuffer()); | ||
| } | ||
| } |
This file contains hidden or 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,24 @@ | ||
| // Serde test for the block proposal type | ||
| import { makeHeader } from '@aztec/circuits.js/testing'; | ||
|
|
||
| import { TxHash } from '../index.js'; | ||
| import { BlockProposal } from './block_proposal.js'; | ||
|
|
||
| describe('Block Proposal serialization / deserialization', () => { | ||
| const makeBlockProposal = (): BlockProposal => { | ||
| const blockHeader = makeHeader(1); | ||
| const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random()); | ||
| const signature = Buffer.alloc(64, 1); | ||
|
|
||
| return new BlockProposal(blockHeader, txs, signature); | ||
| }; | ||
|
|
||
| it('Should serialize / deserialize', () => { | ||
| const proposal = makeBlockProposal(); | ||
|
|
||
| const serialized = proposal.toBuffer(); | ||
| const deserialized = BlockProposal.fromBuffer(serialized); | ||
|
|
||
| expect(deserialized).toEqual(proposal); | ||
| }); | ||
| }); |
This file contains hidden or 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,55 @@ | ||
| import { Header } from '@aztec/circuits.js'; | ||
| import { BaseHashType } from '@aztec/foundation/hash'; | ||
| import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; | ||
|
|
||
| import { TxHash } from '../index.js'; | ||
| import { Gossipable } from './gossipable.js'; | ||
| import { TopicType, createTopicString } from './topic_type.js'; | ||
|
|
||
| export class BlockProposalHash extends BaseHashType { | ||
| constructor(hash: Buffer) { | ||
| super(hash); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * BlockProposal | ||
| * | ||
| * A block proposal is created by the leader of the chain proposing a sequence of transactions to | ||
| * be included in the head of the chain | ||
| */ | ||
| export class BlockProposal extends Gossipable { | ||
| static override p2pTopic: string; | ||
|
|
||
| constructor( | ||
| /** The block header, after execution of the below sequence of transactions */ | ||
| public readonly header: Header, | ||
| /** The sequence of transactions in the block */ | ||
| public readonly txs: TxHash[], | ||
| /** The signer of the BlockProposal over the header of the new block*/ | ||
| public readonly signature: Buffer, | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| static { | ||
| this.p2pTopic = createTopicString(TopicType.block_proposal); | ||
| } | ||
|
|
||
| override p2pMessageIdentifier(): BaseHashType { | ||
| return BlockProposalHash.fromField(this.header.hash()); | ||
| } | ||
|
|
||
| toBuffer(): Buffer { | ||
| return serializeToBuffer([this.header, this.txs.length, this.txs, this.signature.length, this.signature]); | ||
| } | ||
|
|
||
| static fromBuffer(buf: Buffer | BufferReader): BlockProposal { | ||
| const reader = BufferReader.asReader(buf); | ||
| return new BlockProposal( | ||
| reader.readObject(Header), | ||
| reader.readArray(reader.readNumber(), TxHash), | ||
| reader.readBuffer(), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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 { type BaseHashType } from '@aztec/foundation/hash'; | ||
|
|
||
| /** | ||
| * Gossipable | ||
| * | ||
| * Any class which extends gossipable will be able to be Gossiped over the p2p network | ||
| */ | ||
| export abstract class Gossipable { | ||
| /** p2p Topic | ||
| * | ||
| * - The p2p topic identifier, this determines how the message is handled | ||
| */ | ||
| static p2pTopic: string; | ||
|
|
||
| /** p2p Message Identifier | ||
| * | ||
| * - A digest of the message information, this key is used for deduplication | ||
| */ | ||
| abstract p2pMessageIdentifier(): BaseHashType; | ||
|
|
||
| /** To Buffer | ||
| * | ||
| * - Serialization method | ||
| */ | ||
| abstract toBuffer(): Buffer; | ||
| } |
This file contains hidden or 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,5 @@ | ||
| export * from './block_attestation.js'; | ||
| export * from './block_proposal.js'; | ||
| export * from './interface.js'; | ||
| export * from './gossipable.js'; | ||
| export * from './topic_type.js'; |
This file contains hidden or 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,17 @@ | ||
| import { Tx } from '../tx/tx.js'; | ||
| import { BlockAttestation } from './block_attestation.js'; | ||
| import { BlockProposal } from './block_proposal.js'; | ||
| import { type Gossipable } from './gossipable.js'; | ||
| import { TopicType } from './topic_type.js'; | ||
|
|
||
| export interface RawGossipMessage { | ||
| topic: string; | ||
| data: Uint8Array; | ||
| } | ||
|
|
||
| // Force casts as we know that each field here extends Gossipable, and we just want types from Gossipable | ||
| export const TopicTypeMap: Record<string, typeof Gossipable> = { | ||
| [TopicType.tx]: Tx as unknown as typeof Gossipable, | ||
| [TopicType.block_proposal]: BlockProposal as unknown as typeof Gossipable, | ||
| [TopicType.block_attestation]: BlockAttestation as unknown as typeof Gossipable, | ||
| }; |
This file contains hidden or 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,18 @@ | ||
| /** Create Topic String | ||
| * | ||
| * The topic channel identifier | ||
| * @param topicType | ||
| * @returns | ||
| */ | ||
| export function createTopicString(topicType: TopicType) { | ||
| return '/aztec/' + topicType + '/0.1.0'; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| export enum TopicType { | ||
| tx = 'tx', | ||
| block_proposal = 'block_proposal', | ||
| block_attestation = 'block_attestation', | ||
| } |
This file contains hidden or 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.
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.
I think this is good for now, but do we ultimately want to gossip the full TxObject? Since this may have come from a builder and the TxObject may not have been in the mempool?
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.
agreed, the granularity will likely need to change