Skip to content

Commit

Permalink
Check block age
Browse files Browse the repository at this point in the history
  • Loading branch information
faberto committed Jan 30, 2024
1 parent 33cd5fd commit e5a8714
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions backend/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,14 @@ export async function getTransaction(transactionHash: string) {
await client.transaction.getByHash(transactionHash);
return tx.data;
}

/**
* Get the current block height
* @returns block height
*/
export async function getBlockHeight() {
const client = getClient();
const blockHeight: CallResult<number> =
await client.blockchain.getBlockNumber();
return blockHeight.data;
}
8 changes: 8 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
STAKING_CONTRACT_ADDRESS,
convertAddressForRPC,
getBlockHeight,
getPaymentStatus,
getTotalRewards,
getTransaction,
Expand Down Expand Up @@ -158,6 +159,13 @@ async function checkTransaction(
);
return false;
} else {
const blockHeight = await getBlockHeight();
if (blockHeight - transaction.blockNumber > 180) {
console.log(
`Transaction ${transactionHash} too old. Supposed to be for ${validatorWalletAddress}`,
);
return false;
}
if (
convertAddressForRPC(transaction.from) !==
convertAddressForRPC(validatorWalletAddress)
Expand Down
2 changes: 0 additions & 2 deletions backend/src/nodecontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ export async function removeValidator(address: string) {
for (const spec of specs) {
try {
// delete if exists

await client.read(spec);

const response = await client.delete(spec);
console.log(response);
} catch (e) {
Expand Down

0 comments on commit e5a8714

Please sign in to comment.