-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core-transaction-pool): add type, interfaces and sort out st…
…ructural issues
- Loading branch information
1 parent
c497f93
commit ea79251
Showing
38 changed files
with
1,443 additions
and
1,892 deletions.
There are no files selected for viewing
604 changes: 565 additions & 39 deletions
604
...ation/core-transaction-pool/guard.test.ts → ...n/core-transaction-pool/processor.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
__tests__/unit/core-transaction-pool/mem-pool-transaction.test.ts
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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { Enums, Interfaces } from "@arkecosystem/crypto"; | ||
import { MemPoolTransaction } from "../../../packages/core-transaction-pool/src/mem-pool-transaction"; | ||
import { MemPoolTransaction } from "../../../packages/core-transaction-pool/src/pool-transaction"; | ||
import { transactions } from "./__fixtures__/transactions"; | ||
|
||
describe("MemPoolTransaction", () => { | ||
describe("expireAt", () => { | ||
describe("expiresAt", () => { | ||
it("should return transaction expiration when it is set", () => { | ||
const transaction: Interfaces.ITransaction = transactions.dummy1; | ||
transaction.data.expiration = 1123; | ||
const memPoolTransaction = new MemPoolTransaction(transaction); | ||
expect(memPoolTransaction.expireAt(1)).toBe(1123); | ||
expect(memPoolTransaction.expiresAt(1)).toBe(1123); | ||
}); | ||
|
||
it("should return timestamp + maxTransactionAge when expiration is not set", () => { | ||
const transaction: Interfaces.ITransaction = transactions.dummy2; | ||
transaction.data.timestamp = 344; | ||
const memPoolTransaction = new MemPoolTransaction(transaction); | ||
expect(memPoolTransaction.expireAt(131)).toBe(transaction.data.timestamp + 131); | ||
expect(memPoolTransaction.expiresAt(131)).toBe(transaction.data.timestamp + 131); | ||
}); | ||
|
||
it("should return null for timelock transfer with no expiration set", () => { | ||
const transaction: Interfaces.ITransaction = transactions.dummy3; | ||
transaction.data.type = Enums.TransactionTypes.TimelockTransfer; | ||
const memPoolTransaction = new MemPoolTransaction(transaction); | ||
expect(memPoolTransaction.expireAt(1)).toBe(null); | ||
expect(memPoolTransaction.expiresAt(1)).toBe(null); | ||
}); | ||
}); | ||
}); |
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
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
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
172 changes: 18 additions & 154 deletions
172
packages/core-interfaces/src/core-transaction-pool/connection.ts
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 |
---|---|---|
@@ -1,180 +1,44 @@ | ||
import { Enums, Interfaces } from "@arkecosystem/crypto"; | ||
import { Dato } from "@faustbrian/dato"; | ||
import { IProcessor } from "./processor"; | ||
|
||
export interface IAddTransactionResponse { | ||
success: boolean; | ||
} | ||
|
||
export interface IAddTransactionErrorResponse extends IAddTransactionResponse { | ||
transaction: Interfaces.ITransaction; | ||
type: string; | ||
message: string; | ||
success: boolean; | ||
transaction?: Interfaces.ITransaction; | ||
type?: string; | ||
message?: string; | ||
} | ||
|
||
export interface IConnection { | ||
options: any; | ||
loggedAllowedSenders: string[]; | ||
walletManager: any; | ||
makeProcessor(): IProcessor; | ||
|
||
make(): Promise<this>; | ||
|
||
/** | ||
* Get a driver instance. | ||
*/ | ||
driver(): () => any; | ||
|
||
/** | ||
* Disconnect from transaction pool. | ||
* @return {void} | ||
*/ | ||
disconnect(): void; | ||
|
||
/** | ||
* Get the number of transactions in the pool. | ||
*/ | ||
getPoolSize(): number; | ||
|
||
/** | ||
* Get the number of transactions in the pool from a specific sender\ | ||
*/ | ||
getSenderSize(senderPublicKey: string): number; | ||
|
||
/** | ||
* Add many transactions to the pool. | ||
* @param {Array} transactions, already transformed and verified | ||
* by transaction guard - must have serialized field | ||
* @return {Object} like | ||
* { | ||
* added: [ ... successfully added transactions ... ], | ||
* notAdded: [ { transaction: Transaction, type: String, message: String }, ... ] | ||
* } | ||
*/ | ||
addTransactions( | ||
transactions: Interfaces.ITransaction[], | ||
): { | ||
added: Interfaces.ITransaction[]; | ||
notAdded: IAddTransactionErrorResponse[]; | ||
notAdded: IAddTransactionResponse[]; | ||
}; | ||
|
||
/** | ||
* Add a transaction to the pool. | ||
*/ | ||
addTransaction(transaction: Interfaces.ITransaction): IAddTransactionResponse; | ||
|
||
/** | ||
* Remove a transaction from the pool by transaction object. | ||
* @param {Transaction} transaction | ||
* @return {void} | ||
*/ | ||
removeTransaction(transaction: Interfaces.ITransaction): void; | ||
|
||
/** | ||
* Remove a transaction from the pool by id. | ||
*/ | ||
removeTransactionById(id: string, senderPublicKey?: string): void; | ||
|
||
/** | ||
* Get all transactions that are ready to be forged. | ||
*/ | ||
getTransactionsForForging(blockSize: number): string[]; | ||
|
||
/** | ||
* Get a transaction by transaction id. | ||
*/ | ||
acceptChainedBlock(block: Interfaces.IBlock): void; | ||
blockSender(senderPublicKey: string): Dato; | ||
buildWallets(): Promise<void>; | ||
flush(): void; | ||
getTransaction(id: string): Interfaces.ITransaction; | ||
|
||
/** | ||
* Get all transactions within the specified range [start, start + size), ordered by fee. | ||
* @return {(Array|void)} array of serialized transaction hex strings | ||
*/ | ||
getTransactions(start: number, size: number, maxBytes?: number): Buffer[]; | ||
|
||
/** | ||
* Get all transactions within the specified range [start, start + size). | ||
* @return {Array} array of transactions IDs in the specified range | ||
*/ | ||
getTransactionIdsForForging(start: number, size: number): string[]; | ||
|
||
/** | ||
* Get data from all transactions within the specified range [start, start + size). | ||
* Transactions are ordered by fee (highest fee first) or by | ||
* insertion time, if fees equal (earliest transaction first). | ||
* @return {Array} array of transaction[property] | ||
*/ | ||
getTransactionsData(start: number, size: number, property: string, maxBytes?: number): string[] | Buffer[]; | ||
|
||
/** | ||
* Get all transactions of a given type from the pool. | ||
*/ | ||
getTransactions(start: number, size: number, maxBytes?: number): Buffer[]; | ||
getTransactionsByType(type: any): any; | ||
|
||
/** | ||
* Remove all transactions from the transaction pool belonging to specific sender. | ||
*/ | ||
removeTransactionsForSender(senderPublicKey: string): void; | ||
|
||
/** | ||
* Check whether sender of transaction has exceeded max transactions in queue. | ||
*/ | ||
getTransactionsData<T>(start: number, size: number, property: string, maxBytes?: number): T[]; | ||
getTransactionsForForging(blockSize: number): string[]; | ||
has(transactionId: string): any; | ||
hasExceededMaxTransactions(transaction: Interfaces.ITransactionData): boolean; | ||
|
||
/** | ||
* Flush the pool (delete all transactions from it). | ||
*/ | ||
flush(): void; | ||
|
||
/** | ||
* Checks if a transaction exists in the pool. | ||
*/ | ||
transactionExists(transactionId: string): any; | ||
|
||
/** | ||
* Check if transaction sender is blocked | ||
* @return {Boolean} | ||
*/ | ||
isSenderBlocked(senderPublicKey: string): boolean; | ||
|
||
/** | ||
* Blocks sender for a specified time | ||
*/ | ||
blockSender(senderPublicKey: string): Dato; | ||
|
||
/** | ||
* Processes recently accepted block by the blockchain. | ||
* It removes block transaction from the pool and adjusts | ||
* pool wallets for non existing transactions. | ||
* | ||
* @param {Object} block | ||
* @return {void} | ||
*/ | ||
acceptChainedBlock(block: Interfaces.IBlock): void; | ||
|
||
/** | ||
* Rebuild pool manager wallets | ||
* Removes all the wallets from pool manager and applies transaction from pool - if any | ||
* It waits for the node to sync, and then check the transactions in pool | ||
* and validates them and apply to the pool manager. | ||
*/ | ||
buildWallets(): Promise<void>; | ||
|
||
purgeByBlock(block: Interfaces.IBlock): void; | ||
purgeByPublicKey(senderPublicKey: string): void; | ||
|
||
/** | ||
* Purges all transactions from senders with at least one | ||
* invalid transaction. | ||
*/ | ||
purgeSendersWithInvalidTransactions(block: Interfaces.IBlock): void; | ||
|
||
/** | ||
* Purges all transactions from the block. | ||
* Purges if transaction exists. It assumes that if trx exists that also wallet exists in pool | ||
*/ | ||
purgeBlock(block: Interfaces.IBlock): void; | ||
|
||
/** | ||
* Check whether a given sender has any transactions of the specified type | ||
* in the pool. | ||
*/ | ||
removeTransaction(transaction: Interfaces.ITransaction): void; | ||
removeTransactionById(id: string, senderPublicKey?: string): void; | ||
removeTransactionsForSender(senderPublicKey: string): void; | ||
senderHasTransactionsOfType(senderPublicKey: string, transactionType: Enums.TransactionTypes): boolean; | ||
} |
Oops, something went wrong.