Skip to content

Commit

Permalink
feat: max ipfs cid length
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Mar 8, 2024
1 parent 89b9e46 commit 4662aba
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
5 changes: 2 additions & 3 deletions packages/node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PeerId } from "@libp2p/interface-peer-id";
import { ssz, ts } from "types/lib";
import { SignableENR } from "@chainsafe/discv5";
import logger, { Logger } from "api/lib/logger";
import { deserializeMempoolId, serializeMempoolId } from "params/lib";
import { serializeMempoolId } from "params/lib";
import { Config } from "executor/lib/config";
import { AllChainsMetrics } from "monitoring/lib";
import { Executor } from "executor/lib/executor";
Expand Down Expand Up @@ -198,8 +198,7 @@ export class Network implements INetwork {

const canonicalMempool = this.relayersConfig.getCanonicalMempool()
if (canonicalMempool.mempoolId) {
const mempoolId = deserializeMempoolId(serializeMempoolId(canonicalMempool.mempoolId));
this.subscribeGossipCoreTopics(mempoolId);
this.subscribeGossipCoreTopics(canonicalMempool.mempoolId);
}

if (enr) {
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/reqresp/protocols/Status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ssz, ts } from "types/lib";
import { MAX_MEMPOOLS_PER_BUNDLER } from "types/lib/sszTypes";
import { deserializeMempoolId } from "params/lib";
import {
ContextBytesType,
DialOnlyProtocolDefinition,
Expand Down
7 changes: 3 additions & 4 deletions packages/node/src/sync/sync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logger from "api/lib/logger";
import { PeerId } from "@libp2p/interface-peer-id";
import { ts } from "types/lib";
import { deserializeMempoolId } from "params/lib";
import { deserializeMempoolId, isMempoolIdEqual } from "params/lib";
import { deserializeUserOp, userOpHashToString } from "params/lib/utils/userOp";
import { AllChainsMetrics } from "monitoring/lib";
import { Executor } from "executor/lib/executor";
Expand Down Expand Up @@ -127,10 +127,9 @@ export class SyncService implements ISyncService {
try {
for (const mempool of peer.metadata.supported_mempools) {
const canonicalMempool = this.executorConfig.getCanonicalMempool();
const mempoolStr = deserializeMempoolId(mempool).toLowerCase();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (canonicalMempool.mempoolId.toLowerCase() != mempoolStr) {
logger.debug(`mempool not supported: ${mempoolStr}`);
if (!isMempoolIdEqual(canonicalMempool.mempoolId, mempool)) {
logger.debug(`mempool not supported: ${deserializeMempoolId(mempool)}`);
continue;
}

Expand Down
23 changes: 19 additions & 4 deletions packages/params/src/utils/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ import { MempoolId } from "types/lib/sszTypes";
import { utils } from "ethers";

export function serializeMempoolId(mempoolId: string): Uint8Array {
const hex = utils.hexlify(utils.toUtf8Bytes(mempoolId));
return MempoolId.fromJson(hex);
const id = utils.toUtf8Bytes(mempoolId);
const serialized = MempoolId.defaultValue();
serialized.set(id);
return serialized;
}

export function deserializeMempoolId(byteArray: Uint8Array): string {
const json = MempoolId.toJson(byteArray) as string;
return utils.toUtf8String(json);
return utils.toUtf8String(byteArray);
}

export function isMempoolIdEqual(a: Uint8Array | string, b: Uint8Array | string): boolean {
if (typeof a == 'string') {
a = serializeMempoolId(a);
}
if (typeof b == 'string') {
b = serializeMempoolId(b);
}
if (a.length != b.length) return false;
for (let i = 0; i < a.length; ++i) {
if (a[i] != b[i]) return false;
}
return true;
}
4 changes: 2 additions & 2 deletions packages/types/src/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ByteListType,
ContainerType,
ListCompositeType,
ByteVectorType,
ByteVectorType
} from "@chainsafe/ssz";
import * as primitiveSsz from "./primitive/sszTypes";
const { Address, Bytes32, UintBn256 } = primitiveSsz;
Expand All @@ -22,7 +22,7 @@ export const MAX_SUPPORTED_MEMPOOLS = 1024;
// Mempool
// ========

export const MempoolId = new ByteVectorType(46);
export const MempoolId = new ByteVectorType(256);
export const ChainId = primitiveSsz.UintBn64;
export const SupportedMempools = new ListCompositeType(
MempoolId,
Expand Down

0 comments on commit 4662aba

Please sign in to comment.