Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unused parts #4380

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/agents/sequencer/src/executer.ts

This file was deleted.

88 changes: 1 addition & 87 deletions packages/agents/sequencer/src/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ChainData,
jsonifyError,
RelayerType,
XTransferErrorStatus,
} from "@connext/nxtp-utils";
import Broker from "amqplib";
import { SubgraphReader } from "@connext/nxtp-adapters-subgraph";
Expand All @@ -18,15 +17,13 @@ import { Web3Signer } from "@connext/nxtp-adapters-web3signer";
import { setupConnextRelayer, setupGelatoRelayer } from "@connext/nxtp-adapters-relayer";
import { getDatabase } from "@connext/nxtp-adapters-database";

import { MessageType, SequencerConfig } from "./lib/entities";
import { SequencerConfig } from "./lib/entities";
import { getConfig } from "./config";
import { AppContext } from "./lib/entities/context";
import { bindSubscriber } from "./bindings/subscriber";
import { bindHTTPSubscriber } from "./bindings/publisher";
import { bindServer } from "./bindings/server";
import { getHelpers } from "./lib/helpers";
import { getOperations } from "./lib/operations";
import { NoBidsSent, NotEnoughRelayerFee, SlippageToleranceExceeded } from "./lib/errors";

const context: AppContext = {} as any;
export const getContext = () => context;
Expand Down Expand Up @@ -266,88 +263,6 @@ export const makeSubscriber = async () => {
}
};

/// MARK - Execute
/**
* A `make` method used to configure a context for handling execution of a given transfer.
*
* This is used to separate execution on a transfer-by-transfer basis into child processes.
* @param _configOverride - Overrides for configuration; normally only used for testing.
*/
export const execute = async (_configOverride?: SequencerConfig) => {
const {
execute: { executeFastPathData, executeSlowPathData },
tasks: { updateTask },
} = getOperations();

// The transferId <-> message type is a CLI argument provided by the parent
// ex; {
// "0x33a3f2ee99315a4e0635e59a43044e94c4886b775f1ef2abe8722fc75fe35da8" : "ExecuteFast",
// "0x8d634d61b323e66ab99f4f422a1724d6aeb0d97bd0db44dad364c7b8f049fc7c": "ExecuteSlow"
// }
const args = JSON.parse(process.argv[2]) as Record<string, string>;
const transferIds = Object.keys(args);

context.adapters = {} as any;
await setupContext(_configOverride);

for (const transferId of transferIds) {
const { requestContext, methodContext } = createLoggingContext(execute.name, undefined, transferId);
const messageType = args[transferId] as MessageType;
try {
const { taskId } =
messageType === MessageType.ExecuteFast
? await executeFastPathData(transferId, requestContext)
: await executeSlowPathData(transferId, messageType, requestContext);

if (taskId) {
await updateTask(transferId, messageType);
}
} catch (error: any) {
const errorObj = jsonifyError(error as Error);
context.logger.error("Error executing:", requestContext, methodContext, errorObj);

let errorName: XTransferErrorStatus = XTransferErrorStatus.ExecutionError;
switch (errorObj.type) {
case SlippageToleranceExceeded.name: {
errorName = XTransferErrorStatus.LowSlippage;
break;
}
case NotEnoughRelayerFee.name: {
errorName = XTransferErrorStatus.LowRelayerFee;
break;
}
case NoBidsSent.name: {
errorName = XTransferErrorStatus.NoBidsReceived;
break;
}
}
try {
await context.adapters.database.updateErrorStatus(transferId, errorName);
} catch (e: unknown) {
context.logger.error("Database error:updateErrorStatus", requestContext, methodContext, undefined, {
transferId,
error: e,
});
}

// increase backoff in case error is one of slippage or relayer fee
if (messageType === MessageType.ExecuteSlow) {
try {
await context.adapters.database.increaseBackoff(transferId);
} catch (e: unknown) {
context.logger.error("Database error:increaseBackoff", requestContext, methodContext, undefined, {
transferId,
error: e,
});
}
}

process.exit(1);
}
}
process.exit(0);
};

/// MARK - Context Setup
export const setupContext = async (_configOverride?: SequencerConfig) => {
const { requestContext, methodContext } = createLoggingContext(setupContext.name);
Expand Down Expand Up @@ -508,7 +423,6 @@ export const setupMQ = async (requestContext: RequestContext): Promise<Broker.Co
const { logger, config } = context;

const methodContext = createMethodContext(setupMQ.name);

logger.info("MQ setup in progress...", requestContext, methodContext, {});
const connection = await Broker.connect(config.messageQueue.connection.uri);

Expand Down