Skip to content

Commit e3e4d25

Browse files
committed
refat: removed unused files
1 parent a51b4ae commit e3e4d25

File tree

7 files changed

+14
-407
lines changed

7 files changed

+14
-407
lines changed

indexer/src/services/balanceService.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.

indexer/src/services/blockService.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

indexer/src/services/eventService.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

indexer/src/services/sync/payload.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { BlockAttributes } from "../../models/block";
2-
import { TransactionAttributes } from "../../models/transaction";
3-
import { EventAttributes } from "../../models/event";
4-
import { TransferAttributes } from "../../models/transfer";
5-
import { transactionService } from "../transactionService";
6-
import { eventService } from "../eventService";
7-
import { transferService } from "../transferService";
2+
import TransactionModel, {
3+
TransactionAttributes,
4+
} from "../../models/transaction";
5+
import Event, { EventAttributes } from "../../models/event";
6+
import Transfer, { TransferAttributes } from "../../models/transfer";
87
import { getNftTransfers, getCoinTransfers } from "./transfers";
98
import { Transaction } from "sequelize";
109
import { delay, getDecoded, getRequiredEnvNumber } from "../../utils/helpers";
@@ -158,19 +157,18 @@ export async function processTransaction(
158157
.filter((transfer) => transfer.amount !== undefined);
159158

160159
try {
161-
let transactionInstance = await transactionService.save(
160+
const { id: transactionId } = await TransactionModel.create(
162161
transactionAttributes,
163-
{ transaction: tx },
162+
{
163+
transaction: tx,
164+
},
164165
);
165166

166-
let transactionId = transactionInstance.id;
167-
168167
const eventsWithTransactionId = eventsAttributes.map((event) => ({
169168
...event,
170-
transactionId: transactionId,
169+
transactionId,
171170
})) as EventAttributes[];
172-
173-
await eventService.saveMany(eventsWithTransactionId, { transaction: tx });
171+
await Event.bulkCreate(eventsWithTransactionId, { transaction: tx });
174172

175173
const signers = (cmdData.signers ?? []).map(
176174
(signer: any, index: number) => ({
@@ -179,20 +177,16 @@ export async function processTransaction(
179177
pubkey: signer.pubKey,
180178
clist: signer.clist,
181179
scheme: signer.scheme,
182-
transactionId: transactionId,
180+
transactionId,
183181
}),
184182
);
185-
186183
await Signer.bulkCreate(signers, { transaction: tx });
187184

188185
const transfersWithTransactionId = transfersAttributes.map((transfer) => ({
189186
...transfer,
190-
tokenId: transfer.tokenId,
191-
contractId: transfer.contractId,
192-
transactionId: transactionId,
187+
transactionId,
193188
})) as TransferAttributes[];
194-
195-
await transferService.saveMany(transfersWithTransactionId, {
189+
await Transfer.bulkCreate(transfersWithTransactionId, {
196190
transaction: tx,
197191
});
198192
} catch (error) {

indexer/src/services/syncService.ts

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ const SYNC_MIN_HEIGHT = getRequiredEnvNumber("SYNC_MIN_HEIGHT");
2626
const SYNC_FETCH_INTERVAL_IN_BLOCKS = getRequiredEnvNumber(
2727
"SYNC_FETCH_INTERVAL_IN_BLOCKS",
2828
);
29-
const SYNC_TIME_BETWEEN_REQUESTS_IN_MS = getRequiredEnvNumber(
30-
"SYNC_TIME_BETWEEN_REQUESTS_IN_MS",
31-
);
3229

3330
const shutdownSignal = createSignal();
3431

@@ -118,79 +115,6 @@ export async function processKeys(
118115
return totalKeysProcessed;
119116
}
120117

121-
/**
122-
* Initiates the process of synchronizing blockchain data from a specific point, either from the latest block cut or from the
123-
* last recorded synchronization status for each chain.
124-
*
125-
* The synchronization process involves the following steps:
126-
* 1. Fetching the latest cut from the Chainweb network to determine the current highest block heights across all chains.
127-
* 2. Retrieving the last synchronization status for all chains to identify the starting point of the fill process.
128-
* If no previous synchronization status is found for a chain, the process starts from the height provided by the latest cut.
129-
* 3. Processing each chain individually in a round-robin fashion, fetching headers and their corresponding payloads from
130-
* the last height down to a specified minimum height. This ensures that the load is evenly distributed across all chains and
131-
* that the system remains responsive during the synchronization process.
132-
* 4. For each chain, headers and payloads are fetched in descending order (from higher blocks to lower blocks), allowing for
133-
* efficient catch-up to the current state of the blockchain.
134-
* 5. The process continues iteratively, moving through each chain in turn, until all chains have reached the minimum required block height.
135-
*
136-
* @param {string} network - The identifier of the Chainweb network from which to synchronize data (e.g., 'mainnet01').
137-
*/
138-
export async function startBackFill(
139-
network: string,
140-
chainId = 0,
141-
): Promise<void> {
142-
try {
143-
console.log("Starting filling...");
144-
const chains = await getLastSync(network);
145-
const chain = chains.find((c) => c.chainId === chainId);
146-
if (!chain) {
147-
throw new Error("Chain not found in the list of chains.");
148-
}
149-
console.info(
150-
"Starting backfill process for chain: ",
151-
chain,
152-
SYNC_MIN_HEIGHT,
153-
);
154-
while (chain.currentHeight > SYNC_MIN_HEIGHT) {
155-
console.info(`Processing chain:`, {
156-
chainId: chain.chainId,
157-
currentHeight: chain.currentHeight,
158-
});
159-
160-
let nextHeight = Math.max(
161-
chain.currentHeight - SYNC_FETCH_INTERVAL_IN_BLOCKS,
162-
SYNC_MIN_HEIGHT + 1,
163-
);
164-
165-
const start = new Date().getTime();
166-
167-
const counters = await fetchHeadersWithRetry(
168-
network,
169-
chain.chainId,
170-
nextHeight,
171-
chain.currentHeight,
172-
);
173-
174-
chain.currentHeight = nextHeight - 1;
175-
176-
const end = new Date().getTime();
177-
const time = end - start;
178-
console.log(
179-
{
180-
chainId: chain.chainId,
181-
currentHeight: chain.currentHeight,
182-
},
183-
`processed in ${time / 1000}s.`,
184-
);
185-
console.log("Counters: ", counters);
186-
}
187-
188-
console.log("All chains have been processed to the minimum height.");
189-
} catch (error) {
190-
console.error("Error during backfilling: ", error);
191-
}
192-
}
193-
194118
/**
195119
* Retrieves the last synchronization status for each chain in a given network.
196120
* It fetches the latest cut (highest block heights) from the network and combines

0 commit comments

Comments
 (0)