-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write updateNetworkTxsList func create /network-txs-list endpoint fix: improper logic in case txRemove tx is not in txList ServiceQueue: updated sortedInsert() definition and calls ServiceQueue: fix Logger import add verify function for syncing txList add queries for syncing txList from validators add syncTxList func + use it in syncV2 step add ServiceQueue funcs + minor refactor handle case where txList isnt correct post-cycle record parse
- Loading branch information
1 parent
9a14537
commit 41b5c1f
Showing
6 changed files
with
217 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { P2P } from "@shardus/types"; | ||
import * as Logger from './Logger' | ||
import { stringifyReduce } from "./profiler/StringifyReduce"; | ||
import * as crypto from './Crypto' | ||
|
||
let txList: P2P.ServiceQueueTypes.NetworkTxEntry[] = [] | ||
|
||
export function addTxs(addTxs: P2P.ServiceQueueTypes.AddNetworkTx[]): boolean { | ||
try { | ||
for (const addTx of addTxs) { | ||
Logger.mainLogger.info(`Adding network tx of type ${addTx.type} and payload ${stringifyReduce(addTx.txData)}`) | ||
Check warning Code scanning / CodeQL Log injection Medium
Log entry depends on a
user-provided value Error loading related location Loading |
||
const { sign, ...txDataWithoutSign } = addTx.txData | ||
sortedInsert(txList, { | ||
hash: addTx.hash, | ||
tx: { | ||
hash: addTx.hash, | ||
txData: txDataWithoutSign, | ||
type: addTx.type, | ||
cycle: addTx.cycle, | ||
...(addTx.subQueueKey && { subQueueKey: addTx.subQueueKey }), | ||
}, | ||
}) | ||
} | ||
return true | ||
} catch (e) { | ||
Logger.mainLogger.error(`ServiceQueue:addTxs: Error adding txs: ${e}`) | ||
return false | ||
} | ||
} | ||
|
||
export function removeTxs(removeTxs: P2P.ServiceQueueTypes.RemoveNetworkTx[]): boolean { | ||
try { | ||
for (const removeTx of removeTxs) { | ||
const index = txList.findIndex((entry) => entry.hash === removeTx.txHash) | ||
if (index === -1) { | ||
Logger.mainLogger.error(`TxHash ${removeTx.txHash} does not exist in txList`) | ||
Check warning Code scanning / CodeQL Log injection Medium
Log entry depends on a
user-provided value Error loading related location Loading |
||
} else { | ||
txList.splice(index, 1) | ||
} | ||
} | ||
return true | ||
} catch (e) { | ||
Logger.mainLogger.error(`ServiceQueue:removeTxs: Error removing txs: ${e}`) | ||
return false | ||
} | ||
} | ||
|
||
export function setTxList(_txList: P2P.ServiceQueueTypes.NetworkTxEntry[]): void { | ||
txList = _txList | ||
} | ||
|
||
export function getTxList(): P2P.ServiceQueueTypes.NetworkTxEntry[] { | ||
return txList | ||
} | ||
|
||
export function getNetworkTxsListHash(): string { | ||
return crypto.hashObj(txList) | ||
} | ||
|
||
function sortedInsert( | ||
list: P2P.ServiceQueueTypes.NetworkTxEntry[], | ||
entry: P2P.ServiceQueueTypes.NetworkTxEntry | ||
): void { | ||
const index = list.findIndex( | ||
(item) => | ||
item.tx.cycle > entry.tx.cycle || (item.tx.cycle === entry.tx.cycle && item.hash > entry.tx.hash) | ||
) | ||
if (index === -1) { | ||
list.push(entry) | ||
} else { | ||
list.splice(index, 0, entry) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters