From 295c3866cb8fcbde65a366810db6f0d054abeb53 Mon Sep 17 00:00:00 2001 From: Scorbajio Date: Sat, 6 Aug 2022 01:56:35 +0000 Subject: [PATCH] Create account fetcher base --- .../client/lib/sync/fetcher/accountfetcher.ts | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 packages/client/lib/sync/fetcher/accountfetcher.ts diff --git a/packages/client/lib/sync/fetcher/accountfetcher.ts b/packages/client/lib/sync/fetcher/accountfetcher.ts new file mode 100644 index 00000000000..ca670c27371 --- /dev/null +++ b/packages/client/lib/sync/fetcher/accountfetcher.ts @@ -0,0 +1,195 @@ +import { Fetcher, FetcherOptions } from './fetcher' +import { Account } from '@ethereumjs/util' +// import { Chain } from '../../blockchain' +import { Job } from './types' +import { Peer } from '../../net/peer' + +export interface AccountFetcherOptions extends FetcherOptions { + /** Root hash of the account trie to serve */ + root: Buffer + + /** Account hash of the first to retrieve */ + origin: Buffer + + /** Account hash after which to stop serving data */ + limit: Buffer + + /** Soft limit at which to stop returning data */ + bytes: bigint + + /** Destroy fetcher once all tasks are done */ + destroyWhenDone?: boolean +} + +// root comes from block? +export type JobTask = { + root: Buffer + origin: Buffer + limit: Buffer + bytes: bigint +} + +export class AccountFetcher extends Fetcher< + JobTask, + Account[], + Account +> { + /** + * Where the fetcher starts apart from the tasks already in the `in` queue. + */ + root: Buffer + /** + * Account hash of the first to retrieve + */ + origin: Buffer + /** + * Account hash after which to stop serving data + */ + limit: Buffer + /** + * Soft limit at which to stop returning data + */ + bytes: bigint + + /** + * Create new block fetcher + */ + constructor(options: AccountFetcherOptions) { + super(options) + + this.root = options.root + this.origin = options.origin + this.limit = options.limit + this.bytes = options.bytes + this.debug( + `Block fetcher instantiated root=${this.root} origin=${this.origin} limit=${this.limit} bytes=${this.bytes} destroyWhenDone=${this.destroyWhenDone}` + ) + } + + /** + * Request results from peer for the given job. + * Resolves with the raw result + * If `undefined` is returned, re-queue the job. + * @param job + * @param peer + */ + async request(job: Job, peer: Peer): Promise { + return + } + + /** + * Process the reply for the given job. + * If the reply contains unexpected data, return `undefined`, + * this re-queues the job. + * @param job fetch job + * @param result result data + */ + process(job: Job, result: Account[]): Account[] | undefined { + return + } + + /** + * Store fetch result. Resolves once store operation is complete. + * @param result fetch result + */ + async store(result: Account[]): Promise { + return + } +} import { Fetcher, FetcherOptions } from './fetcher' +import { Account } from '@ethereumjs/util' +// import { Chain } from '../../blockchain' +import { Job } from './types' +import { Peer } from '../../net/peer' + +export interface AccountFetcherOptions extends FetcherOptions { + /** Root hash of the account trie to serve */ + root: Buffer + + /** Account hash of the first to retrieve */ + origin: Buffer + + /** Account hash after which to stop serving data */ + limit: Buffer + + /** Soft limit at which to stop returning data */ + bytes: bigint + + /** Destroy fetcher once all tasks are done */ + destroyWhenDone?: boolean +} + +// root comes from block? +export type JobTask = { + root: Buffer + origin: Buffer + limit: Buffer + bytes: bigint +} + +export class AccountFetcher extends Fetcher< + JobTask, + Account[], + Account +> { + /** + * Where the fetcher starts apart from the tasks already in the `in` queue. + */ + root: Buffer + /** + * Account hash of the first to retrieve + */ + origin: Buffer + /** + * Account hash after which to stop serving data + */ + limit: Buffer + /** + * Soft limit at which to stop returning data + */ + bytes: bigint + + /** + * Create new block fetcher + */ + constructor(options: AccountFetcherOptions) { + super(options) + + this.root = options.root + this.origin = options.origin + this.limit = options.limit + this.bytes = options.bytes + this.debug( + `Block fetcher instantiated root=${this.root} origin=${this.origin} limit=${this.limit} bytes=${this.bytes} destroyWhenDone=${this.destroyWhenDone}` + ) + } + + /** + * Request results from peer for the given job. + * Resolves with the raw result + * If `undefined` is returned, re-queue the job. + * @param job + * @param peer + */ + async request(job: Job, peer: Peer): Promise { + return + } + + /** + * Process the reply for the given job. + * If the reply contains unexpected data, return `undefined`, + * this re-queues the job. + * @param job fetch job + * @param result result data + */ + process(job: Job, result: Account[]): Account[] | undefined { + return + } + + /** + * Store fetch result. Resolves once store operation is complete. + * @param result fetch result + */ + async store(result: Account[]): Promise { + return + } +} \ No newline at end of file