Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core-transaction-pool): Switch expiration to chain height #2461

Merged
merged 25 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
525f165
feat(core-transaction-pool): Switch expiration to chain height
vasild Apr 23, 2019
e61fa9f
fix(core-transaction-pool): properly get the current chain height
vasild Apr 23, 2019
2b76687
Merge branch 'develop' into transaction-expiration-in-height
faustbrian Apr 24, 2019
f6df72c
Merge branch 'develop' into transaction-expiration-in-height
faustbrian Apr 24, 2019
8186c8a
Update __tests__/unit/core-transaction-pool/connection.test.ts
faustbrian Apr 24, 2019
da79b1c
Update __tests__/unit/core-transaction-pool/connection.test.ts
faustbrian Apr 24, 2019
4675364
Update __tests__/unit/core-transaction-pool/connection.test.ts
faustbrian Apr 24, 2019
086aa30
Update packages/core-transaction-pool/src/memory.ts
faustbrian Apr 24, 2019
6c10fe5
chore(core-transaction-pool): rename MemoryTransaction
vasild Apr 24, 2019
9794070
chore(core-transaction-pool): get current height from "blockchain"
vasild Apr 24, 2019
4d1e25c
chore(core-transaction-pool): remove unused variable
vasild Apr 24, 2019
1e58fe3
Merge branch 'develop' into transaction-expiration-in-height
faustbrian Apr 24, 2019
0167421
fix(core-transaction-pool): get current height in a more robust way
vasild Apr 24, 2019
fb8631b
chore(core-transaction-pool): remove unreachable code
vasild Apr 24, 2019
31c0835
test(core-transaction-pool): disable tx exiration test
vasild Apr 24, 2019
dd58504
Merge remote-tracking branch 'ArkEcosystem/core/develop' into transac…
vasild Apr 25, 2019
fd1c4ec
chore(core-transaction-pool): only use app.has if it is available
vasild Apr 25, 2019
de89d7a
fix(core-transaction-pool): handle undefined "expiration"
vasild Apr 25, 2019
68334f7
Merge remote-tracking branch 'ArkEcosystem/core/develop' into transac…
vasild Apr 25, 2019
00b0a22
tests(core-transaction-pool): fix a disabled test by proper mocking
vasild Apr 25, 2019
21845ee
Merge remote-tracking branch 'ArkEcosystem/core/develop' into transac…
vasild Apr 25, 2019
e5581c8
tests(core-transaction-pool): adjust after a4567cd26
vasild Apr 25, 2019
a2b52a0
chore(core-transaction-pool): simplify, now that we have the last block
vasild Apr 25, 2019
541c2e6
Merge remote-tracking branch 'ArkEcosystem/core/develop' into transac…
vasild Apr 26, 2019
156cd28
Merge branch 'develop' into transaction-expiration-in-height
faustbrian Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-transaction-pool/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class Connection implements TransactionPool.IConnection {
}

private purgeExpired() {
for (const transaction of this.memory.getExpired()) {
for (const transaction of this.memory.getExpired(this.options.maxTransactionAge)) {
this.emitter.emit("transaction.expired", transaction.data);

this.walletManager.revertTransactionForSender(transaction);
Expand Down
45 changes: 37 additions & 8 deletions packages/core-transaction-pool/src/memory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { app } from "@arkecosystem/core-container";
import { Enums, Interfaces, Utils } from "@arkecosystem/crypto";
import assert from "assert";
import { Blockchain } from "@arkecosystem/core-interfaces";
import { Enums, Interfaces, Utils } from "@arkecosystem/crypto";
import { SequentialTransaction } from "./sequential-transaction";
import { app } from "@arkecosystem/core-container";

export class Memory {
private sequence: number = 0;
Expand Down Expand Up @@ -56,16 +57,27 @@ export class Memory {
return this.all;
}

public getExpired(): Interfaces.ITransaction[] {
public getExpired(maxTransactionAge: number): Interfaces.ITransaction[] {
const currentHeight: number = this.currentHeight();

if (currentHeight === null) {
return [];
}

if (!this.byExpirationIsSorted) {
this.byExpiration.sort((a, b) => a.transaction.data.expiration - b.transaction.data.expiration);
this.byExpirationIsSorted = true;
}

const currentHeight: number = app.resolve("blockchain").getLastHeight();
const transactions: Interfaces.ITransaction[] = [];

for (const SequentialTransaction of this.byExpiration) {
if (SequentialTransaction.transaction.data.expiration === 0) {
SequentialTransaction.transaction.data.expiration = currentHeight + maxTransactionAge;
this.byExpirationIsSorted = false;
continue;
}

if (SequentialTransaction.transaction.data.expiration > currentHeight) {
break;
}
Expand Down Expand Up @@ -147,11 +159,16 @@ export class Memory {
}

if (type !== Enums.TransactionTypes.TimelockTransfer) {
const maxHeight: number = app.resolve("blockchain").getLastHeight() + maxTransactionAge;
if (SequentialTransaction.transaction.data.expiration === 0 ||
SequentialTransaction.transaction.data.expiration > maxHeight) {
const currentHeight: number = this.currentHeight();
if (currentHeight !== null) {
const maxHeight: number = currentHeight + maxTransactionAge;
if (SequentialTransaction.transaction.data.expiration === 0 ||
SequentialTransaction.transaction.data.expiration > maxHeight) {

SequentialTransaction.transaction.data.expiration = maxHeight;
SequentialTransaction.transaction.data.expiration = maxHeight;
}
} else {
SequentialTransaction.transaction.data.expiration = 0;
}
this.byExpiration.push(SequentialTransaction);
this.byExpirationIsSorted = false;
Expand Down Expand Up @@ -256,4 +273,16 @@ export class Memory {

return removed;
}

private currentHeight(): number {
vasild marked this conversation as resolved.
Show resolved Hide resolved
if (app.has("state")) {
return app.resolve("state").getLastBlock().data.height;
}

if (app.has("blockchain")) {
vasild marked this conversation as resolved.
Show resolved Hide resolved
return app.resolvePlugin<Blockchain.IBlockchain>("blockchain").getLastHeight();
}

return null;
}
}