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

Ledger: Correct off by one logic in txTail.recent trim loop #4615

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlgoAxel
Copy link
Contributor

Summary

What

This change modifies the loop condition for trimming txTail's recent list during comittedUpTo calls.

Why

It was pointed out that the equality check used was avoiding deletion of one entry, leaving 1001 entries in the list. The expectation is that only 1000 entries would remain after being trimmed.

How

I duplicated the loop which handles deletion, and added a consensus flag to control which version is used. If consensus is on future, it will use the modified logic, and trim down to 1000 entries. Else, the existing behavior is retained.

Presumably, once this feature is adopted via consensus, we can remove the branched logic and consensus flag.

Test Plan

make generate
make sanity
make test
make integration (still running, but all look good so far)

Unit Test: I added an explicit length check to an existing unit test for txTail, which confirms that the length is correct to the consensus version which is selected.

Additionally: I logged the length of txtail.recent before and after the affected loop, and also logged any deletion actions taken.
Before

before: 1002","name":"","time":"2022-09-28T16:06:16.435378-04:00"}
deleted 24428225","name":"","time":"2022-09-28T16:06:16.435465-04:00"}
after: 1001","name":"","time":"2022-09-28T16:06:16.435492-04:00"}

After

before: 1001","name":"","time":"2022-09-28T16:08:55.860060-04:00"}
deleted 24428270","name":"","time":"2022-09-28T16:08:55.860285-04:00"}
after: 1000","name":"","time":"2022-09-28T16:08:55.860342-04:00"}

@CLAassistant
Copy link

CLAassistant commented Sep 30, 2022

CLA assistant check
All committers have signed the CLA.

@AlgoAxel AlgoAxel changed the title Correct off by one logic in txTail.recent trim loop Ledger: Correct off by one logic in txTail.recent trim loop Sep 30, 2022
@codecov
Copy link

codecov bot commented Sep 30, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b4fecd5) 54.27% compared to head (0a039f2) 54.22%.
Report is 851 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4615      +/-   ##
==========================================
- Coverage   54.27%   54.22%   -0.05%     
==========================================
  Files         402      402              
  Lines       51809    51814       +5     
==========================================
- Hits        28119    28097      -22     
- Misses      21330    21351      +21     
- Partials     2360     2366       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jannotti
Copy link
Contributor

jannotti commented Oct 1, 2022 via email

@AlgoAxel
Copy link
Contributor Author

AlgoAxel commented Oct 3, 2022

Don't we need 1001 now to support block Timestamp opcode?
( @jannotti )

There should be no impact to opcodes, as txTail.recent is a mapping of roundLease structures, which only intersects with the TX Lease functionality, as far as I can tell. I searched for usages of .recent across the package, and only found it this in use by TX Tail for Leases.

@jannotti
Copy link
Contributor

jannotti commented Oct 3, 2022

Don't we need 1001 now to support block Timestamp opcode?
( @jannotti )

There should be no impact to opcodes, as txTail.recent is a mapping of roundLease structures, which only intersects with the TX Lease functionality, as far as I can tell. I searched for usages of .recent across the package, and only found it this in use by TX Tail for Leases.

This sounds right. I thought you were discussing the txtail as a whole. For example, txtail.blockHeaderData needs the extra round. But it seems correct that the leases only need MaxTxnLifetime.

// TXTailRecentsFix modifies the logic of the txtail's comittedUpTo function to address an off-by-one-error
// txtail previously trimmed up to (but not including) round `r + maxlife`. Doing this left 1001 transaction objects after trimming.
// the intention is to have only 1000 items after trim, so the logic is modified to trim *including* round `r + maxlife`
TXTailRecentsFix bool
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this change will have an impact on the consensus. This is an extra element which is sitting and taking up space that nobody depends on. Therefore, TXTailRecentFix is not needed.
@algorandskiy do you agree?
Otherwise, will be nice to describe how this is impacting the consensus.

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 idea is that if there are different behaviors of TX Tail, transactions would be distributed by some nodes, and discarded by other nodes, since they wouldn't agree on if the lease was still valid on that 1000/1001 threshold. It was originally a discussion with Pavel that prompted this feature flag, but I'll leave it to him for the deeper answer.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need a test to demonstrate this disagreement. I don't think we have one now. At least not a unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could be part of why @algorandskiy had suggested the Protocol flag in the first place -- by enforcing the recents length at the protocol level, there is no concern that peers will disagree, so no test would be needed on that (right?).

@jsgranados jsgranados self-assigned this May 23, 2023
@AlgoAxel AlgoAxel marked this pull request as draft May 23, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants