Skip to content

Commit

Permalink
SHARD-1137: Fix getTxTimestampBinary bucket size (#367)
Browse files Browse the repository at this point in the history
* SHARD-1137: Fix getTxTimestampBinary size

* SHARD-1137: Fix getTxTimestampBinary size

* SHARD-1137: Fix getTxTimestampBinary size
  • Loading branch information
mgthuramoemyint authored Jan 20, 2025
1 parent 1ec9f43 commit 2026232
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const SERVER_CONFIG: StrictServerConfiguration = {
networkTransactionsToProcessPerCycle: 20,
getTxTimestampTimeoutOffset: 0,
dropNGTByGossipEnabled: false,
timestampCacheFixSize: 10000
},
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 @@ -986,6 +986,7 @@ export interface ServerConfiguration {
getTxTimestampTimeoutOffset?: number // default timeout is 5 seconds so this can be used to add or subtract time from that
/** allow dropping NGTs by hitting a single node's endpoint and the drop mesage being sent to other nodes by gossip */
dropNGTByGossipEnabled: boolean
timestampCacheFixSize: number
}
/** Server IP configuration */
ip?: {
Expand Down
21 changes: 20 additions & 1 deletion src/state-manager/TransactionConsensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,21 @@ class TransactionConsenus {
nestedCountersInstance.countEvent('consensus', 'get_tx_timestamp found tx timestamp in cacheById')
return tsReceipt
}

// Ensure the cycleCounter is within the acceptable range relative to lastest cycle number. If the absolute difference is greater than 1, return null to indicate an invalid state.
if (Math.abs(cycleCounter - CycleChain.newest.counter) > 1 ){
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 +1844,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

0 comments on commit 2026232

Please sign in to comment.