Skip to content

Refactor cdel DB from CesarSuber to CesarOnSuber for lexicographic key ordering #1251

@jaelliot

Description

@jaelliot

Background

Per Sam's review (2026-02-26 dev call), the cdel database in src/keri/db/basing.py (line ~1341) uses CesarSuber but should use CesarOnSuber.

# Current (basing.py)
self.cdel = subing.CesarSuber(db=self, subkey='cdel.', klas=coring.Diger)

Problem

The key space for cdel uses a sequence number (via Seqner.qb64/Number.qb64). When stored with a CESR code prefix, the base64 encoding is not guaranteed to be lexicographically ordered if the code ever changes. This means:

  • Database iteration methods won't return entries in numerical order
  • The behavior is fragile — changing from Seqner to Number without huge could silently break ordering

Proposed Fix

  1. Change CesarSuberCesarOnSuber for the cdel database
  2. The key space would then use a hex string ordinal (no CESR code), guaranteeing lexicographic = numeric ordering
  3. Callers would pass the integer sequence number directly instead of constructing a Seqner/Number instance for the key

Current callers in src/keri/app/delegating.py:

  • Line ~96: cdiger = self.hby.db.cdel.get(keys=(prefixer.qb64, seqner.qb64))
  • Line ~234: self.hby.db.cdel.put(keys=(pre, coring.Seqner(sn=serder.sn).qb64), val=coring.Diger(qb64=serder.said))

These would need to change to pass sn as an integer to the OnSuber-style key builder.

Context

References

  • subing.CesarOnSuber — the target DB class (uses hex ordinals in key space)
  • Sam's direction from 2026-02-26 dev call transcript

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions