Multimap tables

Outputs

When referencing outputs, Monero will use the amount and the amount index. This means 2 keys are needed to reach an output.

With LMDB you can set the DUP_SORT flag on a table and then set the key/value to:

#![allow(unused)]
fn main() {
Key = KEY_PART_1
}
#![allow(unused)]
fn main() {
Value = {
    KEY_PART_2,
    VALUE // The actual value we are storing.
}
}

Then you can set a custom value sorting function that only takes KEY_PART_2 into account; this is how monerod does it.

This requires that the underlying database supports:

  • multimap tables
  • custom sort functions on values
  • setting a cursor on a specific key/value

How cuprate_blockchain does it

Another way to implement this is as follows:

#![allow(unused)]
fn main() {
Key = { KEY_PART_1, KEY_PART_2 }
}
#![allow(unused)]
fn main() {
Value = VALUE
}

Then the key type is simply used to look up the value; this is how cuprate_blockchain does it as cuprate_database does not have a multimap abstraction (yet).

For example, the key/value pair for outputs is:

#![allow(unused)]
fn main() {
PreRctOutputId => Output
}

where PreRctOutputId looks like this:

#![allow(unused)]
fn main() {
struct PreRctOutputId {
    amount: u64,
    amount_index: u64,
}
}
Last change: 2024-10-17, commit: 978d72b