More scalable data storage
This commit is contained in:
@@ -24,9 +24,9 @@ function publicAddress(ip: string): boolean {
|
||||
return family === 6 && globalV6.check(ip, 'ipv6') && !excluded.check(ip, 'ipv6');
|
||||
}
|
||||
const remoteStatus = z.object({ network: z.literal(NETWORK), chainId: z.literal(CHAIN_ID),
|
||||
size: z.number().int().min(0).max(10_000), tip: z.string().regex(/^[a-f0-9]{64}$/).optional() }).strict();
|
||||
size: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER), tip: z.string().regex(/^[a-f0-9]{64}$/).optional() }).strict();
|
||||
const pageSchema = z.object({ blocks: z.array(blockSchema).max(32),
|
||||
next: z.number().int().min(0).max(10_000).nullable() }).strict();
|
||||
next: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).nullable() }).strict();
|
||||
const poolSchema = z.object({ transactions: z.array(transferSchema).max(256) }).strict();
|
||||
type Peer = { url: string; connected: boolean; error?: string; offset: number; busy: boolean };
|
||||
|
||||
@@ -121,8 +121,8 @@ export class PeerNetwork {
|
||||
if (peer.offset < status.size) {
|
||||
const page = pageSchema.parse(await this.request(peer, `/p2p/blocks?offset=${peer.offset}`));
|
||||
const end = peer.offset + page.blocks.length;
|
||||
if (!page.blocks.length || end > 10_000 ||
|
||||
(page.next !== null && (page.next !== end || end >= 10_000)) ||
|
||||
if (!page.blocks.length || !Number.isSafeInteger(end) ||
|
||||
(page.next !== null && page.next !== end) ||
|
||||
(page.next === null && end < status.size)) throw new Error('Invalid peer pagination');
|
||||
for (const block of page.blocks) {
|
||||
if (this.closed) throw new Error('Peer network closed');
|
||||
|
||||
Reference in New Issue
Block a user