Skip to content

fix(v16): correct drop_transaction_data to drop every second element#1178

Closed
rishabhvaish wants to merge 1 commit intoEVerest:mainfrom
rishabhvaish:fix/drop-transaction-data-algorithm-1165
Closed

fix(v16): correct drop_transaction_data to drop every second element#1178
rishabhvaish wants to merge 1 commit intoEVerest:mainfrom
rishabhvaish:fix/drop-transaction-data-algorithm-1165

Conversation

@rishabhvaish
Copy link
Copy Markdown

The drop_transaction_data function in v16/utils.cpp was supposed to drop every second MeterValue while keeping the first and last (per OCPP 1.6 Appendix). The implementation iterated forward with erase(), but each removal shifted subsequent indices down, causing the loop to skip elements.

With 5 messages [0, 1, 2, 3, 4] the old code kept [0, 3, 4] (after two while-loop passes) instead of [0, 2, 4] in a single pass. The middle message was lost unnecessarily.

I switched to backward iteration from the highest odd index so that removals never affect the positions of elements still to be processed. Also updated the existing test expectation and added three new test cases covering 6-element, 7-element, and minimum-preservation scenarios.

Fixes EVerest/EVerest#1990

The erase-while-iterating-forward approach skipped elements because
indices shift after each erase(). With 5 messages the algorithm kept
[0, 3, 4] instead of the spec-required [0, 2, 4].

Iterate backwards from the highest odd index so that removals never
affect the positions of elements still to be processed.

Fixes #1165

Signed-off-by: Rishabh Vaish <rishabhvaish.904@gmail.com>
@rishabhvaish rishabhvaish force-pushed the fix/drop-transaction-data-algorithm-1165 branch from 0729487 to 0896eae Compare March 23, 2026 01:29
@Pietfried
Copy link
Copy Markdown
Contributor

Hi @rishabhvaish , this comment also applies here.

@rishabhvaish
Copy link
Copy Markdown
Author

Thanks @Pietfried! Reopened in the monorepo: EVerest/EVerest#2003

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.

1.6 drop_transaction_data algorithm seems incorrect

2 participants