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

[rosetta] Fix staking balances #15247

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Conversation

gregnazario
Copy link
Contributor

@gregnazario gregnazario commented Nov 9, 2024

Description

This cleans up and ensures that Rosetta only returns either the base account balances, the staking balances, or the delegated staking balances. It will never return all three at the same time.

How Has This Been Tested?

Tested against existing accounts on mainnet with a local version. Prior version would return the account's balance and stake together, when requesting stake.

Now it only returns the balance

curl -s -X POST http://localhost:8082/account/balance -H 'Content-Type: application/json' -d '{ "network_identifier": { "blockchain": "aptos", "network": "mainnet" }, "account_identifier": { "address": "75d9ef170a1e8c4215084da639d626d75dfd8a6405e91928261160ed66aa748e", "sub_account": {"address":"stake" }}, "metadata": {} }' | jq
{
  "block_identifier": {
    "index": 249813200,
    "hash": "mainnet-249813200"
  },
  "balances": [
    {
      "value": "888062873502462",
      "currency": {
        "symbol": "APT",
        "decimals": 8,
        "metadata": {
          "move_type": "0x1::aptos_coin::AptosCoin"
        }
      }
    }
  ],
  "metadata": {
    "sequence_number": "50",
    "operators": [
      "e6a5cbbb9754a54af17909352ba96d2b46b379037a4bc94f6530596aaf5f2a13"
    ],
    "lockup_expiration_time_utc": "1731575845"
  }
}

Key Areas to Review

Logically, this should be the same as before. The main issue was the fallthrough behavior that would handle the base account path on every path. Instead it should only be handled on the base path, where staking should do the staking path.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (Rosetta)

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Copy link

trunk-io bot commented Nov 9, 2024

⏱️ 2h 3m total CI duration on this PR
Slowest 15 Jobs Cumulative Duration Recent Runs
rust-smoke-tests 27m 🟩
test-target-determinator 14m 🟩🟩🟩
execution-performance / test-target-determinator 13m 🟩🟩🟩
check 11m 🟩🟩🟩
fetch-last-released-docker-image-tag 10m 🟩🟩🟩
rust-cargo-deny 8m 🟩🟩🟩🟩
check-dynamic-deps 6m 🟩🟩🟩🟩
rust-targeted-unit-tests 6m 🟩
rust-doc-tests 5m 🟩
rust-doc-tests 5m 🟩
rust-lints 4m 🟩
rust-build-cached-packages 2m 🟩
rust-check-merge-base 2m 🟩
general-lints 2m 🟩🟩🟩🟩
rust-move-tests 2m 🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

@gregnazario gregnazario mentioned this pull request Nov 9, 2024
22 tasks
@gregnazario gregnazario enabled auto-merge (squash) November 9, 2024 01:42

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@GhostWalker562 GhostWalker562 left a comment

Choose a reason for hiding this comment

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

Looks good, the only logical change I see is the if statements for base, pool staking, and account staking as stated in the description.

Ok(Some(balance_result)) => {
if let Some(balance) = balance_result.balance {
has_staking = true;
total_balance += u64::from_str(&balance.value).unwrap_or_default();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, this isn't a u128?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User balance is a u64, but I can just change them all to u128 since they're being converted to and from strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually nevermind it will always be a u64

the last refactor made it get staking balances and the account's balance

this should fix it so it never cross contaminates between staking, delegated
staking, and normal balances.  It's much more straightforward and should be
easier to understand.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

✅ Forge suite realistic_env_max_load success on d69cd07e324a95974bfdb83787f55c4952fd59f0

two traffics test: inner traffic : committed: 14588.98 txn/s, latency: 2725.49 ms, (p50: 2700 ms, p70: 2700, p90: 2700 ms, p99: 4800 ms), latency samples: 5547120
two traffics test : committed: 99.94 txn/s, latency: 1763.01 ms, (p50: 1300 ms, p70: 1400, p90: 1500 ms, p99: 16900 ms), latency samples: 1700
Latency breakdown for phase 0: ["MempoolToBlockCreation: max: 1.779, avg: 1.484", "ConsensusProposalToOrdered: max: 0.326, avg: 0.291", "ConsensusOrderedToCommit: max: 0.365, avg: 0.353", "ConsensusProposalToCommit: max: 0.655, avg: 0.644"]
Max non-epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 0.85s no progress at version 2249615 (avg 0.20s) [limit 15].
Max epoch-change gap was: 0 rounds at version 0 (avg 0.00) [limit 4], 8.71s no progress at version 2249613 (avg 8.71s) [limit 15].
Test Ok

Copy link
Contributor

✅ Forge suite compat success on 58c5c53eaffe680eb2fc4cfbddf05a867fecadb9 ==> d69cd07e324a95974bfdb83787f55c4952fd59f0

Compatibility test results for 58c5c53eaffe680eb2fc4cfbddf05a867fecadb9 ==> d69cd07e324a95974bfdb83787f55c4952fd59f0 (PR)
1. Check liveness of validators at old version: 58c5c53eaffe680eb2fc4cfbddf05a867fecadb9
compatibility::simple-validator-upgrade::liveness-check : committed: 15490.70 txn/s, latency: 1918.19 ms, (p50: 1900 ms, p70: 2100, p90: 2100 ms, p99: 2200 ms), latency samples: 577720
2. Upgrading first Validator to new version: d69cd07e324a95974bfdb83787f55c4952fd59f0
compatibility::simple-validator-upgrade::single-validator-upgrading : committed: 7886.81 txn/s, latency: 3426.81 ms, (p50: 3600 ms, p70: 4000, p90: 4700 ms, p99: 4800 ms), latency samples: 143200
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 7821.20 txn/s, latency: 4055.67 ms, (p50: 4100 ms, p70: 4200, p90: 6200 ms, p99: 6600 ms), latency samples: 258460
3. Upgrading rest of first batch to new version: d69cd07e324a95974bfdb83787f55c4952fd59f0
compatibility::simple-validator-upgrade::half-validator-upgrading : committed: 7978.96 txn/s, latency: 3450.54 ms, (p50: 3400 ms, p70: 4100, p90: 4700 ms, p99: 4900 ms), latency samples: 145180
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 7728.21 txn/s, latency: 4078.24 ms, (p50: 4100 ms, p70: 4200, p90: 6400 ms, p99: 6800 ms), latency samples: 255680
4. upgrading second batch to new version: d69cd07e324a95974bfdb83787f55c4952fd59f0
compatibility::simple-validator-upgrade::rest-validator-upgrading : committed: 12394.82 txn/s, latency: 2200.02 ms, (p50: 2400 ms, p70: 2500, p90: 2700 ms, p99: 2900 ms), latency samples: 213440
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 12097.59 txn/s, latency: 2629.34 ms, (p50: 2500 ms, p70: 2700, p90: 2900 ms, p99: 4300 ms), latency samples: 388660
5. check swarm health
Compatibility test for 58c5c53eaffe680eb2fc4cfbddf05a867fecadb9 ==> d69cd07e324a95974bfdb83787f55c4952fd59f0 passed
Test Ok

@gregnazario gregnazario merged commit 7d6d59c into main Nov 13, 2024
48 of 54 checks passed
@gregnazario gregnazario deleted the pr-rosetta-staking-balances branch November 13, 2024 00:32
github-actions bot pushed a commit that referenced this pull request Nov 13, 2024
the last refactor made it get staking balances and the account's balance

this should fix it so it never cross contaminates between staking, delegated
staking, and normal balances.  It's much more straightforward and should be
easier to understand.

(cherry picked from commit 7d6d59c)
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
aptos-release-v1.23

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants