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(p2p): GossibSub #6170

Merged
merged 59 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f80d6c8
feat(p2p): DiscV5 Peer Discovery
spypsy Apr 10, 2024
f703226
add cspell, docs
spypsy Apr 10, 2024
99d9a81
merge with master
spypsy Apr 10, 2024
393b422
discv5 unit test
spypsy Apr 10, 2024
65a0786
update logger usage
spypsy Apr 10, 2024
5e5bad1
use running promise
spypsy Apr 10, 2024
4cfcdf6
check discv5 persistence
spypsy Apr 10, 2024
d27fc52
docs & fixes
spypsy Apr 10, 2024
8f3c87a
fix peer store return types
spypsy Apr 10, 2024
1a8196f
fix e2e
spypsy Apr 10, 2024
801cfbc
p2p test app
spypsy Apr 11, 2024
4ec73fe
filter aztec nodes correctly
spypsy Apr 12, 2024
006a121
gossipsub for test app
spypsy Apr 17, 2024
27d32b6
PR Fixes
spypsy Apr 17, 2024
4ad3f84
bootnode config
spypsy Apr 17, 2024
93c7e0e
merge with master
spypsy Apr 17, 2024
03278ca
fix yarn.lock
spypsy Apr 17, 2024
165a6b2
fix config type
spypsy Apr 17, 2024
4f5becf
merge p2p updates
spypsy Apr 17, 2024
19bab6c
update libp2p service
spypsy Apr 22, 2024
d6b4174
merge with master
spypsy Apr 22, 2024
4529a1f
remove unused dep
spypsy Apr 22, 2024
5991fb3
merge with master
spypsy Apr 22, 2024
c7d82ee
Merge branch 'spy/discv5-peer-discovery' into spy/p2p-test-app
spypsy Apr 22, 2024
6cafbf4
yarn install
spypsy Apr 22, 2024
539ae67
lmdb datastore implementation
spypsy Apr 26, 2024
9a42570
tested datastore
spypsy Apr 29, 2024
ae8c18d
peer manager
spypsy May 1, 2024
3db0d5e
fixes
spypsy May 1, 2024
50693ff
minor adds
spypsy May 1, 2024
04f8762
merge with master
spypsy May 1, 2024
6effce8
rm foundry dir
spypsy May 1, 2024
c4a0d58
version fixes
spypsy May 1, 2024
6ee0708
rm unused fn
spypsy May 1, 2024
1977628
fix yarn.lock
spypsy May 1, 2024
eb243c0
fix tcp transport version
spypsy May 2, 2024
9397b42
fix bootstrap node parsing
spypsy May 2, 2024
8613d2c
remove silly log
spypsy May 2, 2024
cbae10e
rm db files
spypsy May 2, 2024
81b39c5
use datastore, remove test app
spypsy May 3, 2024
fdbcced
remove test from package.json
spypsy May 3, 2024
33ca009
Merge branch 'master' into spy/pubsub
spypsy May 3, 2024
b74fa6e
use config datadir
spypsy May 3, 2024
677c90e
fix import
spypsy May 3, 2024
a06b306
Update bootnode, skip flakey test
spypsy May 3, 2024
258ee2f
log string
spypsy May 7, 2024
a75466f
Merge branch 'master' into spy/pubsub
spypsy May 7, 2024
8e08f21
simple PR Fixes
spypsy May 8, 2024
d74c12b
external datastore test suite WIP
spypsy May 8, 2024
352608f
datastore tests
spypsy May 9, 2024
9f240e6
custom iterable functions
spypsy May 9, 2024
42aa1d0
add map doc
spypsy May 9, 2024
4334897
update prune comment
spypsy May 9, 2024
7bcf1d9
Merge branch 'master' into spy/pubsub
spypsy May 9, 2024
3a098fb
fix map signatures
spypsy May 9, 2024
c6fbe35
fix yarn
spypsy May 9, 2024
c2594bc
fix yarn.lock
spypsy May 9, 2024
70f9595
increase cleanup timeout
spypsy May 9, 2024
6eef730
Merge branch 'master' into spy/pubsub
spypsy May 9, 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
5 changes: 4 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"fuzzers",
"gitmodules",
"gitrepo",
"gossipsub",
"grumpkin",
"gtest",
"gzipped",
Expand Down Expand Up @@ -132,6 +133,7 @@
"linkability",
"lmdb",
"maddiaa",
"mcache",
"memdown",
"memfs",
"Merkle",
Expand Down Expand Up @@ -171,6 +173,7 @@
"Palla",
"parallelizable",
"Pedersen",
"peekable",
"permissionless",
"permissionlessly",
"persistable",
Expand Down Expand Up @@ -296,4 +299,4 @@
"flagWords": [
"anonymous"
]
}
}
5 changes: 5 additions & 0 deletions yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export const startNode = async (
nodeConfig = mergeEnvVarsAndCliOptions<AztecNodeConfig>(nodeConfig, parseModuleOptions(options.prover));
}

