Skip to content

Commit

Permalink
fix: update libp2p dep
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Oct 28, 2023
1 parent 8b2673d commit f69c01a
Show file tree
Hide file tree
Showing 26 changed files with 1,808 additions and 1,747 deletions.
4 changes: 2 additions & 2 deletions docs/modules/program/composition/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const forum2 = await client2.open<Forum>(forum.address, {
});

// Wait for client 1 to be available (only needed for testing locally)
await forum2.waitFor(client.peerId);
await forum2.channels.log.waitForReplicator(client.identity.publicKey);

// find channels from the forum from client2 perspective
const channels = await forum2.channels.index.search(new SearchRequest());
Expand All @@ -133,7 +133,7 @@ const channel2 = await client2.open<Channel>(channels[0], {
});

// Wait for client 1 to be available (only needed for testing locally)
await channel2.waitFor(client.peerId);
await channel2.db.posts.log.waitForReplicator(client.identity.publicKey);

// find messages
const messages = await channel2.db.posts.index.search(new SearchRequest());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as connection from "../connection.js";
import { EventEmitter, CustomEvent } from "@libp2p/interface/events";
import { CustomEvent } from "@libp2p/interface/events";
import type { TypedEventTarget } from "@libp2p/interface/events";

export class EventEmitterNode extends connection.MessageNode {
constructor(
readonly eventEmitter: EventEmitter<{
readonly eventEmitter: TypedEventTarget<{
hello: CustomEvent<connection.Hello>;
data: CustomEvent<connection.DataMessage>;
}>
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/peerbit-server/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"devDependencies": {
"@peerbit/test-lib": "^0.0.1",
"@peerbit/test-utils": "1.0.33",
"@types/yargs": "^17.0.24",
"@types/yargs": "17.0.24",
"aws-sdk": "^2.1259.0",
"dotenv": "^16.1.4",
"@types/tmp": "^0.2.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/peerbit-server/node/src/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const launchNodes = async (properties: {
new RunInstancesCommand({
ImageId: AWS_LINUX_ARM_AMIs[regionString],
SecurityGroupIds: [securityGroupOut.GroupId!],
InstanceType: "t4g." + (properties.size || "micro"),
InstanceType: ("t4g." + (properties.size || "micro")) as any, // TODO types
UserData: Buffer.from(
setupUserData(properties.email, properties.grantAccess)
).toString("base64"),
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/peerbit-server/test-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"devDependencies": {
"@peerbit/test-utils": "*",
"libp2p": "0.46.9"
"libp2p": "0.46.16"
},
"dependencies": {
"@peerbit/string": "*",
Expand Down
8 changes: 4 additions & 4 deletions packages/clients/peerbit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"@peerbit/uint8arrays": "3.0.1",
"datastore-level": "^10.1.4",
"@dao-xyz/libp2p-noise": "^13.0.1",
"@libp2p/mplex": "^9.0.5",
"@libp2p/mplex": "^9.0.9",
"@chainsafe/libp2p-yamux": "^5.0.0",
"@libp2p/webrtc": "^3.1.9",
"@libp2p/websockets": "^7.0.5",
"@libp2p/tcp": "^8.0.5",
"@libp2p/webrtc": "^3.2.5",
"@libp2p/websockets": "^7.0.10",
"@libp2p/tcp": "^8.0.10",
"level": "^8.0.0",
"memory-level": "^1.0.0",
"path-browserify": "^1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@peerbit/blocks-interface": "^1.1.3",
"@peerbit/crypto": "1.0.10",
"@peerbit/logger": "1.0.1",
"libp2p": "0.46.9",
"libp2p": "0.46.16",
"p-queue": "^7.3.3",
"path-browserify": "^1.0.1",
"yallist": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deserialize, field, serialize, variant } from "@dao-xyz/borsh";
import { deserialize, field, option, serialize, variant } from "@dao-xyz/borsh";
import { TestSession } from "@peerbit/test-utils";
import { Access, AccessType } from "../access";
import { AnyAccessCondition, PublicKeyAccessCondition } from "../condition";
Expand All @@ -12,13 +12,11 @@ import {
} from "@peerbit/crypto";
import {
Documents,
DocumentIndex,
SearchRequest,
StringMatch,
Observer,
Role
} from "@peerbit/document";
import { RPC } from "@peerbit/rpc";
import { Program } from "@peerbit/program";
import { IdentityAccessController } from "../acl-db";
import { PeerId } from "@libp2p/interface/peer-id";
Expand Down Expand Up @@ -53,12 +51,10 @@ class TestStore extends Program<{ role: Role }> {

constructor(properties: { publicKey: PublicSignKey | PeerId }) {
super();
if (properties) {
this.store = new Documents();
this.accessController = new IdentityAccessController({
rootTrust: properties.publicKey
});
}
this.store = new Documents();
this.accessController = new IdentityAccessController({
rootTrust: properties.publicKey
});
}

async open(properties?: { role: Role }) {
Expand Down Expand Up @@ -88,7 +84,6 @@ describe("index", () => {

it("can be deterministic", async () => {
const key = (await Ed25519Keypair.create()).publicKey;
let id = randomBytes(32);
const t1 = new IdentityAccessController({
id: key.publicKey,
rootTrust: key
Expand Down Expand Up @@ -205,16 +200,6 @@ describe("index", () => {
const l0b = await TestStore.open(l0a.address!, session.peers[1]);
const l0c = await TestStore.open(l0a.address!, session.peers[2]);

/* await waitForPeers(
session.peers[1],
session.peers[0],
l0a.address.toString()
);
await waitForPeers(
session.peers[2],
session.peers[0],
l0a.address.toString()
); */
await expect(
l0c.store.put(
new Document({
Expand Down Expand Up @@ -264,10 +249,45 @@ describe("index", () => {
new Document({
id: "2"
})
); // Now trusted
);
});
/* it("xxxx", async () => {
console.log("----------------------------------------");
const l0axx = await session.peers[0].open(
new TestStore({
publicKey: session.peers[0].peerId
})
);
await TestStore.open(l0axx.address!, session.peers[1]);
await TestStore.open(l0axx.address!, session.peers[2]);
console.log(l0axx.getTopics?.());
console.log("B");
const l0a = await session.peers[0].open(
new TestStore({
publicKey: session.peers[1].peerId
})
);
console.log(l0a.getTopics?.());
const l0b = await TestStore.open(l0a.address!, session.peers[1], {
args: { role: new Observer() }
});
await l0b.store.log.waitForReplicator(
session.peers[0].identity.publicKey
);
}); */

/*
*/

it("any access", async () => {
console.log("A");

const l0a = await session.peers[0].open(
new TestStore({
publicKey: session.peers[0].peerId
Expand All @@ -282,12 +302,6 @@ describe("index", () => {

const l0b = await TestStore.open(l0a.address!, session.peers[1]);

/* await waitForPeers(
session.peers[1],
session.peers[0],
l0a.address.toString()
); */

await expect(
l0b.store.put(
new Document({
Expand Down Expand Up @@ -315,6 +329,9 @@ describe("index", () => {
});

it("read access", async () => {
//
console.log("B");

const l0a = await session.peers[0].open(
new TestStore({
publicKey: session.peers[0].peerId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1801,8 +1801,10 @@ describe("index", () => {
}
// Wait for ack that everone can connect to each outher through the rpc topic
for (let i = 0; i < session.peers.length; i++) {
await stores[i].docs.waitFor(
session.peers.filter((_v, ix) => ix !== i).map((x) => x.peerId)
await stores[i].docs.log.waitForReplicator(
...session.peers
.filter((_v, ix) => ix !== i)
.map((x) => x.identity.publicKey)
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { waitFor } from "@peerbit/time";
import { EventStore } from "./utils/stores/event-store";
import assert from "assert";
import mapSeries from "p-each-series";
import { waitForResolved } from "@peerbit/time";

describe(`Automatic Replication`, function () {
let session: TestSession;
Expand All @@ -19,7 +20,7 @@ describe(`Automatic Replication`, function () {
const entryArr: number[] = [];

const db1 = await session.peers[0].open(new EventStore<string>());
const db3 = await session.peers[0].open(new EventStore<string>());
/* const db3 = await session.peers[0].open(new EventStore<string>()); */

// Create the entries in the first database
for (let i = 0; i < entryCount; i++) {
Expand All @@ -34,24 +35,30 @@ describe(`Automatic Replication`, function () {
session.peers[1]
))!;

const db4 = (await EventStore.open<EventStore<string>>(
db3.address!,
session.peers[1]
))!;

await waitFor(
async () =>
(await db2.iterator({ limit: -1 })).collect().length === entryCount
);
/* const db4 = (await EventStore.open<EventStore<string>>(
db3.address!,
session.peers[1]
))!;
*/
try {
await waitForResolved(async () =>
expect((await db2.iterator({ limit: -1 })).collect()).toHaveLength(
entryCount
)
);
} catch (error) {
const x = 123;
throw error;
}
const result1 = (await db1.iterator({ limit: -1 })).collect();
const result2 = (await db2.iterator({ limit: -1 })).collect();
expect(result1.length).toEqual(result2.length);
for (let i = 0; i < result1.length; i++) {
assert(result1[i].equals(result2[i]));
}

expect(db3.log.log.length).toEqual(0);
expect(db4.log.log.length).toEqual(0);
/*
expect(db3.log.log.length).toEqual(0);
expect(db4.log.log.length).toEqual(0); */
});

it("starts replicating the database when peers connect in write mode", async () => {
Expand Down
51 changes: 10 additions & 41 deletions packages/programs/data/shared-log/src/__tests__/sharding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { TestSession } from "@peerbit/test-utils";
import { delay, waitFor, waitForResolved } from "@peerbit/time";
import { AbsoluteReplicas, maxReplicas } from "../replication.js";
import { Replicator } from "../role";
import { deserialize } from "@dao-xyz/borsh";

describe(`sharding`, () => {
let session: TestSession;
Expand Down Expand Up @@ -77,8 +76,12 @@ describe(`sharding`, () => {
session.peers[2]
);

await waitFor(() => db2.log.getReplicatorsSorted()?.length === 3);
await waitFor(() => db3.log.getReplicatorsSorted()?.length === 3);
await waitForResolved(() =>
expect(db2.log.getReplicatorsSorted()).toHaveLength(3)
);
await waitForResolved(() =>
expect(db3.log.getReplicatorsSorted()).toHaveLength(3)
);

const entryCount = sampleSize;

Expand Down Expand Up @@ -287,31 +290,16 @@ describe(`sharding`, () => {
db1.address!,
session.peers[2]
);
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxx");
console.log(session.peers.map((x) => x.identity.publicKey.hashcode()));

const entryCount = sampleSize;

await waitForResolved(() =>
expect(db2.log.getReplicatorsSorted()).toHaveLength(3)
);
try {
await waitForResolved(() =>
expect(db3.log.getReplicatorsSorted()).toHaveLength(3)
);
} catch (error) {
console.log(
"???",
db3.log.getReplicatorsSorted(),
db3.log.role,
db3.log
.getReplicatorsSorted()
?.find(
(x) => x.hash === session.peers[2].identity.publicKey.hashcode()
)
);
throw error;
}

await waitForResolved(() =>
expect(db3.log.getReplicatorsSorted()).toHaveLength(3)
);

const promises: Promise<any>[] = [];
for (let i = 0; i < entryCount; i++) {
Expand Down Expand Up @@ -357,25 +345,6 @@ describe(`sharding`, () => {
db3.log.log.values.length > entryCount * 0.5 &&
db3.log.log.values.length < entryCount * 0.85
);
console.log("---->", [
session.peers.map((x) => x.identity.publicKey.hashcode())
]);
console.log("XYZ1", db1.log.getReplicatorsSorted());
//
/* const a = [...db1.log["_gidPeersHistory"].values()];
console.log(
a.slice(0, 5),
db2.log.log.values.length,
db3.log.log.values.length
);
await delay(1000);
console.log(
JSON.stringify([...db1.log["_gidPeersHistory"].values()]) ===
JSON.stringify(a),
db2.log.log.values.length,
db3.log.log.values.length
);
console.log("XYZ2", db1.log.getReplicatorsSorted()); */

await db3.close();

Expand Down
5 changes: 3 additions & 2 deletions packages/programs/program/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ProgramInitializationOptions,
addParent
} from "./handler.js";
import type { TypedEventTarget } from "@libp2p/interface/events";

const intersection = (
a: Set<string> | undefined,
Expand Down Expand Up @@ -96,7 +97,7 @@ export abstract class Program<
private _node: ProgramClient;
private _allPrograms: Program[] | undefined;

private _events: EventEmitter<ProgramEvents>;
private _events: TypedEventTarget<ProgramEvents>;
private _closed: boolean;

parents: (Program<any> | undefined)[];
Expand All @@ -117,7 +118,7 @@ export abstract class Program<
this._address = address;
}

get events(): EventEmitter<Events> {
get events(): TypedEventTarget<Events> {
return this._events || (this._events = new EventEmitter());
}

Expand Down
Loading

0 comments on commit f69c01a

Please sign in to comment.