Skip to content

Commit

Permalink
Merge branch 'dev' into GOLD-221
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketdivekar authored Dec 9, 2024
2 parents a1f249d + a018859 commit c8c53c2
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 197 deletions.
1 change: 1 addition & 0 deletions src/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const SERVER_CONFIG: StrictServerConfiguration = {
timestampCacheFix: true,
useAjvCycleRecordValidation: true,
networkTransactionsToProcessPerCycle: 20,
getTxTimestampTimeoutOffset: 0
},
ip: {
externalIp: '0.0.0.0',
Expand Down
34 changes: 18 additions & 16 deletions src/p2p/Lost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ FUTURE-SLASHING
we would not want to blindly check signatures, and may later need
a way to mark a node as bad if it spams the ping endpoint too much
*/
const pingNodeRoute: P2P.P2PTypes.Route<P2P.P2PTypes.InternalHandler<SignedPingMessage>> = {
name: 'ping-node',
handler: (payload, response, sender) => {
profilerInstance.scopedProfileSectionStart('ping-node')
try {
//used by isNodeDown to test if a node can be reached on the internal protocol
if (payload?.m === 'ping') {
response({ s: 'ack', r: 1 })
}
} finally {
profilerInstance.scopedProfileSectionEnd('ping-node')
}
},
}
// const pingNodeRoute: P2P.P2PTypes.Route<P2P.P2PTypes.InternalHandler<SignedPingMessage>> = {
// name: 'ping-node',
// handler: (payload, response, sender) => {
// profilerInstance.scopedProfileSectionStart('ping-node')
// try {
// //used by isNodeDown to test if a node can be reached on the internal protocol
// if (payload?.m === 'ping') {
// response({ s: 'ack', r: 1 })
// }
// } finally {
// profilerInstance.scopedProfileSectionEnd('ping-node')
// }
// },
// }

const lostDownRoute: P2P.P2PTypes.GossipHandler = (
payload: P2P.LostTypes.SignedDownGossipMessage,
Expand Down Expand Up @@ -200,7 +200,7 @@ const removeByAppRoute: P2P.P2PTypes.GossipHandler = (

const routes = {
external: [killExternalRoute, killOtherExternalRoute],
internal: [pingNodeRoute], //lostReportRoute
internal: [], //pingNodeRoute, lostReportRoute
gossip: {
'lost-down': lostDownRoute,
'lost-up': lostUpRoute,
Expand Down Expand Up @@ -271,7 +271,9 @@ export function init() {
{}
)
} else {
res = await Comms.ask(targetNode, payload.route, payload.message)
error(`proxy handler route is not get_trie_hashes: ${payload.route}`)
await respond(proxyRes)
return
}
proxyRes = {
success: true,
Expand Down
46 changes: 40 additions & 6 deletions src/shardus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ class Shardus extends EventEmitter {
}
}

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

const txId = this.app.calculateTxId(tx);
let timestampReceipt: ShardusTypes.TimestampReceipt;
if (!injectedTimestamp || injectedTimestamp === -1) {
let isMissingInjectedTimestamp = !injectedTimestamp || injectedTimestamp === -1
if (isMissingInjectedTimestamp) {
if (injectedTimestamp === -1) {
/* prettier-ignore */
if (logFlags.p2pNonFatal && logFlags.console) console.log("Dapp request to generate a new timestmap for the tx");
Expand All @@ -1085,13 +1086,13 @@ class Shardus extends EventEmitter {
if (logFlags.p2pNonFatal && logFlags.console) console.log("Network generated a" +
" timestamp", txId, timestampReceipt);
}
if (!injectedTimestamp && !timestampReceipt) {
if (isMissingInjectedTimestamp && !timestampReceipt) {
this.shardus_fatal(
"put_noTimestamp",
`Transaction timestamp cannot be determined ${utils.stringifyReduce(tx)} `
);
this.statistics.incrementCounter("txRejected");
nestedCountersInstance.countEvent("rejected", "_timestampNotDetermined");
nestedCountersInstance.countEvent("rejected", `_timestampNotDetermined-${loggingContext}`);
return {
success: false,
reason: "Transaction timestamp cannot be determined.",
Expand Down Expand Up @@ -1139,7 +1140,7 @@ class Shardus extends EventEmitter {

if (inRangeOfCurrentTime(timestamp, txExpireTimeMs, txExpireTimeMs) === false) {
/* prettier-ignore */
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()} `);
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}`);
this.statistics.incrementCounter("txRejected");
nestedCountersInstance.countEvent("rejected", "transaction timestamp out of range");
return { success: false, reason: "Transaction timestamp out of range", status: 400 };
Expand Down Expand Up @@ -1609,7 +1610,7 @@ class Shardus extends EventEmitter {
}
} else {
// tx nonce is equal to account nonce
let result = await this._timestampAndQueueTransaction(tx, appData, global, noConsensus)
let result = await this._timestampAndQueueTransaction(tx, appData, global, noConsensus, 'immediateQueue')

// start of timestamp logging
if (logFlags.important_as_error) {
Expand Down Expand Up @@ -1812,6 +1813,39 @@ class Shardus extends EventEmitter {
return true
}

isNodeReadyByPubKey(pubKey: string): boolean {
const node = this.p2p.state.getNodeByPubKey(pubKey)
if (node == null) {
return false
}
if (node.status !== NodeStatus.READY) {
return false
}
return true
}

isNodeSyncingByPubKey(pubKey: string): boolean {
const node = this.p2p.state.getNodeByPubKey(pubKey)
if (node == null) {
return false
}
if (node.status !== NodeStatus.SYNCING) {
return false
}
return true
}

isNodeSelectedByPubKey(pubKey: string): boolean {
const node = this.p2p.state.getNodeByPubKey(pubKey)
if (node == null) {
return false
}
if (node.status !== NodeStatus.SELECTED) {
return false
}
return true
}

isNodeActive(id: string): boolean {
const node = this.p2p.state.getNode(id)
if (node == null) {
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 @@ -947,6 +947,7 @@ export interface ServerConfiguration {
// /** The number of network transactions to try to process per cycle from txAdd in cycle record */
networkTransactionsToProcessPerCycle: number
useAjvCycleRecordValidation: boolean
getTxTimestampTimeoutOffset?: number // default timeout is 5 seconds so this can be used to add or subtract time from that
}
/** Server IP configuration */
ip?: {
Expand Down
Loading

0 comments on commit c8c53c2

Please sign in to comment.