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

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Apr 23, 2019

Switch from calculating transactions' expiration in "number of seconds
since genesis block" to "chain height".

Notice: this change alters the semantic of the maxTransactionAge beyond
just the units (seconds vs height). Before the change we would use the
user-defined transaction.timestamp and add maxTransactionAge (seconds)
to it. After the change we use the current chain height when we have
received the transaction (which is not user-defined and not necessary
the same as when the transaction was created by the user) and add
maxTransactionAge (height) to it.

Resolves #1060

Summary

What kind of change does this PR introduce?

  • Bugfix
  • New feature
  • Refactoring / Performance Improvements
  • Build-related changes
  • Documentation
  • Tests / Continuous Integration
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Other information

Switch from calculating transactions' expiration in "number of seconds
since genesis block" to "chain height".

Notice: this change alters the semantic of the maxTransactionAge beyond
just the units (seconds vs height). Before the change we would use the
user-defined transaction.timestamp and add maxTransactionAge (seconds)
to it. After the change we use the current chain height when we have
received the transaction (which is not user-defined and not necessary
the same as when the transaction was created by the user) and add
maxTransactionAge (height) to it.

Resolves #1060
@ghost
Copy link

ghost commented Apr 23, 2019

The ci/circleci: test-node10-e2e job is failing as of 21845ee79cfe1c89f0331691453abe84a94adfce. Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@vasild vasild force-pushed the transaction-expiration-in-height branch from 854244a to 537eb5d Compare April 23, 2019 15:40
// Max transaction age in number of blocks produced since receiving a transaction.
// If a transaction stays that long in the pool without being included in any block,
// then it will be removed.
maxTransactionAge: 2700,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to something better so the comment is not needed to understand what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the variable name is fine, any suggestions are welcome though.

It is not possible to condense the information from 3 lines into a variable name. In this case the important information the comment is conveying is:

  • The units of measurement (it is blocks, not seconds)
  • When does the counter start ticking (it is when the transaction has been received, not when it was created like it was before this change)
  • What happens when the time expires.

Please, do not remove the comment.

It is normal to have one or two sentences describing each variable/config parameter, for example:

  -debuglogfile=<file>
       Specify location of debug log file. Relative paths will be prefixed by a
       net-specific datadir location. (-nodebuglogfile to disable;
       default: debug.log)

  -includeconf=<file>
       Specify additional configuration file, relative to the -datadir path
       (only useable from configuration file, not command line)

  -loadblock=<file>
       Imports blocks from external blk000??.dat file on startup

  -maxmempool=<n>
       Keep the transaction memory pool below <n> megabytes (default: 300)

  -maxorphantx=<n>
       Keep at most <n> unconnectable transactions in memory (default: 100)

  -mempoolexpiry=<n>
       Do not keep transactions in the mempool longer than <n> hours (default:
       336)

  -par=<n>
       Set the number of script verification threads (-8 to 16, 0 = auto, <0 =
       leave that many cores free, default: 0)

  -persistmempool
       Whether to save the mempool on shutdown and load on restart (default: 1)

  -prune=<n>
       Reduce storage requirements by enabling pruning (deleting) of old
       blocks. This allows the pruneblockchain RPC to be called to
       delete specific blocks, and enables automatic pruning of old
       blocks if a target size in MiB is provided. This mode is
       incompatible with -txindex and -rescan. Warning: Reverting this
       setting requires re-downloading the entire blockchain. (default:
       0 = disable pruning blocks, 1 = allow manual pruning via RPC,
       >=550 = automatically prune block files to stay under the
       specified target size in MiB)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it not possible to convey that minuscule bit of information in a variable name? All of the following make it pretty clear that it is about lifetime/expiration of the transaction and the unit of measurement is a number of blocks.

  • transactionTtlInBlocks
  • transactionLifetimeInBlocks
  • transactionValidForNumberOfBlocks
  • transactionMaxAgeInBlocks
  • transactionExpiresAfterNumberOfBlocks

