Skip to content

Commit 40dedfe

Browse files
fix: allow (DATASET_INFINITE_VOLUME - 1) in bulk datasetorders for compatibility with already signed orders (#45)
Due to a communication error, some users have signed datasetorders with volume `9007199254740990` instead of `9007199254740991` to represent infinite volume suitable for bulk processing. To address compatibility with these orders, a decision has been made to accept datasetorders with volume greater than or equal to `9007199254740990` in bulk processing.
1 parent 6652122 commit 40dedfe

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

api/src/services/order.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
TAG_MAP,
3232
tagToArray,
3333
excludeTagArray,
34+
DATASET_INFINITE_VOLUME,
3435
} from '../utils/order-utils.js';
3536
import { maxOpenOrdersPerWallet } from '../config.js';
3637
import { ANY } from '../utils/keywords.js';
@@ -588,7 +589,7 @@ const getDatasetorders = async ({
588589
...(dataset && requiredDatasetOrAnyClause(dataset)),
589590
...(datasetOwner && { signer: datasetOwner }),
590591
...(bulkOnly && {
591-
'order.volume': Number.MAX_SAFE_INTEGER,
592+
'order.volume': { $gte: DATASET_INFINITE_VOLUME - 1 }, // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
592593
'order.datasetprice': 0,
593594
}),
594595
...apprestrictOrAnyClause(app, isAppStrict),

api/src/utils/order-utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,21 @@ const excludeTagArray = (tagArray) =>
139139
})
140140
.filter((e) => e !== null);
141141

142+
const DATASET_INFINITE_VOLUME = Number.MAX_SAFE_INTEGER;
143+
142144
const isDatasetBulkOrder = (order = {}) => {
143-
return order?.volume >= Number.MAX_SAFE_INTEGER && order?.datasetprice === 0;
145+
return (
146+
order?.volume >= DATASET_INFINITE_VOLUME - 1 && // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
147+
order?.datasetprice === 0
148+
);
144149
};
145150

146151
export {
147152
OBJ_MAP,
148153
STATUS_MAP,
149154
TAG_MAP,
150155
UNPUBLISH_TARGET_MAP,
156+
DATASET_INFINITE_VOLUME,
151157
tagToArray,
152158
excludeTagArray,
153159
isDatasetBulkOrder,

api/test/datasetorders.test.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import supertest from 'supertest';
1111
import { Wallet } from 'ethers';
1212
import { IExec, utils } from 'iexec';
1313
import { chains } from '../src/config.js';
14-
import { STATUS_MAP } from '../src/utils/order-utils.js';
14+
import {
15+
DATASET_INFINITE_VOLUME,
16+
STATUS_MAP,
17+
} from '../src/utils/order-utils.js';
1518
import {
1619
WALLETS,
1720
sleep,
@@ -950,15 +953,15 @@ describe('Offchain marketplace', () => {
950953
noRestrictOrders.push(...datasetPrice0);
951954
allOrders.push(...datasetPrice0);
952955

953-
const bulk = await Promise.all(
954-
Array(2)
956+
const bulk = await Promise.all([
957+
...Array(2)
955958
.fill(null)
956959
.map(async () => {
957960
const order = await iexecUser.order
958961
.createDatasetorder({
959962
dataset: datasetAddress,
960963
datasetprice: 0, // bulk order must be free
961-
volume: Number.MAX_SAFE_INTEGER, // bulk order must have max volume
964+
volume: DATASET_INFINITE_VOLUME, // bulk order must have max volume
962965
})
963966
.then(iexecUser.order.signDatasetorder);
964967
const orderHash = await iexecUser.order.hashDatasetorder(order);
@@ -968,7 +971,24 @@ describe('Offchain marketplace', () => {
968971
signer: ownerAddress,
969972
};
970973
}),
971-
);
974+
...Array(2)
975+
.fill(null)
976+
.map(async () => {
977+
const order = await iexecUser.order
978+
.createDatasetorder({
979+
dataset: datasetAddress,
980+
datasetprice: 0, // bulk order must be free
981+
volume: DATASET_INFINITE_VOLUME - 1, // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
982+
})
983+
.then(iexecUser.order.signDatasetorder);
984+
const orderHash = await iexecUser.order.hashDatasetorder(order);
985+
return {
986+
order,
987+
orderHash,
988+
signer: ownerAddress,
989+
};
990+
}),
991+
]);
972992
bulkOrders.push(...bulk);
973993
minVolumeOrders.push(...bulk);
974994
noRestrictOrders.push(...bulk);
@@ -1864,7 +1884,7 @@ describe('Offchain marketplace', () => {
18641884
expect(Array.isArray(notOnlyBulkRes.data.orders)).toBe(true);
18651885
notOnlyBulkRes.data.orders.forEach((e) => {
18661886
if (
1867-
e.order.volume >= Number.MAX_SAFE_INTEGER &&
1887+
e.order.volume >= DATASET_INFINITE_VOLUME - 1 && // DATASET_INFINITE_VOLUME - 1 is accepted for compatibility with existing orders
18681888
e.order.datasetprice === 0
18691889
) {
18701890
expect(e.bulk).toBe(true);

0 commit comments

Comments
 (0)