Skip to content

feat: storage deposit #4035

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

Closed
wants to merge 11 commits into from
Closed

Conversation

piux2
Copy link
Contributor

@piux2 piux2 commented Mar 31, 2025

Solution for : #3418

BREAKING CHANGES

New Message Flag

  • MsgCall and MsgRun now include an optional deposit field to specify how many GNOT the caller is willing to lock for storage.
  • This deposit is used to pay storage changes at the end of each message.
  • The user's balance is deducted or refunded based on actual storage changes.

AddPkg Additional Logic

  • AddPkg now includes:
    • A send flag to send tokens to the realm.
    • A deposit flag to specify how much GNOT to include for storage fees.
  • Previously, the -deposit flag was used in place of -send within AddPkg.
  • The user's balance is deducted or refunded based on actual storage changes.

Purpose

  1. Paying for Storage
    Whenever data is stored in a realm (e.g., via SetObject), an amount of GNOT is locked as a “storage deposit.”

  2. Reclaiming Storage & Deposit
    When stored data is removed, the corresponding deposit is released back to the user.

  3. Encouraging Efficient Storage
    Users must pay to keep data on-chain, incentivizing them to store only what is necessary.

High-Level Design

The system imposes a GNOT deposit for stored data. Each realm tracks its total number of bytes in use and the total tokens locked for that storage. After each message is processed, the net change in storage usage is calculated, and the appropriate amount of GNOT is locked or unlocked. By default, deposit tracking is aggregated per realm rather than per user. Any user refunds or reward mechanisms for freeing storage are determined by the realm.


Usage Tracking

  1. Realm-Level Tracking

    • Storage: The total number of bytes used in this realm.
    • Deposits: The total GNOT locked to pay for the realm’s storage.
  2. Global VM Parameters

    • Storage Price: A rate (in GNOT per byte) defining how much GNOT must be locked per byte stored (e.g., “1 GNOT/KB” or another fraction).
    • Default Deposit: A fallback amount if the user does not specify a custom deposit.
  3. Message-Level Fields

    • Optional Deposit Field (in MsgCall/MsgRun/AddPkg): The user can specify how many GNOT to deposit for potential storage usage.
    • Settlement at Message End: When a message finishes, the net storage change is computed, and tokens are transferred accordingly (locked or refunded).

Deposit & Retrieval Flow

  1. Make a MsgCall / MsgRun / AddPkg Call

    • The user (or contract) sets how many GNOT to allow for extra storage usage.
  2. During Execution

    • The system tracks changes in storage size (growth or shrinkage).
    • If storage grows: GNOT from the deposit buffer is locked into the realm.
    • If storage shrinks: GNOT is unlocked from the realm and refunded to the user.
  3. Anyone Can Free Storage

    • Because deposits are tracked per realm (not per user), anyone can remove data.
    • This can create a “cleanup reward” scenario where the person who deletes data gains the released deposit.
    • It also gives the realm developer flexibility to design and manage user storage.

Tools

  • gnokey query vm/qstorage -data <realm_path>: Shows a realm’s locked tokens and current storage usage.
  • Storage Directive in Tests: A Storage: directive can be added to file tests to display storage usage across realms.

Future Improvements

  • Large Default Deposit: Currently, the default deposit is set to a high number, so below that threshold, users do not need to explicitly specify their own deposit. This is used as a workaround for genesis transactions.
  • High Storage Price: A rate of 1 GNOT per KB can significantly increase the cost of deploying a package.
  • Better User Information: Tools and feedback should be improved to show users how much deposit is being locked or released.
  • The realm subsidizes the storage deposit.
  • More examples to manage the storage deposit and refund.

@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Mar 31, 2025
@piux2 piux2 changed the title storage deposit feat: storage deposit Mar 31, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 31, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: piux2/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Copy link

codecov bot commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/misc.go 0.00% 8 Missing ⚠️
gnovm/pkg/gnolang/values.go 0.00% 2 Missing ⚠️
gnovm/stdlibs/std/crypto.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Kouteki Kouteki moved this from Triage to In Review in 🧙‍♂️gno.land core team Mar 31, 2025
@Kouteki
Copy link
Contributor

Kouteki commented Mar 31, 2025

Closes #3418

@Kouteki Kouteki requested a review from jaekwon March 31, 2025 15:05
@zivkovicmilos zivkovicmilos added this to the 🚀 Mainnet beta launch milestone Apr 1, 2025
@piux2 piux2 requested review from moul and zivkovicmilos April 2, 2025 04:42
Copy link
Contributor

@jaekwon jaekwon left a comment

Choose a reason for hiding this comment

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

Overall direction looks great, just needs some changes. Please call me after changes.

@Kouteki Kouteki requested a review from jaekwon April 24, 2025 12:49
@jaekwon
Copy link
Contributor

jaekwon commented Jun 7, 2025

I'll take a look!

@thehowl
Copy link
Member

thehowl commented Jul 3, 2025

superseded by #4281

@thehowl thehowl closed this Jul 3, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in 💪 Bounties & Worx Jul 3, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in 🧙‍♂️gno.land core team Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants