Skip to content

feat(nano): Add address balance in global state#1431

Open
msbrogli wants to merge 1 commit intomasterfrom
feat/nano-address-balance
Open

feat(nano): Add address balance in global state#1431
msbrogli wants to merge 1 commit intomasterfrom
feat/nano-address-balance

Conversation

@msbrogli
Copy link
Member

Motivation

What was the motivation for the changes in this PR?

Acceptance Criteria

  • Include here all things that this PR should solve

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

@msbrogli msbrogli self-assigned this Sep 25, 2025
@msbrogli msbrogli moved this from Todo to In Progress (WIP) in Hathor Network Sep 25, 2025
@github-actions
Copy link

github-actions bot commented Sep 25, 2025

🐰 Bencher Report

Branchfeat/nano-address-balance
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.66 m
(-2.73%)Baseline: 1.71 m
1.54 m
(92.53%)
2.05 m
(81.06%)
🐰 View full continuous benchmarking report in Bencher

@msbrogli msbrogli force-pushed the feat/nano-address-balance branch 13 times, most recently from 8899037 to c63ed89 Compare October 2, 2025 16:50
@jansegre jansegre assigned jansegre and unassigned msbrogli Oct 24, 2025
@jansegre jansegre force-pushed the feat/nano-address-balance branch from c63ed89 to 67993eb Compare October 24, 2025 14:57
@jansegre jansegre force-pushed the feat/nano-address-balance branch from 67993eb to d99ce6c Compare February 10, 2026 16:33
@jansegre jansegre marked this pull request as ready for review February 10, 2026 16:33
@jansegre jansegre self-requested a review as a code owner February 10, 2026 16:33
@msbrogli msbrogli force-pushed the master branch 2 times, most recently from eb416fa to 21d7909 Compare February 12, 2026 23:12
@jansegre jansegre force-pushed the feat/nano-address-balance branch from d99ce6c to 572f68d Compare February 18, 2026 16:38
@jansegre jansegre moved this from In Progress (WIP) to In Progress (Done) in Hathor Network Feb 18, 2026
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 74.54545% with 84 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.66%. Comparing base (a98679e) to head (572f68d).

Files with missing lines Patch % Lines
hathor/verification/transfer_header_verifier.py 54.41% 23 Missing and 8 partials ⚠️
hathor/transaction/transaction.py 42.85% 15 Missing and 1 partial ⚠️
hathor/consensus/consensus.py 11.11% 7 Missing and 1 partial ⚠️
hathor/dag_builder/vertex_exporter.py 84.09% 5 Missing and 2 partials ⚠️
hathor/nanocontracts/runner/runner.py 40.00% 3 Missing and 3 partials ⚠️
hathor/transaction/headers/transfer_header.py 92.50% 3 Missing and 3 partials ⚠️
hathor/dag_builder/builder.py 75.00% 2 Missing and 2 partials ⚠️
hathor/verification/verification_service.py 71.42% 1 Missing and 1 partial ⚠️
hathor/verification/vertex_verifier.py 33.33% 1 Missing and 1 partial ⚠️
hathor/transaction/base_transaction.py 50.00% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1431      +/-   ##
==========================================
- Coverage   85.68%   85.66%   -0.02%     
==========================================
  Files         442      444       +2     
  Lines       33846    34155     +309     
  Branches     5293     5347      +54     
==========================================
+ Hits        29000    29260     +260     
- Misses       3824     3859      +35     
- Partials     1022     1036      +14     
Flag Coverage Δ
test-lib 85.66% <74.54%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

# XXX Should we fail?
return

# XXX Should we check for the size to prevent miscalling with a contract id?
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Transfer to contracts should be made exclusively by deposits.

raise NanoContractDoesNotExist(contract_id.hex())
token_proxy = TokenProxy(self)
return NCContractStorage(trie=trie, nc_id=contract_id, token_proxy=token_proxy)
block_proxy = TokenProxy(self)
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe rename TokenProxy to RestrictedBlockProxy?

@@ -51,3 +51,6 @@ def create_token(
token_symbol=token_symbol,
token_version=token_version
)

def add_address_balance(self, address: Address, amount: Amount, token_id: TokenUid) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

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

Missing docstring.

return Amount(balance)

def add_address_balance(self, address: Address, amount: Amount, token_id: TokenUid) -> None:
key = AddressBalanceKey(address, token_id)
Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't we assert that address is an actual address (never a contract id)?

fees=fees or (),
)

def transfer_to_address(self, address: Address, amount: Amount) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

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

What about the token id?

raise TooManySigOps(f'sigops count greater than max: {sigops_count} > {MAX_SCRIPT_SIGOPS_COUNT}')

try:
raw_script_eval(
Copy link
Member Author

Choose a reason for hiding this comment

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

Make sure it works properly for P2SH.

Comment on lines +57 to +58
tx2.nc_transfer_input = 10 HTR main
tx2.nc_transfer_output = 10 HTR main
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we allow an input and an output of the same token? I guess not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just checked the verifier and it is not allowed. How's this test passing? Are they using different addresses?

Copy link
Member Author

Choose a reason for hiding this comment

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

Missing test adding to the mempool with an output greater than the available balance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Missing test where the execution with transfer headers is successful. Actually, at least three tests, one with transfer headers, another with a contract transfer, and, finally, another with transfer headers and contract transfer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Missing test where the execution fails (but not because of the transfer). In this case, the transfer should not be persisted. Another test where the execution fails because of the transfer (low balance). In this case, the transfer should be persisted as well.

@jansegre jansegre moved this from In Progress (Done) to In Review (WIP) in Hathor Network Feb 19, 2026
Co-authored-by: Jan Segre <jan@hathor.network>
@jansegre jansegre force-pushed the feat/nano-address-balance branch from 572f68d to 7f00f0f Compare February 27, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review (WIP)

Development

Successfully merging this pull request may close these issues.

2 participants