Skip to content

Commit 994140d

Browse files
authored
SHARD-1149: fix case for timestamp fetching failing or timing out (#342)
* add `getTxTimestampTimeoutOffset` config for controlling timeout of `binary/get_tx_timestamp` call * fix: correctly check for injectedTimestamp existence + add logging context to timestamp function for easier debugging * fix: build * rename variable
1 parent 4744a5b commit 994140d

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

src/config/server.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ const SERVER_CONFIG: StrictServerConfiguration = {
155155
requiredVotesPercentage: 2 / 3.0,
156156
timestampCacheFix: true,
157157
useAjvCycleRecordValidation: true,
158-
networkTransactionsToProcessPerCycle: 20
158+
networkTransactionsToProcessPerCycle: 20,
159+
getTxTimestampTimeoutOffset: 0
159160
},
160161
ip: {
161162
externalIp: '0.0.0.0',

src/shardus/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ class Shardus extends EventEmitter {
10591059
}
10601060
}
10611061

1062-
async _timestampAndQueueTransaction(tx: ShardusTypes.OpaqueTransaction, appData: any, global = false, noConsensus = false) {
1062+
async _timestampAndQueueTransaction(tx: ShardusTypes.OpaqueTransaction, appData: any, global = false, noConsensus = false, loggingContext = '') {
10631063
// Give the dapp an opportunity to do some up front work and generate
10641064
// appData metadata for the applied TX
10651065
const { status: preCrackSuccess, reason } = await this.app.txPreCrackData(tx, appData)
@@ -1075,7 +1075,8 @@ class Shardus extends EventEmitter {
10751075

10761076
const txId = this.app.calculateTxId(tx);
10771077
let timestampReceipt: ShardusTypes.TimestampReceipt;
1078-
if (!injectedTimestamp || injectedTimestamp === -1) {
1078+
let isMissingInjectedTimestamp = !injectedTimestamp || injectedTimestamp === -1
1079+
if (isMissingInjectedTimestamp) {
10791080
if (injectedTimestamp === -1) {
10801081
/* prettier-ignore */
10811082
if (logFlags.p2pNonFatal && logFlags.console) console.log("Dapp request to generate a new timestmap for the tx");
@@ -1085,13 +1086,13 @@ class Shardus extends EventEmitter {
10851086
if (logFlags.p2pNonFatal && logFlags.console) console.log("Network generated a" +
10861087
" timestamp", txId, timestampReceipt);
10871088
}
1088-
if (!injectedTimestamp && !timestampReceipt) {
1089+
if (isMissingInjectedTimestamp && !timestampReceipt) {
10891090
this.shardus_fatal(
10901091
"put_noTimestamp",
10911092
`Transaction timestamp cannot be determined ${utils.stringifyReduce(tx)} `
10921093
);
10931094
this.statistics.incrementCounter("txRejected");
1094-
nestedCountersInstance.countEvent("rejected", "_timestampNotDetermined");
1095+
nestedCountersInstance.countEvent("rejected", `_timestampNotDetermined-${loggingContext}`);
10951096
return {
10961097
success: false,
10971098
reason: "Transaction timestamp cannot be determined.",
@@ -1139,7 +1140,7 @@ class Shardus extends EventEmitter {
11391140

11401141
if (inRangeOfCurrentTime(timestamp, txExpireTimeMs, txExpireTimeMs) === false) {
11411142
/* prettier-ignore */
1142-
this.shardus_fatal(`tx_outofrange`, `Transaction timestamp out of range: timestamp:${timestamp} now:${shardusGetTime()} diff(now-ts):${shardusGetTime() - timestamp} ${utils.stringifyReduce(tx)} our offset: ${getNetworkTimeOffset()} `);
1143+
this.shardus_fatal(`tx_outofrange`, `Transaction timestamp out of range: timestamp:${timestamp} now:${shardusGetTime()} diff(now-ts):${shardusGetTime() - timestamp} ${utils.stringifyReduce(tx)} our offset: ${getNetworkTimeOffset()} loggingContext: ${loggingContext}`);
11431144
this.statistics.incrementCounter("txRejected");
11441145
nestedCountersInstance.countEvent("rejected", "transaction timestamp out of range");
11451146
return { success: false, reason: "Transaction timestamp out of range", status: 400 };
@@ -1609,7 +1610,7 @@ class Shardus extends EventEmitter {
16091610
}
16101611
} else {
16111612
// tx nonce is equal to account nonce
1612-
let result = await this._timestampAndQueueTransaction(tx, appData, global, noConsensus)
1613+
let result = await this._timestampAndQueueTransaction(tx, appData, global, noConsensus, 'immediateQueue')
16131614

16141615
// start of timestamp logging
16151616
if (logFlags.important_as_error) {

src/shardus/shardus-types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ export interface ServerConfiguration {
943943
// /** The number of network transactions to try to process per cycle from txAdd in cycle record */
944944
networkTransactionsToProcessPerCycle: number
945945
useAjvCycleRecordValidation: boolean
946+
getTxTimestampTimeoutOffset?: number // default timeout is 5 seconds so this can be used to add or subtract time from that
946947
}
947948
/** Server IP configuration */
948949
ip?: {

src/state-manager/TransactionConsensus.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,10 @@ class TransactionConsenus {
18891889
},
18901890
serializeGetTxTimestampReq,
18911891
deserializeGetTxTimestampResp,
1892-
{}
1892+
{},
1893+
'',
1894+
false,
1895+
this.config.p2p.getTxTimestampTimeoutOffset ?? 0
18931896
)
18941897

18951898
timestampReceipt = serialized_res

src/state-manager/TransactionQueue.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,13 @@ class TransactionQueue {
11151115
}
11161116
// end of timestamp logging.
11171117

1118-
await this.stateManager.shardus._timestampAndQueueTransaction(item.tx, item.appData, item.global, item.noConsensus)
1118+
await this.stateManager.shardus._timestampAndQueueTransaction(
1119+
item.tx,
1120+
item.appData,
1121+
item.global,
1122+
item.noConsensus,
1123+
'nonceQueue'
1124+
)
11191125

11201126
// start of timestamp logging
11211127
if (logFlags.important_as_error) {

0 commit comments

Comments
 (0)