// ensure bootstrapNodes is an array
if (nodeConfig.bootstrapNodes && typeof nodeConfig.bootstrapNodes === 'string') {
nodeConfig.bootstrapNodes = (nodeConfig.bootstrapNodes as string).split(',');
}

if (!nodeConfig.disableSequencer && nodeConfig.disableProver) {
throw new Error('Cannot run a sequencer without a prover');
}
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/aztec/src/cli/texts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const cliTexts = {
'Starts a Sequencer with options. If started additionally to --node, the Sequencer will attach to that node.\n' +
'Available options are listed below as cliProperty:ENV_VARIABLE_NAME.\n' +
'rcpUrl:ETHEREUM_HOST - string - The host of the Ethereum node to connect to. Default: http://localhost:8545\n' +
'minTxsPerBlock:SEQ_MIN_TXS_PER_BLOCK - number - The minimum number of transactions to include in a block. Default: 1\n' +
'maxTxsPerBlock:SEQ_MAX_TXS_PER_BLOCK - number - The maximum number of transactions to include in a block. Default: 32\n' +
'apiKey:API_KEY - string - The key for the ethereum node if necessary.\n' +
'chainId:CHAIN_ID - number - The chain id of the ethereum host. Default: 31337\n' +
'version:VERSION - number - The version of the Aztec rollup. Default: 1\n' +
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const parseModuleOptions = (options: string): Record<string, string> => {
if (!options?.length) {
return {};
}
const optionsArray = options.split(',');
const optionsArray = options.split(/,(?=\w+=)/);
return optionsArray.reduce((acc, option) => {
const [key, value] = option.split('=');
return { ...acc, [key]: value };
Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"./json-rpc": "./dest/json-rpc/index.js",
"./json-rpc/server": "./dest/json-rpc/server/index.js",
"./json-rpc/client": "./dest/json-rpc/client/index.js",
"./iterable": "./dest/iterable/index.js",
"./log": "./dest/log/index.js",
"./mutex": "./dest/mutex/index.js",
"./fields": "./dest/fields/index.js",
Expand Down
27 changes: 27 additions & 0 deletions yarn-project/foundation/src/iterable/all.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { all } from './index.js';

describe('all iterable', () => {
it('should collect all entries of an iterator as an array', () => {
const values = [0, 1, 2, 3, 4];

const res = all(values);

expect(res).not.toHaveProperty('then');
expect(res).toEqual(values);
});

it('should collect all entries of an async iterator as an array', async () => {
const values = [0, 1, 2, 3, 4];

const generator = (async function* (): AsyncGenerator<number, void, undefined> {
yield* [0, 1, 2, 3, 4];
})();

const p = all(generator);
expect(p).toHaveProperty('then');
expect(p.then).toBeInstanceOf(Function);

const res = await p;
expect(res).toEqual(values);
});
});
32 changes: 32 additions & 0 deletions yarn-project/foundation/src/iterable/all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { isAsyncIterable } from './isAsyncIt.js';

/**
* Collects all values from an (async) iterable and returns them as an array
* @param source - Iterable to collect all values from
* @returns All of the iterable's values as an array.
*/
function all<T>(source: Iterable<T>): T[];
function all<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T[]>;
function all<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T[]> | T[] {
if (isAsyncIterable(source)) {
return (async () => {
const arr = [];

for await (const entry of source) {
arr.push(entry);
}

return arr;
})();
}

const arr = [];

for (const entry of source) {
arr.push(entry);
}

return arr;
}

export { all };
93 changes: 93 additions & 0 deletions yarn-project/foundation/src/iterable/filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { all, filter } from './index.js';

function* values(vals: number[] = [0, 1, 2, 3, 4]): Generator<number, void, undefined> {
yield* vals;
}

async function* asyncValues(vals: number[] = [0, 1, 2, 3, 4]): AsyncGenerator<number, void, undefined> {
yield* values(vals);
}

describe('filter iterable', () => {
it('should filter all values greater than 2', () => {
const res = all(filter(values(), val => val > 2));

expect(res[Symbol.iterator]).toBeTruthy();
expect(res).toEqual([3, 4]);
});

it('should filter all values less than 2', () => {
const res = all(filter(values(), val => val < 2));

expect(res[Symbol.iterator]).toBeTruthy();
expect(res).toEqual([0, 1]);
});

it('should filter all values greater than 2 with a promise', () => {
const res = all(filter(values(), val => val > 2));

expect(res[Symbol.iterator]).toBeTruthy();
expect(res).toEqual([3, 4]);
});

it('should filter all values greater than 2 with a promise', async () => {
// eslint-disable-next-line require-await
const res = filter(values(), async val => val > 2);

expect(res[Symbol.asyncIterator]).toBeTruthy();
await expect(all(res)).resolves.toEqual([3, 4]);
});

it('should filter all async values greater than 2', async () => {
const res = filter(asyncValues(), val => val > 2);

expect(res[Symbol.asyncIterator]).toBeTruthy();
await expect(all(res)).resolves.toEqual([3, 4]);
});

it('should filter all async values greater than 2 with a promise', async () => {
// eslint-disable-next-line require-await
const res = filter(asyncValues(), async val => val > 2);

expect(res[Symbol.asyncIterator]).toBeTruthy();
await expect(all(res)).resolves.toEqual([3, 4]);
});

it('should filter values with indexes', () => {
const vals = [4, 3, 2, 1, 0];
const callbackArgs: any[] = [];
const gen = filter(values(vals), (...args: any[]) => {
callbackArgs.push(args);
return true;
});
expect(gen[Symbol.iterator]).toBeTruthy();

const results = all(gen);
expect(results).toHaveLength(vals.length);
expect(callbackArgs).toHaveLength(vals.length);

vals.forEach((value, index) => {
expect(callbackArgs[index][0]).toEqual(value);
expect(callbackArgs[index][1]).toEqual(index);
});
});

it('should filter async values with indexes', async () => {
const vals = [4, 3, 2, 1, 0];
const callbackArgs: any[] = [];
const gen = filter(asyncValues(vals), (...args: any[]) => {
callbackArgs.push(args);
return true;
});
expect(gen[Symbol.asyncIterator]).toBeTruthy();

const results = await all(gen);
expect(results).toHaveLength(vals.length);
expect(callbackArgs).toHaveLength(vals.length);

vals.forEach((value, index) => {
expect(callbackArgs[index][0]).toEqual(value);
expect(callbackArgs[index][1]).toEqual(index);
});
});
});
77 changes: 77 additions & 0 deletions yarn-project/foundation/src/iterable/filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { peek } from './peek.js';

function isAsyncIterable<T>(thing: any): thing is AsyncIterable<T> {
return thing[Symbol.asyncIterator] != null;
}

/**
* Filters the passed (async) iterable by using the filter function.
* @param source - An iterable to filter.
* @returns A generator of the filtered values.
*/
function filter<T>(
source: Iterable<T>,
fn: (val: T, index: number) => Promise<boolean>,
): AsyncGenerator<T, void, undefined>;
function filter<T>(source: Iterable<T>, fn: (val: T, index: number) => boolean): Generator<T, void, undefined>;
function filter<T>(
source: Iterable<T> | AsyncIterable<T>,
fn: (val: T, index: number) => boolean | Promise<boolean>,
): AsyncGenerator<T, void, undefined>;
function filter<T>(
source: Iterable<T> | AsyncIterable<T>,
fn: (val: T, index: number) => boolean | Promise<boolean>,
): Generator<T, void, undefined> | AsyncGenerator<T, void, undefined> {
let index = 0;

if (isAsyncIterable(source)) {
return (async function* () {
for await (const entry of source) {
if (await fn(entry, index++)) {
yield entry;
}
}
})();
}

// if mapping function returns a promise we have to return an async generator
const peekable = peek(source);
const { value, done } = peekable.next();

if (done === true) {
return (function* () {})();
}

const res = fn(value, index++);

// @ts-expect-error .then is not present on O
if (typeof res.then === 'function') {
return (async function* () {
if (await res) {
yield value;
}

for await (const entry of peekable) {
if (await fn(entry, index++)) {
yield entry;
}
}
})();
}

const func = fn as (val: T, index: number) => boolean;

return (function* () {
if (res === true) {
yield value;
}

for (const entry of peekable) {
if (func(entry, index++)) {
yield entry;
}
}
})();
}

export { filter };
6 changes: 6 additions & 0 deletions yarn-project/foundation/src/iterable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './map.js';
export * from './filter.js';
export * from './sort.js';
export * from './take.js';
export * from './all.js';
export * from './peek.js';
8 changes: 8 additions & 0 deletions yarn-project/foundation/src/iterable/isAsyncIt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Utility function to type check an AsyncIterable
* @param thing - Input to type check
* @returns Type-checked input
*/
export function isAsyncIterable<T>(thing: any): thing is AsyncIterable<T> {
return thing[Symbol.asyncIterator] != null;
}
Loading
Loading