Skip to content

fix(nano): allow create token and withdraw on same tx#1454

Merged
msbrogli merged 1 commit intomasterfrom
fix/create-withdraw-same-tx
Oct 9, 2025
Merged

fix(nano): allow create token and withdraw on same tx#1454
msbrogli merged 1 commit intomasterfrom
fix/create-withdraw-same-tx

Conversation

@msbrogli
Copy link
Member

@msbrogli msbrogli commented Oct 9, 2025

Motivation

There's a bug in the token index, where an assertion fails when we try to withdraw a nonexistent token. This PR solves this problem by adding support to unknown tokens to the TokenIndex. So all transactions keep being added to the index when they are added to the mempool. If a token does not exist, an unknown token is kept in the index to keep track of the supply and authorities. When the token is created, its information is added to the index too. If the token is never created, this unknown token entry will remain orphan in the index.

Root cause analysis

  1. What's happening?

When adding a nano tx with a withdrawal action and an output of an unknown token is failing, it fails an assert in the token index, therefore causing the full node to crash.

  1. Why?

Because the nano tx passes all verifications, leading to an update in the token index as the nano tx is added to the mempool. However, this index update assumes that the token already exists.

This assumption held true before we allowed contracts to dynamically create tokens. But now, it might happen that tokens do not exist when transactions reach mempool. It is actually impossible to know beforehand whether a token will exist or not after the execution.

  1. Why?

The nano tx passes all verifications because we check that sum(txin) + sum(withdrawals) == sum(txout) + sum(deposits) which is true because the withdrawal of the unknown token balances out the output.

Acceptance Criteria

  • Add a test demonstrating the bug.
  • Refactor: Change _InfoDict type from a typed dict to a dataclass.
  • Add support to unknown tokens to RocksDBTokenIndex.
  • Skip unknown tokens on get_token_info() and iter_all_tokens().
  • Add support for TKN.token_id to the DAG Builder to skip token creation.

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 requested a review from jansegre as a code owner October 9, 2025 18:41
@msbrogli msbrogli requested a review from glevco October 9, 2025 18:42
@msbrogli msbrogli self-assigned this Oct 9, 2025
@msbrogli msbrogli moved this from Todo to In Progress (WIP) in Hathor Network Oct 9, 2025
@msbrogli msbrogli moved this from In Progress (WIP) to In Progress (Done) in Hathor Network Oct 9, 2025
@github-project-automation github-project-automation bot moved this from In Progress (Done) to In Review (WIP) in Hathor Network Oct 9, 2025
@msbrogli msbrogli merged commit b80896c into master Oct 9, 2025
6 of 7 checks passed
@msbrogli msbrogli deleted the fix/create-withdraw-same-tx branch October 9, 2025 18:45
@github-project-automation github-project-automation bot moved this from In Review (WIP) to Waiting to be deployed in Hathor Network Oct 9, 2025
@github-actions
Copy link

github-actions bot commented Oct 9, 2025

🐰 Bencher Report

Branchfix/create-withdraw-same-tx
Testbedubuntu-22.04

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencyminutes (m)
sync-v2 (up to 20000 blocks)📈 view plot
⚠️ NO THRESHOLD
1.95 m
🐰 View full continuous benchmarking report in Bencher

@jansegre jansegre mentioned this pull request Oct 9, 2025
2 tasks
@jansegre jansegre moved this from Waiting to be deployed to Done in Hathor Network Oct 15, 2025
@jansegre jansegre mentioned this pull request Oct 16, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants