Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

compact/v0 package

Overview

Package compact makes fragmentation a number you can act on.

A soft delete does not free anything. It clears the element and leaves the tree node behind, so the bytes stay locked and every read still walks past them. Compacting drops those nodes and the chain refunds their deposit to whoever signed the transaction. So compaction is paid work, and the only real question is WHEN: too early and you free too few nodes to cover the gas, too late and every read has been paying for the holes in between.

This realm refuses to answer that question, on purpose. It publishes the two integers the answer is made of and lets whoever is watching decide, because the realm cannot see the gas price of the day and the caller can.

  • Fragmentation() is live vs allocated, the free read a bot polls.
  • Reclaimable() is what a Compact would actually free, right now.
  • Quote() prices it at the floor gas price, as an advertisement.

The arithmetic is gno.land/p/moul/x/storagecost and the container is gno.land/p/moul/ulist, whose Compact drops dead nodes without moving a live index, so an index is stable for the life of the realm.

Why this quote is trustworthy where a reaper's is not

A reaper advertises what deleting entries will refund, and to do that it has to guess how much state an entry occupies from its payload length. That guess is bad: a per-entry floor dominates at the small end, and one realm under-advertised by 25x on chain because of it.

Compaction has no such problem. What it frees is a COUNT of dead nodes, and the container already reports that count exactly. Every node costs the same whatever it carried. So the number on this page is a measured constant times an exact integer, not a ratio applied to a guess, which is why this is the half of the mechanism worth showing first.

Functions

Add

func Add(cur realm, text string) int

Add appends an entry and locks its storage deposit against the caller.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/compact/v0" -func "Add" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/compact/v0" -func "Add" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Compact

func Compact(cur realm) int

Compact frees the dead tree nodes and returns how many it freed.

Permissionless by design, and the refund goes to whoever signs this transaction rather than to the realm or to the authors: the chain pays the signer directly, so there is nothing here to distribute and nothing to steal. The worst a caller can do is waste their own gas compacting a board that had no holes.

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/compact/v0" -func "Compact" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/compact/v0" -func "Compact" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Drop

func Drop(cur realm, index int)

Drop soft-deletes your own entry, which is what creates a hole.

It frees nothing on its own, and that is the point of the realm: the bytes stay locked until somebody compacts. Only the author may drop, so the fragmentation on this page is the honest kind that ordinary use produces.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/compact/v0" -func "Drop" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/compact/v0" -func "Drop" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Fragmentation

func Fragmentation() (live, allocated int)

Fragmentation reports live elements against allocated indices.

The gap between them is what a compaction has to work with. It is a free read so a bot can poll it and decide for itself, which is the whole design: the realm publishes, the caller times.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/compact/v0.Fragmentation()"

Result

Quote

func Quote() storagecost.Quote

Quote prices what a Compact would return, at the default storage price and the floor gas price.

Unlike a payload-derived bounty this is a counted quantity: Reclaimable is exact, and storagecost.EstimateNodes multiplies it by a measured per-node constant. Treat it as an advertisement all the same. The authoritative numbers are the chain's, in the StorageUnlockEvent the transaction emits.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/compact/v0.Quote()"

Result

Reclaimable

func Reclaimable() int

Reclaimable is how many dead nodes a Compact would free right now.

It is NOT the same as allocated minus live. A dead element only becomes a reclaimable node once every element under it is also dead, so a board with many scattered holes can report a large gap and nothing to reclaim. That difference is exactly what makes the timing a decision instead of a rule.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/compact/v0.Reclaimable()"

Result

Render

func Render(path string) string

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/compact/v0.Render()"

Result