Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHARD-1137: Fix getTxTimestampBinary bucket size #349

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ const SERVER_CONFIG: StrictServerConfiguration = {
timestampCacheFix: true,
useAjvCycleRecordValidation: true,
networkTransactionsToProcessPerCycle: 20,
getTxTimestampTimeoutOffset: 0
getTxTimestampTimeoutOffset: 0,
timestampCacheFixsize: 10000
mgthuramoemyint marked this conversation as resolved.
Show resolved Hide resolved
},
ip: {
externalIp: '0.0.0.0',
Expand Down
1 change: 1 addition & 0 deletions src/shardus/shardus-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ export interface ServerConfiguration {
networkTransactionsToProcessPerCycle: number
useAjvCycleRecordValidation: boolean
getTxTimestampTimeoutOffset?: number // default timeout is 5 seconds so this can be used to add or subtract time from that
timestampCacheFixsize: number
}
/** Server IP configuration */
ip?: {
Expand Down
20 changes: 19 additions & 1 deletion src/state-manager/TransactionConsensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,20 @@ class TransactionConsenus {
nestedCountersInstance.countEvent('consensus', 'get_tx_timestamp found tx timestamp in cacheById')
return tsReceipt
}

if (Math.abs(cycleCounter - CycleChain.newest.counter) > 1 ){
mgthuramoemyint marked this conversation as resolved.
Show resolved Hide resolved
return null
}
if (this.txTimestampCache.size >= Context.config.p2p.timestampCacheFixsize) {
const oldestCycleCounter = [...this.txTimestampCache.keys()][0]
const txMap = this.txTimestampCache.get(oldestCycleCounter);
if (txMap && txMap.size > 0) {
const oldestTxId = [...txMap.keys()][0]
txMap.delete(oldestTxId)
}
if (txMap.size === 0) {
this.txTimestampCache.delete(oldestCycleCounter);
}
}
const tsReceipt: TimestampReceipt = {
txId,
cycleMarker,
Expand All @@ -1830,6 +1843,11 @@ class TransactionConsenus {
// cache to txId map
this.txTimestampCache.get(signedTsReceipt.cycleCounter).set(txId, signedTsReceipt)
if (Context.config.p2p.timestampCacheFix) {
if (this.txTimestampCacheByTxId.size >= Context.config.p2p.timestampCacheFixsize) {
const oldestTxId = [...this.txTimestampCacheByTxId.keys()][0]
this.txTimestampCacheByTxId.delete(oldestTxId)
this.seenTimestampRequests.delete(oldestTxId)
}
// eslint-disable-next-line security/detect-object-injection
this.txTimestampCacheByTxId.set(txId, signedTsReceipt)
this.seenTimestampRequests.add(txId)
Expand Down
Loading