Skip to content

Commit

Permalink
chore: remove min of 2 hash hack, we don't need it anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Nov 24, 2024
1 parent 1035a1b commit c7995a0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
3 changes: 0 additions & 3 deletions ts/session/apis/snode_api/SnodeRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,6 @@ type StoreOnNodeParams = StoreOnNodeNormalParams | StoreOnNodeSubAccountParams;

export type MethodBatchType = 'batch' | 'sequence';

// Until the next storage server release is released, we need to have at least 2 hashes in the list for the `get_expiries` AND for the `update_expiries`
export const fakeHash = '///////////////////////////////////////////';

export type RawSnodeSubRequests =
| RetrieveLegacyClosedGroupSubRequest
| RetrieveUserSubRequest
Expand Down
15 changes: 2 additions & 13 deletions ts/session/apis/snode_api/expireRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { getSodiumRenderer } from '../../crypto';
import { StringUtils, UserUtils } from '../../utils';
import { fromBase64ToArray, fromHexToArray } from '../../utils/String';
import { SeedNodeAPI } from '../seed_node_api';
import {
MAX_SUBREQUESTS_COUNT,
UpdateExpiryOnNodeUserSubRequest,
fakeHash,
} from './SnodeRequestTypes';
import { MAX_SUBREQUESTS_COUNT, UpdateExpiryOnNodeUserSubRequest } from './SnodeRequestTypes';
import { BatchRequests } from './batchRequest';
import { SnodePool } from './snodePool';
import {
Expand Down Expand Up @@ -224,7 +220,7 @@ async function updateExpiryOnNodesNoRetries(

const hashesRequestedButNotInResults = difference(
flatten(expireRequests.map(m => m.messageHashes)),
[...flatten(changesValid.map(c => c.messageHashes)), fakeHash]
[...flatten(changesValid.map(c => c.messageHashes))]
);
if (!isEmpty(hashesRequestedButNotInResults)) {
const now = Date.now();
Expand Down Expand Up @@ -347,13 +343,6 @@ function groupMsgByExpiry(expiringDetails: ExpiringDetails) {
groupedBySameExpiry[expiryStr].push(messageHash);
}

Object.keys(groupedBySameExpiry).forEach(k => {
if (groupedBySameExpiry[k].length === 1) {
// We need to have at least 2 hashes until the next storage server release
groupedBySameExpiry[k].push(fakeHash);
}
});

return groupedBySameExpiry;
}

Expand Down
9 changes: 2 additions & 7 deletions ts/session/apis/snode_api/getExpiriesRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pRetry from 'p-retry';
import { Snode } from '../../../data/types';
import { UserUtils } from '../../utils';
import { SeedNodeAPI } from '../seed_node_api';
import { GetExpiriesFromNodeSubRequest, fakeHash } from './SnodeRequestTypes';
import { GetExpiriesFromNodeSubRequest } from './SnodeRequestTypes';
import { BatchRequests } from './batchRequest';
import { SnodePool } from './snodePool';
import { GetExpiriesResultsContent, WithMessagesHashes } from './types';
Expand Down Expand Up @@ -104,14 +104,9 @@ async function getExpiriesFromNodesNoRetries(
* The returned TTLs should be assigned to the given disappearing messages.
* @param messageHashes the hashes of the messages we want the current expiries for
* @param timestamp the time (ms) the request was initiated, must be within ±60s of the current time so using the server time is recommended.
* @returns an arrray of the expiry timestamps (TTL) for the given messages
* @returns an array of the expiry timestamps (TTL) for the given messages
*/
export async function getExpiriesFromSnode({ messagesHashes }: WithMessagesHashes) {
// FIXME There is a bug in the snode code that requires at least 2 messages to be requested. Will be fixed in next storage server release
if (messagesHashes.length === 1) {
messagesHashes.push(fakeHash);
}

const ourPubKey = UserUtils.getOurPubKeyStrFromCache();
if (!ourPubKey) {
window.log.error('[getExpiriesFromSnode] No pubkey found', messagesHashes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { PubkeyType } from 'libsession_util_nodejs';
import Sinon from 'sinon';
import {
GetExpiriesFromNodeSubRequest,
fakeHash,
} from '../../../../session/apis/snode_api/SnodeRequestTypes';
import { GetExpiriesFromNodeSubRequest } from '../../../../session/apis/snode_api/SnodeRequestTypes';
import {
GetExpiriesRequestResponseResults,
processGetExpiriesRequestResponse,
Expand Down Expand Up @@ -110,8 +107,7 @@ describe('GetExpiriesRequest', () => {
const props = {
targetNode: generateFakeSnode(),
expiries: { 'FLTUh/C/6E+sWRgNtrqWPXhQqKlIrpHVKJJtZsBMWKw': 1696983251624 },
// FIXME There is a bug in the snode code that requires at least 2 messages to be requested. Will be fixed in next storage server release
messageHashes: ['FLTUh/C/6E+sWRgNtrqWPXhQqKlIrpHVKJJtZsBMWKw', fakeHash],
messageHashes: ['FLTUh/C/6E+sWRgNtrqWPXhQqKlIrpHVKJJtZsBMWKw'],
};

it('returns valid results if the response is valid', async () => {
Expand Down

0 comments on commit c7995a0

Please sign in to comment.