Skip to content
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: Add timeouts for request / response stream connections #8434

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b51e908
feat: cleanup publisher
LHerskind Aug 22, 2024
da2eb7a
refactor: get rid of timetraveler from l1-publisher
LHerskind Aug 28, 2024
3388966
feat: revert if timestamp in future
LHerskind Aug 28, 2024
13a60a3
feat: including txhashes explicitly in the rollup attestations
Maddiaa0 Aug 29, 2024
86026f2
temp
Maddiaa0 Aug 30, 2024
f3eac5b
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Aug 30, 2024
fc7a04a
temp
Maddiaa0 Aug 30, 2024
9eed298
temp
Maddiaa0 Sep 2, 2024
cc09455
temp
Maddiaa0 Sep 2, 2024
06f950f
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 2, 2024
4727cd9
temp: get passing with txhash payloads
Maddiaa0 Sep 3, 2024
b4c2a46
fix: make sure transactions are available in the tx pool
Maddiaa0 Sep 5, 2024
4a8d178
chore: remove logs
Maddiaa0 Sep 5, 2024
b4324fc
fmt
Maddiaa0 Sep 5, 2024
052641a
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 5, 2024
a803a94
🪿
Maddiaa0 Sep 5, 2024
164c117
chore: validator tests
Maddiaa0 Sep 6, 2024
27da59d
Add timeouts to individual reqresp connections
Maddiaa0 Sep 6, 2024
9e7d2d8
fix
Maddiaa0 Sep 6, 2024
3c8e1b9
chore: include tests for specific error messages
Maddiaa0 Sep 6, 2024
9a738e5
fmt
Maddiaa0 Sep 6, 2024
c10260c
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 6, 2024
045af5a
clean
Maddiaa0 Sep 6, 2024
73d26ec
🧹
Maddiaa0 Sep 6, 2024
d358228
chore: fix sequencing tests
Maddiaa0 Sep 7, 2024
4b31953
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 7, 2024
2f82a8f
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 7, 2024
f673593
fmt
Maddiaa0 Sep 7, 2024
a15ab17
fmt
Maddiaa0 Sep 7, 2024
2e3f80b
fmt solidity
Maddiaa0 Sep 7, 2024
ae2a05e
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 7, 2024
5734006
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 7, 2024
1bde1fe
fix: test hash
Maddiaa0 Sep 8, 2024
c775b26
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 8, 2024
7a50a2b
exp: adjust test nodes
Maddiaa0 Sep 8, 2024
72f98bd
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 8, 2024
998f38c
chore: add reqresp configuration values to p2p config
Maddiaa0 Sep 8, 2024
1c2b151
fix: use abi.encode vs encodePacked
Maddiaa0 Sep 11, 2024
e6e7f6b
fix
Maddiaa0 Sep 11, 2024
6f417fc
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 11, 2024
cde6283
fix: merge fix
Maddiaa0 Sep 11, 2024
8290c99
fmt
Maddiaa0 Sep 11, 2024
b13ca93
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 11, 2024
1452017
Merge branch 'master' into md/check-tx-requests-before-signing
Maddiaa0 Sep 11, 2024
120c9a3
Merge branch 'md/check-tx-requests-before-signing' into md/09-06-add_…
Maddiaa0 Sep 11, 2024
9b90fe1
Merge branch 'master' into md/09-06-add_timeouts_to_individual_reqres…
Maddiaa0 Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
* @param _signatures - Signatures from the validators
* @param _body - The body of the L2 block
*/
function propose(
function proposeWithBody(
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body
) external override(IRollup) {
AVAILABILITY_ORACLE.publish(_body);
propose(_header, _archive, _blockHash, _signatures);
propose(_header, _archive, _blockHash, _txHashes, _signatures);
}

/**
Expand Down Expand Up @@ -386,6 +387,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
revert Errors.Rollup__SlotAlreadyInChain(lastSlot, slot);
}

// Make sure that the proposer is up to date
bytes32 tipArchive = archive();
if (tipArchive != _archive) {
revert Errors.Rollup__InvalidArchive(tipArchive, _archive);
Expand Down Expand Up @@ -423,7 +425,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
}

/**
* @notice propose an incoming L2 block with signatures
* @notice Propose an incoming L2 block with signatures
*
* @param _header - The L2 block header
* @param _archive - A root of the archive tree after the L2 block is applied
Expand All @@ -434,15 +436,18 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
SignatureLib.Signature[] memory _signatures
) public override(IRollup) {
// Decode and validate header
HeaderLib.Header memory header = HeaderLib.decode(_header);
setupEpoch();

bytes32 digest = keccak256(abi.encodePacked(_archive, _txHashes));
_validateHeader({
_header: header,
_signatures: _signatures,
_digest: _archive,
_digest: digest,
_currentTime: block.timestamp,
_flags: DataStructures.ExecutionFlags({ignoreDA: false, ignoreSignatures: false})
});
Expand Down Expand Up @@ -496,7 +501,8 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
override(IRollup)
{
SignatureLib.Signature[] memory emptySignatures = new SignatureLib.Signature[](0);
propose(_header, _archive, _blockHash, emptySignatures);
bytes32[] memory emptyTxHashes = new bytes32[](0);
propose(_header, _archive, _blockHash, emptyTxHashes, emptySignatures);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ interface IRollup {

function OUTBOX() external view returns (IOutbox);

function propose(
function proposeWithBody(
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body
) external;
Expand All @@ -52,6 +53,7 @@ interface IRollup {
bytes calldata _header,
bytes32 _archive,
bytes32 _blockHash,
bytes32[] memory _txHashes,
SignatureLib.Signature[] memory _signatures
) external;

Expand Down
3 changes: 0 additions & 3 deletions l1-contracts/src/core/sequencer_selection/Leonidas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ contract Leonidas is Ownable, ILeonidas {

/**
* @notice Get the validator set for the current epoch
*
* @dev Makes a call to setupEpoch under the hood, this should ONLY be called as a view function, and not from within
* this contract.
* @return The validator set for the current epoch
*/
function getCurrentEpochCommittee() external view override(ILeonidas) returns (address[] memory) {
Expand Down
7 changes: 5 additions & 2 deletions l1-contracts/test/sparta/Sparta.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ contract SpartaTest is DecoderBase {

rollup.setupEpoch();

bytes32[] memory txHashes = new bytes32[](0);

if (_signatureCount > 0 && ree.proposer != address(0)) {
address[] memory validators = rollup.getEpochCommittee(rollup.getCurrentEpoch());
ree.needed = validators.length * 2 / 3 + 1;

SignatureLib.Signature[] memory signatures = new SignatureLib.Signature[](_signatureCount);

bytes32 digest = keccak256(abi.encodePacked(archive, txHashes));
for (uint256 i = 0; i < _signatureCount; i++) {
signatures[i] = createSignature(validators[i], archive);
signatures[i] = createSignature(validators[i], digest);
}

if (_expectRevert) {
Expand Down Expand Up @@ -219,7 +222,7 @@ contract SpartaTest is DecoderBase {
}

vm.prank(ree.proposer);
rollup.propose(header, archive, bytes32(0), signatures);
rollup.propose(header, archive, bytes32(0), txHashes, signatures);

if (ree.shouldRevert) {
return;
Expand Down
8 changes: 5 additions & 3 deletions yarn-project/archiver/src/archiver/eth_log_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function getBlockMetadataFromRollupTx(
data,
});

if (!(functionName === 'propose')) {
if (!(functionName === 'propose' || functionName === 'proposeWithBody')) {
throw new Error(`Unexpected method called ${functionName}`);
}
const [headerHex, archiveRootHex, _] = args! as readonly [Hex, Hex, Hex];
Expand Down Expand Up @@ -152,17 +152,19 @@ async function getBlockBodiesFromAvailabilityOracleTx(
// [
// "propose(bytes,bytes32,bytes32,(bool,uint8,bytes32,bytes32)[],bytes)": "08978fe9",
// "propose(bytes,bytes32,bytes32,bytes)": "81e6f472",
// "proposeWithBody(bytes,bytes32,bytes32,bytes32[],(bool,uint8,bytes32,bytes32)[],bytes)": "b2283b07",
// "publish(bytes calldata _body)"
// ]
const DATA_INDEX = [4, 3, 0];
const SUPPORTED_SIGS = ['0x08978fe9', '0x81e6f472', '0x7fd28346'];
const DATA_INDEX = [4, 3, 5, 0]; // index where the body is, in the parameters list
const SUPPORTED_SIGS = ['0x08978fe9', '0x81e6f472', '0xb2283b07', '0x7fd28346'];

const signature = slice(data, 0, 4);

if (!SUPPORTED_SIGS.includes(signature)) {
throw new Error(`Unexpected method called ${signature}`);
}

// Check if explicitly calling the DA oracle
if (signature === SUPPORTED_SIGS[SUPPORTED_SIGS.length - 1]) {
const { args } = decodeFunctionData({
abi: AvailabilityOracleAbi,
Expand Down
22 changes: 17 additions & 5 deletions yarn-project/circuit-types/src/p2p/block_attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Buffer32 } from '@aztec/foundation/buffer';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { recoverMessageAddress } from 'viem';
import { keccak256, recoverMessageAddress } from 'viem';

import { TxHash } from '../tx/tx_hash.js';
import { Gossipable } from './gossipable.js';
import { Signature } from './signature.js';
import { TopicType, createTopicString } from './topic_type.js';
Expand All @@ -31,6 +32,7 @@ export class BlockAttestation extends Gossipable {
public readonly header: Header,
// TODO(https://github.com/AztecProtocol/aztec-packages/pull/7727#discussion_r1713670830): temporary
public readonly archive: Fr,
public readonly txHashes: TxHash[],
/** The signature of the block attester */
public readonly signature: Signature,
) {
Expand All @@ -53,8 +55,9 @@ export class BlockAttestation extends Gossipable {
async getSender() {
if (!this.sender) {
// Recover the sender from the attestation
const hashed = keccak256(this.getPayload());
const address = await recoverMessageAddress({
message: { raw: this.p2pMessageIdentifier().to0xString() },
message: { raw: hashed },
signature: this.signature.to0xString(),
});
// Cache the sender for later use
Expand All @@ -64,16 +67,25 @@ export class BlockAttestation extends Gossipable {
return this.sender;
}

getPayload(): Buffer {
return serializeToBuffer([this.archive, this.txHashes]);
}

toBuffer(): Buffer {
return serializeToBuffer([this.header, this.archive, this.signature]);
return serializeToBuffer([this.header, this.archive, this.txHashes.length, this.txHashes, this.signature]);
}

static fromBuffer(buf: Buffer | BufferReader): BlockAttestation {
const reader = BufferReader.asReader(buf);
return new BlockAttestation(reader.readObject(Header), reader.readObject(Fr), reader.readObject(Signature));
return new BlockAttestation(
reader.readObject(Header),
reader.readObject(Fr),
reader.readArray(reader.readNumber(), TxHash),
reader.readObject(Signature),
);
}

static empty(): BlockAttestation {
return new BlockAttestation(Header.empty(), Fr.ZERO, Signature.empty());
return new BlockAttestation(Header.empty(), Fr.ZERO, [], Signature.empty());
}
}
9 changes: 7 additions & 2 deletions yarn-project/circuit-types/src/p2p/block_proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Buffer32 } from '@aztec/foundation/buffer';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { recoverMessageAddress } from 'viem';
import { keccak256, recoverMessageAddress } from 'viem';

import { TxHash } from '../tx/tx_hash.js';
import { Gossipable } from './gossipable.js';
Expand Down Expand Up @@ -55,8 +55,9 @@ export class BlockProposal extends Gossipable {
async getSender() {
if (!this.sender) {
// performance note(): this signature method requires another hash behind the scenes
const hashed = keccak256(this.getPayload());
const address = await recoverMessageAddress({
message: { raw: this.p2pMessageIdentifier().to0xString() },
message: { raw: hashed },
signature: this.signature.to0xString(),
});
// Cache the sender for later use
Expand All @@ -66,6 +67,10 @@ export class BlockProposal extends Gossipable {
return this.sender;
}

getPayload() {
return serializeToBuffer([this.archive, this.txs]);
}

toBuffer(): Buffer {
return serializeToBuffer([this.header, this.archive, this.txs.length, this.txs, this.signature]);
}
Expand Down
11 changes: 8 additions & 3 deletions yarn-project/circuit-types/src/p2p/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { makeHeader } from '@aztec/circuits.js/testing';
import { Fr } from '@aztec/foundation/fields';
import { serializeToBuffer } from '@aztec/foundation/serialize';

import { type PrivateKeyAccount } from 'viem';
import { keccak256 } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';

import { TxHash } from '../tx/tx_hash.js';
Expand All @@ -15,7 +17,8 @@ export const makeBlockProposal = async (signer?: PrivateKeyAccount): Promise<Blo
const blockHeader = makeHeader(1);
const archive = Fr.random();
const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
const signature = Signature.from0xString(await signer.signMessage({ message: { raw: archive.toString() } }));
const hash = keccak256(serializeToBuffer([archive, txs]));
const signature = Signature.from0xString(await signer.signMessage({ message: { raw: hash } }));

return new BlockProposal(blockHeader, archive, txs, signature);
};
Expand All @@ -26,9 +29,11 @@ export const makeBlockAttestation = async (signer?: PrivateKeyAccount): Promise<

const blockHeader = makeHeader(1);
const archive = Fr.random();
const signature = Signature.from0xString(await signer.signMessage({ message: { raw: archive.toString() } }));
const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
const hash = keccak256(serializeToBuffer([archive, txs]));
const signature = Signature.from0xString(await signer.signMessage({ message: { raw: hash } }));

return new BlockAttestation(blockHeader, archive, signature);
return new BlockAttestation(blockHeader, archive, txs, signature);
};

export const randomSigner = (): PrivateKeyAccount => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ describe('L1Publisher integration', () => {

writeJson(`mixed_block_${block.number}`, block, l1ToL2Content, recipientAddress, deployerAccount.address);

await publisher.processL2Block(block);
await publisher.proposeL2Block(block);

const logs = await publicClient.getLogs({
address: rollupAddress,
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('L1Publisher integration', () => {

writeJson(`empty_block_${block.number}`, block, [], AztecAddress.ZERO, deployerAccount.address);

await publisher.processL2Block(block);
await publisher.proposeL2Block(block);

const logs = await publicClient.getLogs({
address: rollupAddress,
Expand Down
Loading