Skip to content

Commit

Permalink
update with new pathfinder2 (#149)
Browse files Browse the repository at this point in the history
* update with new pathfinder2 binary

* include hops

* Set up HOPS_DEFAULT as constant

* Validate hops

* update package files

* Update Dockerfile

Co-authored-by: llunaCreixent <elesmp@protonmail.com>
  • Loading branch information
JacqueGM and llunaCreixent authored Jan 10, 2023
1 parent 4d5b5c4 commit bac5587
Show file tree
Hide file tree
Showing 11 changed files with 8,968 additions and 11,876 deletions.
4 changes: 4 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Returns steps to transfer transitively through trust graph from one node to anot
from: <string>,
to: <string>,
value: <number>,
hops: <number>,
}
```

- `from`: Sender address
- `to`: Receiver address
- `value`: Amount of Freckles to send between sender and receiver (the fractional monetary unit of Circles is named Freckles. One Circle = 1,000,000,000,000,000,000 Freckles (10<sup>18</sup>))
- `hops` (optional): pathfinder2 parameter used to limit the area around the sender that is explored; the maximal "chain length"

**Response:**

Expand Down Expand Up @@ -58,12 +60,14 @@ Updates the steps of a transitive transfer.
from: <string>,
to: <string>,
value: <number>,
hops: <number>,
}
```

- `from`: Sender address
- `to`: Receiver address
- `value`: Amount of Freckles intended to be sent between sender and receiver (the fractional monetary unit of Circles is named Freckles. One Circle = 1,000,000,000,000,000,000 Freckles (10<sup>18</sup>))
- `hops` (optional): pathfinder2 parameter used to limit the area around the sender that is explored; the maximal "chain length"

**Response:**

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14-slim
FROM node:14-bullseye-slim

WORKDIR /usr/src/app

Expand Down
20,768 changes: 8,902 additions & 11,866 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.1",
"ethereumjs-abi": "^0.6.8",
"jest": "^26.6.3",
"nock": "^13.2.4",
"nodemon": "^2.0.16",
Expand All @@ -58,7 +59,7 @@
"dependencies": {
"@babel/runtime": "^7.17.9",
"@circles/core": "^3.1.3",
"@circles/transfer": "^2.0.0",
"@circles/transfer": "^3.0.0",
"aws-sdk": "^2.1133.0",
"body-parser": "^1.20.0",
"bull": "^4.8.5",
Expand Down
Binary file modified pathfinder
Binary file not shown.
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const BASE_PATH = path.join(__dirname, '..');
export const EDGES_DIRECTORY_PATH = path.join(BASE_PATH, 'edges-data');
export const EDGES_FILE_PATH = path.join(EDGES_DIRECTORY_PATH, 'edges.csv');
export const PATHFINDER_FILE_PATH = path.join(BASE_PATH, 'pathfinder');

export const HOPS_DEFAULT = '15';
4 changes: 3 additions & 1 deletion src/services/edgesFromGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { minNumberString } from '../helpers/compare';
import {
EDGES_FILE_PATH,
EDGES_TMP_FILE_PATH,
HOPS_DEFAULT,
PATHFINDER_FILE_PATH,
} from '../constants';

Expand Down Expand Up @@ -396,7 +397,7 @@ export async function writeToFile(edges) {
});
}

export async function transferSteps({ from, to, value }) {
export async function transferSteps({ from, to, value, hops = HOPS_DEFAULT }) {
if (from === to) {
throw new Error('Can not send to yourself');
}
Expand All @@ -408,6 +409,7 @@ export async function transferSteps({ from, to, value }) {
from,
to,
value,
hops,
},
{
edgesFile: EDGES_FILE_PATH,
Expand Down
17 changes: 14 additions & 3 deletions src/services/findTransferSteps.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import findTransferSteps from '@circles/transfer';
import { performance } from 'perf_hooks';

import { EDGES_FILE_PATH, PATHFINDER_FILE_PATH } from '../constants';
import {
EDGES_FILE_PATH,
HOPS_DEFAULT,
PATHFINDER_FILE_PATH,
} from '../constants';

const DEFAULT_PROCESS_TIMEOUT = 1000 * 200;
const FLAG = '--flowcsv';
export default async function transferSteps({ from, to, value }) {
const FLAG = '--csv';

export default async function transferSteps({
from,
to,
value,
hops = HOPS_DEFAULT
}) {
if (from === to) {
throw new Error('Cannot send to yourself');
}
Expand All @@ -20,6 +30,7 @@ export default async function transferSteps({ from, to, value }) {
from,
to,
value,
hops,
},
{
edgesFile: EDGES_FILE_PATH,
Expand Down
19 changes: 15 additions & 4 deletions src/services/updateTransferSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import EdgeUpdateManager from './edgesUpdate';
import logger from '../helpers/logger';
import tasks from '../tasks';
import submitJob from '../tasks/submitJob';
import { EDGES_FILE_PATH, PATHFINDER_FILE_PATH } from '../constants';
import {
EDGES_FILE_PATH,
HOPS_DEFAULT,
PATHFINDER_FILE_PATH,
} from '../constants';

const DEFAULT_PROCESS_TIMEOUT = 1000 * 200;
const FLAG = '--flowcsv';
const FLAG = '--csv';

const hubContract = new web3.eth.Contract(
HubContract.abi,
process.env.HUB_ADDRESS,
Expand Down Expand Up @@ -40,12 +45,17 @@ async function updateSteps(result) {
);

// Write edges.csv file to update edges
submitJob(tasks.exportEdges, 'exportEdges-findTransferSteps');
submitJob(tasks.exportEdges, 'exportEdges-updateSteps');

return values.every((step) => step.status === 'fulfilled');
}

export default async function updatePath({ from, to, value }) {
export default async function updatePath({
from,
to,
value,
hops = HOPS_DEFAULT
}) {
const timeout = process.env.TRANSFER_STEPS_TIMEOUT
? parseInt(process.env.TRANSFER_STEPS_TIMEOUT, 10)
: DEFAULT_PROCESS_TIMEOUT;
Expand All @@ -58,6 +68,7 @@ export default async function updatePath({ from, to, value }) {
from,
to,
value,
hops,
},
{
edgesFile: EDGES_FILE_PATH,
Expand Down
1 change: 1 addition & 0 deletions src/validations/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
value: Joi.string()
.pattern(/^[0-9]+$/, { name: 'numbers' })
.required(),
hops: Joi.number().integer().min(1).max(100).allow(null),
}),
},
};
24 changes: 24 additions & 0 deletions test/transfers-find-steps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,28 @@ describe('POST /transfers - Find transfer steps', () => {
.set('Accept', 'application/json')
.expect(httpStatus.BAD_REQUEST);
});
it('should return an error when hops is not positive', async () => {
await request(app)
.post('/api/transfers')
.send({
from: randomChecksumAddress(),
to: randomChecksumAddress(),
value: '5',
hops: '0'
})
.set('Accept', 'application/json')
.expect(httpStatus.BAD_REQUEST);
});
it('should return an error when hops is empty', async () => {
await request(app)
.post('/api/transfers')
.send({
from: randomChecksumAddress(),
to: randomChecksumAddress(),
value: '5',
hops: ''
})
.set('Accept', 'application/json')
.expect(httpStatus.BAD_REQUEST);
});
});

0 comments on commit bac5587

Please sign in to comment.