Skip to content

Commit 57dc00f

Browse files
feat: removed develpment logs & helpers from pub-sub
1 parent a0930f1 commit 57dc00f

File tree

6 files changed

+8
-73
lines changed

6 files changed

+8
-73
lines changed

src/dex/cables/rate-fetcher.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,7 @@ export class CablesRateFetcher {
106106
logger,
107107
);
108108

109-
this.blacklistPubSub = new NonExpSetPubSub(
110-
dexHelper,
111-
dexKey,
112-
'blacklist',
113-
'',
114-
);
109+
this.blacklistPubSub = new NonExpSetPubSub(dexHelper, dexKey, 'blacklist');
115110
this.blacklistFetcher = new Fetcher<CablesBlacklistResponse>(
116111
dexHelper.httpRequest,
117112
{

src/dex/dexalot/rate-fetcher.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,7 @@ export class RateFetcher {
105105
logger,
106106
);
107107

108-
this.blacklistPubSub = new NonExpSetPubSub(
109-
dexHelper,
110-
dexKey,
111-
'blacklist',
112-
this.blacklistCacheKey,
113-
);
114-
108+
this.blacklistPubSub = new NonExpSetPubSub(dexHelper, dexKey, 'blacklist');
115109
this.blacklistFetcher = new Fetcher<DexalotBlacklistResponse>(
116110
dexHelper.httpRequest,
117111
{

src/dex/generic-rfq/rate-fetcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ export class RateFetcher {
158158
this.dexHelper,
159159
this.dexKey,
160160
'blacklist',
161-
this.blackListCacheKey,
162161
);
163162
}
164163

src/dex/hashflow/rate-fetcher.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ export class RateFetcher {
102102
dexHelper,
103103
dexKey,
104104
'blacklisted',
105-
// TODO-rfq-ps: temporary for validation local with cache
106-
'',
107105
);
108106
}
109107

src/dex/swaap-v2/rate-fetcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export class RateFetcher {
114114
this.dexHelper,
115115
this.dexKey,
116116
'blacklist',
117-
'',
118117
);
119118
}
120119

src/lib/pub-sub.ts

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ import NodeCache from 'node-cache';
22
import { Network } from '../constants';
33
import { IDexHelper } from '../dex-helper';
44
import { Logger } from '../types';
5-
import _ from 'lodash';
6-
import jsonDiff from 'json-diff';
7-
import hash from 'object-hash';
85

96
type KeyValuePubSubMsg = {
107
expiresAt: number;
11-
hash: string;
128
data: Record<string, unknown>;
139
};
1410

@@ -19,7 +15,6 @@ export class ExpKeyValuePubSub {
1915
network: Network;
2016
localCache: NodeCache = new NodeCache();
2117

22-
// TODO-rfq-ps: temporary logger
2318
logger: Logger;
2419

2520
constructor(
@@ -45,20 +40,15 @@ export class ExpKeyValuePubSub {
4540
}
4641

4742
publish(data: Record<string, unknown>, ttl: number) {
48-
const hashedData = hash(data);
49-
this.logger.info(`Publishing to ${this.channel} with hash ${hashedData}`);
50-
5143
const expiresAt = Math.round(Date.now() / 1000) + ttl;
5244
this.dexHelper.cache.publish(
5345
this.channel,
54-
JSON.stringify({ expiresAt, data, hash: hashedData }),
46+
JSON.stringify({ expiresAt, data }),
5547
);
5648
}
5749

5850
handleSubscription(msg: KeyValuePubSubMsg) {
59-
const { expiresAt, data, hash } = msg;
60-
61-
this.logger.info(`Received message from ${this.channel} with hash ${hash}`);
51+
const { expiresAt, data } = msg;
6252

6353
const now = Math.round(Date.now() / 1000);
6454
// calculating ttl as message might come with the delay
@@ -82,31 +72,16 @@ export class ExpKeyValuePubSub {
8272
async getAndCache<T>(key: string): Promise<T | null> {
8373
const localValue = this.localCache.get<T>(key);
8474

85-
// if (localValue) {
86-
// return localValue;
87-
// }
75+
if (localValue) {
76+
return localValue;
77+
}
8878

8979
const [value, ttl] = await Promise.all([
9080
this.dexHelper.cache.get(this.dexKey, this.network, key),
9181
this.dexHelper.cache.ttl(this.dexKey, this.network, key),
9282
]);
9383

94-
// TODO-rfq-ps: compare local and cache value
95-
const isEqual = _.isEqual(
96-
localValue ?? null,
97-
value ? JSON.parse(value) : null,
98-
);
99-
if (!isEqual) {
100-
this.logger.info(
101-
`Values are not equal for the key ${key}, local: ${JSON.stringify(
102-
localValue,
103-
)}, cache: ${value}, diff: ${jsonDiff.diffString(localValue, value)}`,
104-
);
105-
}
106-
10784
if (value && ttl > 0) {
108-
// setting ttl same as in cache
109-
// TODO-ps: check if ttl is not null
11085
const parsedValue = JSON.parse(value);
11186
this.localCache.set(key, parsedValue, ttl);
11287
return parsedValue;
@@ -126,14 +101,12 @@ export class NonExpSetPubSub {
126101
network: Network;
127102
set = new Set<string>();
128103

129-
// TODO-rfq-ps: temporary logger
130104
logger: Logger;
131105

132106
constructor(
133107
private dexHelper: IDexHelper,
134108
private dexKey: string,
135109
channel: string,
136-
private blackListCacheKey: string,
137110
) {
138111
this.network = this.dexHelper.config.data.network;
139112
this.channel = `${this.network}_${this.dexKey}_${channel}`;
@@ -142,7 +115,6 @@ export class NonExpSetPubSub {
142115
}
143116

144117
async initializeAndSubscribe(initialSet: string[]) {
145-
// as there's no lazy load, we need to initialize the set
146118
for (const member of initialSet) {
147119
this.set.add(member);
148120
}
@@ -160,38 +132,16 @@ export class NonExpSetPubSub {
160132
}
161133

162134
publish(msg: SetPubSubMsg) {
163-
this.logger.info(`Publishing to ${this.channel}`);
164-
165-
// should not be a problem, as we also subscribe to the channel on the same instance
166-
// // as there's no lazy load, also store locally
167-
// for (const key of set) {
168-
// this.set.add(key);
169-
// }
170135
this.dexHelper.cache.publish(this.channel, JSON.stringify(msg));
171136
}
172137

173138
handleSubscription(set: SetPubSubMsg) {
174-
this.logger.info(`Received message from ${this.channel}`);
175139
for (const key of set) {
176140
this.set.add(key);
177141
}
178142
}
179143

180144
async has(key: string) {
181-
const localValue = this.set.has(key);
182-
183-
const value = await this.dexHelper.cache.sismember(
184-
this.blackListCacheKey,
185-
key,
186-
);
187-
188-
// TODO-rfq-ps: compare local and cache value
189-
const isEqual = localValue === value;
190-
191-
if (!isEqual) {
192-
this.logger.error('Values are not equal', { localValue, value });
193-
}
194-
195-
return value;
145+
return this.set.has(key);
196146
}
197147
}

0 commit comments

Comments
 (0)