@effectstream/sync 0.100.17 → 0.100.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { applyDelay } from "../common/utils.ts";
2
+ import { bufferAtCap } from "../common/page-helpers.ts";
2
3
  import type { Operation } from "effection";
3
4
  import { call } from "effection";
4
5
  import { getPage } from "@effectstream/db";
@@ -71,6 +72,7 @@ export class UtxoRpcSyncState extends SyncState<
71
72
 
72
73
  @bound
73
74
  override *stateToInput(): Operation<Input | undefined> {
75
+ if (bufferAtCap(this, this.config.syncProtocol)) return undefined;
74
76
  // Get the value of the latest block height.
75
77
  const tipHeight = yield* call(() => this.fetcher.lastHeight());
76
78
  if (!tipHeight) {
@@ -157,6 +159,22 @@ export class UtxoRpcSyncState extends SyncState<
157
159
  rootOutput.blockInfo.push(...blockInfo);
158
160
  }
159
161
 
162
+ @bound
163
+ override outputToLastPage(data: Output): LastPage<Page, RootPage> {
164
+ // Mirror the fetcher's `own`: slot/height from the block header, and the
165
+ // block hash from `blockHashes` (the fetcher builds it as `[completed.hash]`,
166
+ // the same value it stored in `own.hash`).
167
+ return {
168
+ own: {
169
+ slot: Number(data.raw.header!.slot),
170
+ height: Number(data.raw.header!.height),
171
+ hash: data.blockHashes[0],
172
+ },
173
+ ownBlockNumber: Number(data.raw.header!.height),
174
+ root: this.toRootPage(data),
175
+ };
176
+ }
177
+
160
178
  @bound
161
179
  override getNamespace(): string[] {
162
180
  return [this.config.network.name, this.config.syncProtocol.name];
@@ -31,6 +31,8 @@ import { CelestiaFetcher } from "./sync-protocols/celestia/fetcher.ts";
31
31
  import { CelestiaSyncState } from "./sync-protocols/celestia/state.ts";
32
32
  import { NearFetcher } from "./sync-protocols/near/fetcher.ts";
33
33
  import { NearSyncState } from "./sync-protocols/near/state.ts";
34
+ import { TestFetcher } from "./sync-protocols/test/fetcher.ts";
35
+ import { TestSyncState } from "./sync-protocols/test/state.ts";
34
36
 
35
37
  export function* genSyncProtocols(
36
38
  dbConn: PoolClient,
@@ -149,6 +151,17 @@ export function* genSyncProtocols(
149
151
  fetcher,
150
152
  );
151
153
  result.push(state);
154
+ } else if (
155
+ entry.networkType === ConfigNetworkType.TEST
156
+ ) {
157
+ // Synthetic test chain (TEST_MAIN clock or TEST_PARALLEL source).
158
+ const fetcher = new TestFetcher(entry);
159
+ const state = yield* TestSyncState.restoreState(
160
+ dbConn,
161
+ entry,
162
+ fetcher,
163
+ );
164
+ result.push(state);
152
165
  } else {
153
166
  throw new Error(`Unsupported network type: ${entry.network.type}`);
154
167
  }