packages/core-transaction-pool/src/memory-transaction.ts Outdated Show resolved Hide resolved
* transactions that are without expiration are not included. Used to:
* - find all transactions that have expired (have an expiration height
* lower than the current height) - they are at the beginning of the array.
*/
private byExpiration: MemoryTransaction[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need that long of a comment to understand what an array with the name byExpiration holds? The name is pretty self-explanatory and the code that uses it is also very simple.

If you feel the need to write that long comments, or even comments at all for such trivial things, you should think about why you really need those comments and remove the need for them and figure out how to make the code easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is needed to convey the following information, which cannot be deduced from the name of the variable:

  • The array does not contain all transactions
  • Is it sorted in ascending or descending order

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo the information the comment tries to convey is a bit redundant since it can be quickly deduced by checking the relevant code. I personally would remove the comment, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__tests__/unit/core-transaction-pool/connection.test.ts Outdated Show resolved Hide resolved
__tests__/unit/core-transaction-pool/connection.test.ts Outdated Show resolved Hide resolved
__tests__/unit/core-transaction-pool/connection.test.ts Outdated Show resolved Hide resolved
@ArkEcosystem ArkEcosystem deleted a comment Apr 23, 2019
@vasild vasild force-pushed the transaction-expiration-in-height branch from 537eb5d to e61fa9f Compare April 23, 2019 15:42
@vasild vasild force-pushed the transaction-expiration-in-height branch from 3241b69 to fb8631b Compare April 24, 2019 16:08
The test needs to query the current chain height and then wait until it
increases or fake an increased height.
…tion-expiration-in-height

* ArkEcosystem/core/develop:
  release: 2.3.15 (#2478)
  release: 2.3.14 (#2477)
  refactor(core): remove support for old release channels (#2476)
  fix(crypto): add exceptions for transactions with invalid recipients (#2471)
  refactor(crypto): make all Slots.* methods static (#2473)
  docs(template): add release section to pull request template (#2472)
  chore: fix absolute banner urls (#2469)
…tion-expiration-in-height

* ArkEcosystem/core/develop:
  style: apply linting and formatting to e2e tests (#2480)
@codecov-io
Copy link

codecov-io commented Apr 25, 2019

Codecov Report

Merging #2461 into develop will decrease coverage by 0.02%.
The diff coverage is 89.36%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2461      +/-   ##
===========================================
- Coverage    67.79%   67.76%   -0.03%     
===========================================
  Files          386      386              
  Lines         8396     8399       +3     
  Branches       398      399       +1     
===========================================
  Hits          5692     5692              
- Misses        2652     2655       +3     
  Partials        52       52
Impacted Files Coverage Δ
packages/core-transaction-pool/src/storage.ts 100% <100%> (ø) ⬆️
...ore-transaction-pool/src/sequential-transaction.ts 100% <100%> (ø)
packages/core-transaction-pool/src/connection.ts 95.51% <87.5%> (ø) ⬆️
packages/core-transaction-pool/src/memory.ts 95.87% <88.88%> (-3.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d84842...156cd28. Read the comment docs.

…tion-expiration-in-height

* ArkEcosystem/core/develop:
  feat: add core-state to manage the state of in-memory data (#2479)
packages/core-transaction-pool/src/memory.ts Outdated Show resolved Hide resolved
packages/core-transaction-pool/src/memory.ts Outdated Show resolved Hide resolved
}

return new Set();
}

public remember(MemoryTransaction: MemoryTransaction, maxTransactionAge: number, databaseReady?: boolean): void {
const transaction: Interfaces.ITransaction = MemoryTransaction.transaction;
public remember(SequentialTransaction: SequentialTransaction, maxTransactionAge: number, databaseReady?: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public remember(SequentialTransaction: SequentialTransaction, maxTransactionAge: number, databaseReady?: boolean): void {
public remember(sequentialTransaction: SequentialTransaction, maxTransactionAge: number, databaseReady?: boolean): void {

Variable names should always be in camelCase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You named it MemoryTransaction all over the place, I did not wanted to argue and assumed you wanted it to be with capital letter for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely removed the [sS]equentialTransaction from the code in a followup PR: #2494

…tion-expiration-in-height

* ArkEcosystem/core/develop:
  fix(core): parse only the last line of pm2 stdout (#2484)
  release: 2.3.18 (#2488)
  fix(core-snapshots): reset unfinished round after import (#2486)
  fix(core-forger): update configManager height (#2487)
  release: 2.3.16 (#2483)
  fix(core-database): initialize height on startup (#2482)
@spkjp spkjp self-requested a review April 26, 2019 13:44
@faustbrian faustbrian merged commit 5d48f03 into develop Apr 26, 2019
@ghost ghost deleted the transaction-expiration-in-height branch April 26, 2019 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants