nameindex

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package nameindex implements an opt-in, per-node, off-chain index over anchoring Registry names. It exists because the on-chain KV store only supports id lookups and ordered-prefix scans: it cannot answer "does any registry's name contain X" or "which registries end in X" without a full table scan inside consensus-critical code. This package keeps that lookup out of the state machine entirely, backed by a local SQLite file that a node operator opts into via app.toml.

The index is not part of consensus: nodes are not required to run it, two nodes may answer a search differently while one is still backfilling, and its content is derived, never authoritative. The authoritative registry data always lives in the anchoring module's own collections.

Index

Constants

View Source
const ConfigTemplate = `` /* 649-byte string literal not displayed */

ConfigTemplate is appended to the node's app.toml template so operators can see and edit these settings.

View Source
const MinContainsQueryLen = 3

MinContainsQueryLen is the shortest CONTAINS query a trigram index can answer. The other modes have no minimum.

View Source
const TomlSection = "anchoring-name-index"

TomlSection is the app.toml section name node operators use to opt into the registry name index.

Variables

View Source
var ErrContainsTooShort = fmt.Errorf("contains query needs at least %d characters", MinContainsQueryLen)

ErrContainsTooShort rejects a shorter one rather than scanning for it.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

Batch groups upserts into one SQLite transaction, so a backfill or a block with several registry writes costs one fsync and lands atomically.

func (*Batch) Close

func (b *Batch) Close()

Close rolls the batch back unless it was committed. Safe to defer unconditionally.

func (*Batch) Commit

func (b *Batch) Commit() error

Commit publishes every Upsert in the batch at once.

func (*Batch) Upsert

func (b *Batch) Upsert(reg *types.Registry) error

Upsert indexes (or re-indexes) a registry within the batch.

type Config

type Config struct {
	// Enabled registers the ABCIListener, backfills on start, and serves
	// Query/SearchRegistriesByName. Off by default.
	Enabled bool
	// DBPath is the SQLite file. Relative paths resolve under <home>/data.
	DBPath string
}

Config controls whether this node builds and serves the registry name index, and where its backing SQLite file lives.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the disabled-by-default config used to seed a fresh app.toml.

func ReadConfig

func ReadConfig(appOpts servertypes.AppOptions, homeDir string) Config

ReadConfig reads the [anchoring-name-index] section from AppOptions (app.toml), resolving a relative db-path under <home>/data.

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener is a storetypes.ABCIListener that keeps a Store in sync with the anchoring module's Registries collection. It only ever observes state that has already been committed, so a rolled-back tx (e.g. a later msg in the same tx failing) never reaches the index.

func NewListener

func NewListener(store *Store) *Listener

func (*Listener) ListenCommit

func (l *Listener) ListenCommit(_ context.Context, _ abci.ResponseCommit, changeSet []*storetypes.StoreKVPair) error

ListenCommit indexes every Registry write in the just-committed changeset as one batch, so a block lands in the index atomically or not at all.

baseapp only logs an error returned from here; it neither halts the node nor retries. A block whose write failed therefore leaves the index behind until the next restart, when Keeper.BackfillNameIndex re-walks the collection.

func (*Listener) ListenFinalizeBlock

ListenFinalizeBlock is unused: the registries collection is only read from the finalized changeset delivered to ListenCommit.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a local, opt-in SQLite-backed index of registry names.

func Open

func Open(path string, cdc codec.BinaryCodec) (*Store, error)

Open opens (creating if needed) the SQLite database at path and ensures its schema exists. cdc is used to decode the raw Registry proto bytes captured off the committed changeset.

The database runs in WAL mode so RPC readers never block the writer: ListenCommit runs synchronously inside block Commit, and a burst of search queries must not delay it. Writers are serial by construction (backfill at startup, then one batch per committed block); busy_timeout covers the rare overlap with a WAL checkpoint.

case_sensitive_like is on because SQLite serves LIKE from a B-tree index only when it is. Both sides are lowercased in Go, so matching stays case-insensitive.

func (*Store) Begin

func (s *Store) Begin() (*Batch, error)

Begin starts a write batch. Commit it to publish; defer Close so an early return rolls it back.

func (*Store) Close

func (s *Store) Close() error

func (*Store) Count

func (s *Store) Count() (uint64, error)

Count returns the number of indexed registries. Ids are dense and add-only, so a count equal to the chain's RegistryCount means the index is complete.

func (*Store) Search

func (s *Store) Search(mode types.RegistryNameMatchMode, query string, start, limit, offset uint64) (results []*types.Registry, next uint64, err error)

Search returns up to limit registries whose name matches query under mode, ordered by id, starting at the first match with id >= start and then skipping offset matches. Matching is always case-insensitive. A CONTAINS query shorter than MinContainsQueryLen characters returns ErrContainsTooShort.

next is the id of the first match after the page, to pass back as start for the following page, or 0 when the page is the last one. Registry ids start at 1, so a start of 0 means "from the beginning".

func (*Store) Upsert

func (s *Store) Upsert(reg *types.Registry) error

Upsert indexes (or re-indexes) a single registry in its own transaction. Registries are add-only on-chain, but Upsert is idempotent so backfill and listener replay converge on the same content.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址