Repository navigation
Description
Summary
When a moderator's changeDocumentFields changes a property that is part of index keys, for example a mod field in listings keyed [live, mod, …], Drive charges the update as an index delete plus a full re-insert. The moderator pays full storage, added_bytes × 27,000, for every index entry that only moved to another key. The owner is refunded, in the same transition, for the entries that were removed. Nothing left state; the bytes were re-bought, by a different identity.
The genuinely new data in such a change is small, yet a moderator's hide costs many times more. The moderator's real cost should be processing plus the net-new bytes.
Where (v5.0.0-rc.8)
PV14 runs update_document_for_contract_operations v1 (drive_document_method_versions/v4.rs:172), in packages/rs-drive/src/drive/document/update/internal/update_document_for_contract_operations/v1/mod.rs:
- Changed key detected:
:603-610;:613(change_occurred_on_index |= new_takes_part != old_takes_part);:784-791;- array set-diff at
:520-546and:1232.
- Old reference removed with
batch_delete_up_tree_while_emptyat:980-1010. This also prunes subtrees that become empty, refunding their flag owner. - New reference inserted:
- new trees at
:645-651,:829-858and:885-897; - the
[0]tree at:1045-1054; - the reference at
:1058-1080, with the update's flags at:290-294(current payer epoch; owner as described in Drive: moderator ChangeDocumentFields flags new storage with the document owner, so tombstones and unhides refund moderator-paid bytes to the author #5575).
- new trees at
- Who pays: added bytes cost
added_bytes * 27000regardless of flags (fees/op.rs:414), charged to the signer (execute_event/v1/mod.rs:209). - The document item itself is overwritten in place, and replaced bytes cost processing only (
add_document_to_primary_storage/v0/mod.rs:604-626,op.rs:1911-1913). Only the index side is re-bought. - GroveDB's move can't be used here.
GroveOp::Move(grovedbbatch/mod.rs:659-666, rev2128ea18) is same-subtree only and refuses indexed trees and flagged elements whose key length changes (:1640-1679). A lane change is a path change.
Measured (testnet, Drive 5.0.0-rc.8)
Contract and identities as in #5575: social 5Kucw9g9TsiSRXbns2mPumXKVkYW7jwVrTdjFuFhMEwU, moderator 9HX1B7LeHJCcBDnj3B6SWcEZz1SLhz2uRsi89WFXwXvo.
Rates (rs-platform-version/src/version/fee/storage/v1.rs:6-10): 27,000 credits per added storage byte. A same-epoch refund is 26,966.25 per byte; every hide refund divides into whole bytes.
Element sizes:
- A tag, mention or log chain (value tree +
[0]tree + reference) is 582 B. - A timeline or ownerAndTime chain is 648 B.
- The document grows by 42 B per hide:
$moderatedAt8 +$moderatedBy32 +mod1 +modLabel1.
| Hide of | Moderator paid | Net-new bytes (doc +42 B, log entry 582 B) | Re-bought moved entries | Processing | Owner refunded in the same hide |
|---|---|---|---|---|---|
| post, 1 tag | 105.62M | 624 B → 16.85M (16%) | 2,195.5 B → 59.28M (56%) | ~29.5M | 61.97M |
| post, 4 tags + 8 mentions | 384.12M | 624 B → 16.85M (4.4%) | 12,469 B → 336.66M (88%) | ~30.6M | 335.78M |
| a tombstone (nothing to move) | 21.62–21.92M | 16.85M | 0 | ~5M | 0 |
Hides measured across shapes cost 80–395M (≈4.8–23.7¢ at $60/DASH). Unhides re-buy the visible-lane entries the same way: 41.9–134.5M on v18-shaped data. Fresh destination subtrees cost about 371 B (10.0M) each and are a minority of the cost; the moved references are most of it.
Expected
A pure re-key, where the same document's reference moves from one index key to another, should keep the existing storage flags (payer and epoch) and cost processing only. Storage should be charged only for net-new bytes, including any destination subtree beyond what the move freed.
Suggested fix
When an update moves a reference, carry the removed element's flags onto the inserted one; the old flags are already decoded at v1/mod.rs:376-377. Then price the pair as replaced bytes rather than as removed plus added. The sites are v1/mod.rs:290-294, :645-651 and :968-1066. An alternative is to rewrite the costs, as forfeit_storage_refunds does (apply_drive_operations/v1/mod.rs:260-276).
This is not moderation-specific. Any replace that changes an indexed property re-buys the moved entries. With an owner's replace, owner payer and owner refund net out apart from pro-rating. With a moderator's change, two different identities are involved, which is what produces the refund issue #5575.
Impact
"Hide, don't delete" moderation, where moderators set a field instead of deleting, is many times more expensive than it should be. On these measurements a hide is 80–395M, against roughly 42–56M with move-aware accounting, so a 20M per-post action fee covers well under one hide per post. Combined with #5575, it also funds the author's refund.
Activity