Skip to content

Commit a253f4f

Browse files
authored
lukas/fix grpc multi user smol bugs (#1995)
* fix: add missing slot check on multi user update slot * feat: min i64 * feat: only flush grpc multi user subscriber if is multi subscribed * fix: prettier and lint
1 parent 0f930ab commit a253f4f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sdk/src/accounts/grpcMultiUserAccountSubscriber.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export class grpcMultiUserAccountSubscriber {
119119
this.listeners.set(key, new Set());
120120
this.keyToPk.set(key, userAccountPublicKey);
121121
this.pendingAddKeys.add(key);
122-
this.scheduleFlush();
122+
if (this.isMultiSubscribed) {
123+
// only schedule flush if already subscribed to the multi-subscriber
124+
this.scheduleFlush();
125+
}
123126
}
124127
};
125128

@@ -161,6 +164,10 @@ export class grpcMultiUserAccountSubscriber {
161164
},
162165

163166
updateData(userAccount: UserAccount, slot: number): void {
167+
const existingData = parent.userData.get(key);
168+
if (existingData && existingData.slot > slot) {
169+
return;
170+
}
164171
parent.userData.set(key, { data: userAccount, slot });
165172
perUserEmitter.emit('userAccountUpdate', userAccount);
166173
perUserEmitter.emit('update');

sdk/src/constants/numericConstants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
22
import { BN } from '@coral-xyz/anchor';
3+
import { BigNum } from '../factory/bigNum';
34

45
export const ZERO = new BN(0);
56
export const ONE = new BN(1);
@@ -116,3 +117,7 @@ export const FUEL_START_TS = new BN(1723147200); // unix timestamp
116117
export const MAX_PREDICTION_PRICE = PRICE_PRECISION;
117118

118119
export const GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = 99;
120+
121+
// integer constants
122+
export const MAX_I64 = BigNum.fromPrint('9223372036854775807').val;
123+
export const MIN_I64 = BigNum.fromPrint('-9223372036854775808').val;

0 commit comments

Comments
 (0)