Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
♻️ Fix minor type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuGowda committed May 5, 2020
1 parent 56484e2 commit 8059dc5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion elements/lisk-transaction-pool/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface TransactionObject {
signatures?: ReadonlyArray<string>;
readonly type: number;
verifiedOnce?: boolean;
feePriority: bigint;
feePriority?: bigint;
}

export interface TransactionFunctions {
Expand Down
3 changes: 2 additions & 1 deletion framework/src/application/node/forger/forger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export class Forger {
keypair.publicKey.toString('hex'),
]);

if (account.isDelegate) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (account?.isDelegate) {
if (forging) {
this.keypairs[
getAddressFromPublicKey(keypair.publicKey.toString('hex'))
Expand Down
23 changes: 15 additions & 8 deletions framework/src/application/node/forger/strategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
*/

import { MaxHeap, TransactionPool } from '@liskhq/lisk-transaction-pool';
import { Status as TransactionStatus, BaseTransaction } from '@liskhq/lisk-transactions';
import {
Status as TransactionStatus,
BaseTransaction,
} from '@liskhq/lisk-transactions';
import { Chain } from '@liskhq/lisk-chain';

export class HighFeeForgingStrategy {
private readonly chainModule: Chain;
private readonly transactionPoolModule: TransactionPool;
private readonly constants: {
readonly maxPayloadLength: number
readonly maxPayloadLength: number;
};

public constructor({
Expand All @@ -30,9 +33,9 @@ export class HighFeeForgingStrategy {
// constants
maxPayloadLength,
}: {
readonly chainModule: Chain,
readonly transactionPoolModule: TransactionPool,
readonly maxPayloadLength: number
readonly chainModule: Chain;
readonly transactionPoolModule: TransactionPool;
readonly maxPayloadLength: number;
}) {
this.chainModule = chainModule;
this.transactionPoolModule = transactionPoolModule;
Expand All @@ -55,13 +58,17 @@ export class HighFeeForgingStrategy {
const feePriorityHeap = new MaxHeap();
for (const senderId of Object.keys(transactionsBySender)) {
const lowestNonceTrx = transactionsBySender[senderId][0];
feePriorityHeap.push(lowestNonceTrx.feePriority, lowestNonceTrx);
feePriorityHeap.push(
lowestNonceTrx.feePriority as bigint,
lowestNonceTrx,
);
}

// Loop till we have last account exhausted to pick transactions
while (Object.keys(transactionsBySender).length !== 0) {
// Get the transaction with highest fee and lowest nonce
const lowestNonceHighestFeeTrx = (feePriorityHeap.pop()?.value) as BaseTransaction;
const lowestNonceHighestFeeTrx = feePriorityHeap.pop()
?.value as BaseTransaction;
// Try to process transaction
const result = await this.chainModule.applyTransactionsWithStateStore(
[lowestNonceHighestFeeTrx],
Expand Down Expand Up @@ -115,7 +122,7 @@ export class HighFeeForgingStrategy {
const nextLowestNonceTransaction =
transactionsBySender[lowestNonceHighestFeeTrx.senderId][0];
feePriorityHeap.push(
nextLowestNonceTransaction.feePriority,
nextLowestNonceTransaction.feePriority as bigint,
nextLowestNonceTransaction,
);
}
Expand Down

0 comments on commit 8059dc5

Please sign in to comment.