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

fix: 0-conf endpoint schema update #822

Merged
merged 1 commit into from
Feb 13, 2025
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
28 changes: 22 additions & 6 deletions lib/chain/ElementsWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,29 @@ class ElementsWrapper
// of the public client
const hasLowball = this.lowballClient() !== undefined;

this.publicClient().on('transaction', ({ transaction, confirmed }) => {
if (hasLowball && !confirmed) {
return;
}
this.publicClient().on(
'transaction',
async ({ transaction, confirmed }) => {
if (hasLowball && !confirmed) {
return;
}

if (confirmed) {
this.emit('transaction', { transaction, confirmed });
return;
}

this.emit('transaction', { transaction, confirmed });
});
try {
if (await this.zeroConfCheck.checkTransaction(transaction)) {
this.emit('transaction', { transaction, confirmed });
}
} catch (e) {
this.logger.error(
`${this.symbol} 0-conf transaction check failed: ${formatError(e)}`,
);
}
},
);

this.lowballClient()?.on(
'transaction',
Expand Down
23 changes: 14 additions & 9 deletions lib/chain/elements/ZeroConfTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export type ZeroConfToolConfig = {
};

type ZeroConfResponse = {
node_types: {
bridge: {
observations?: {
bridge?: {
seen: number;
total: number;
};
Expand Down Expand Up @@ -50,7 +50,7 @@ class ZeroConfTool
this.maxRetries = config.maxRetries || 60;

this.logger.info(
`Checking every ${this.retryDelay}ms with ${this.maxRetries} retries with 0-conf tool at ${this.endpoint}`,
`Checking every ${this.retryDelay}ms with ${this.maxRetries} retries with 0-conf tool at: ${this.endpoint}`,
);

this.start().then();
Expand Down Expand Up @@ -125,13 +125,18 @@ class ZeroConfTool

private check = async () => {
for (const [txId, { retries }] of this.toCheck) {
const res = await axios.get<any, AxiosResponse<ZeroConfResponse>>(
`${this.endpoint}/${txId}`,
);
const res = (
await axios.get<any, AxiosResponse<ZeroConfResponse>>(
`${this.endpoint}/${txId}`,
)
).data;

const bridgeData = res.observations?.bridge;
if (bridgeData === undefined) {
continue;
}

if (
res.data.node_types.bridge.seen === res.data.node_types.bridge.total
) {
if (bridgeData.seen > 0 && bridgeData.seen === bridgeData.total) {
this.toCheck.delete(txId);
this.emit('accepted', txId);

Expand Down
7 changes: 7 additions & 0 deletions test/integration/chain/ElementsWrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ describe('ElementsWrapper', () => {
Logger.disabledLogger,
elementsConfig,
);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
oneWrapper['zeroConfCheck'] = {
name: 'stub',
checkTransaction: jest.fn().mockResolvedValue(true),
};

await oneWrapper.connect();

expect.assertions(2);
Expand Down
4 changes: 2 additions & 2 deletions test/integration/chain/elements/ZeroConfTool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ZeroConfTool', () => {

app.get('/accept', (_, res) => {
res.json({
node_types: {
observations: {
bridge: {
seen: 21,
total: 21,
Expand All @@ -37,7 +37,7 @@ describe('ZeroConfTool', () => {

app.get('/timeout', (_, res) => {
res.json({
node_types: {
observations: {
bridge: {
seen: 20,
total: 21,
Expand Down
Loading