Skip to content

fix(nano): non-idempotent indexes handling #1313

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged

fix(nano): non-idempotent indexes handling #1313

merged 1 commit into from
Jul 10, 2025

Conversation

glevco
Copy link
Contributor

@glevco glevco commented Jul 8, 2025

Motivation

There's a bug in the index handling of nano contracts. There's a method called nc_update_add() in the IndexesManager that updates indexes according to contract's actions and executed syscalls. This method was called in the update() method of that class every time the nano tx was affected by an update in the consensus. Instead, it should be called only once, when the contract executes.

Without this fix, index handling would happen more than once, which is problematic for some syscalls. For example, if a contract creates a token TKA, the amount of TKA is added to the tokens index and the amount of HTR deposit is removed. When the tx is spent, it would be considered a txs_affected in the consensus, causing the index to be updated again. This would drift the index values away from the expected ones, doubling the amount of created TKA and deposited HTR.

Acceptance Criteria

  • Move IndexesManager.nc_update_add call from IndexesManager.update to BlockConsensusAlgorithm._nc_execute_calls.
  • Rename IndexesManager.nc_update_add to handle_contract_execution and nc_update_remove to handle_contract_unexecution.
  • Add a test that fails on master, but passes on this branch.

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@glevco glevco self-assigned this Jul 8, 2025
@glevco glevco requested review from jansegre and msbrogli as code owners July 8, 2025 17:58
@glevco glevco added the bug Something isn't working label Jul 8, 2025
@glevco glevco moved this from Todo to In Progress (WIP) in Hathor Network Jul 8, 2025
Copy link

github-actions bot commented Jul 8, 2025

🐰 Bencher Report

Branchfix/nano/indexes
Testbedubuntu-22.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
minutes (m)
(Result Δ%)
Lower Boundary
minutes (m)
(Limit %)
Upper Boundary
minutes (m)
(Limit %)
sync-v2 (up to 20000 blocks)📈 view plot
🚷 view threshold
1.63 m
(-0.51%)Baseline: 1.64 m
1.47 m
(90.46%)
1.80 m
(90.44%)
🐰 View full continuous benchmarking report in Bencher

Copy link

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.61%. Comparing base (5aa5543) to head (4ce6c0b).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1313      +/-   ##
==========================================
- Coverage   85.62%   85.61%   -0.02%     
==========================================
  Files         426      426              
  Lines       31948    31947       -1     
  Branches     4965     4962       -3     
==========================================
- Hits        27355    27350       -5     
- Misses       3595     3597       +2     
- Partials      998     1000       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@glevco glevco force-pushed the fix/nano/indexes branch 2 times, most recently from 5f6634d to f8c87fc Compare July 8, 2025 19:09
@glevco glevco moved this from In Progress (WIP) to In Progress (Done) in Hathor Network Jul 8, 2025
@glevco glevco force-pushed the fix/nano/indexes branch from f8c87fc to e9e4bda Compare July 8, 2025 19:24
@github-project-automation github-project-automation bot moved this from In Progress (Done) to In Review (WIP) in Hathor Network Jul 8, 2025
@glevco glevco moved this from In Review (WIP) to In Review (Done) in Hathor Network Jul 9, 2025
@glevco glevco force-pushed the fix/nano/indexes branch from e9e4bda to 4ce6c0b Compare July 10, 2025 21:11
@glevco glevco merged commit e417e0e into master Jul 10, 2025
8 checks passed
@glevco glevco deleted the fix/nano/indexes branch July 10, 2025 22:57
@github-project-automation github-project-automation bot moved this from In Review (Done) to Waiting to be deployed in Hathor Network Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Waiting to be deployed
Development

Successfully merging this pull request may close these issues.

3 participants