# README
Legacy, notes from Yongzhe
For functions which retrieves one key-value pair, sql.ErrNoRows will be thrown if no rows is founded. For functions which retrieves a list of key-value pairs, sql.ErrNoRows will be omitted. So please check the length of the output to decide if the fetching is incomplete.
New notes
Design
The DB supports the map server in two aspects:
- Stores the certificates and their trust chains
- Stores the Sparse Merkle Tree structure on disk
We need very efficient requests based on the domain name. The update process has to simply retrieve the new certificates and their trust chains, add them to the DB, write down those updated domains, and process the SMT for those domains only.
Tables
For performance reasons, no foreign keys exist in any table.
certs
tableid
: PK, this is the SHA256 of the certificate.parent_id
: this is the parent certificate, in the trust chain, orNULL
if root.expiration
: this is the not_after field of the certificate.payload
: BLOB, this is the certificate, serialized.
domains
table. This table is updated in DB from thecerts
tablecert_id
: PK, SHA256 of the certificatedomain_id
: PK, SHA256 of the domaindomain
: index, text, the name of the domainpayload_id
: BIGINT, points to the serialized certificate collection, according to the rules.
domain_payloads
table. Holds the collection of certificates for each domain. This comes from all the certificates that have theircerts.domain
equal to thisdomains.domain
, serialized following certain rules.id
: BIGINTpayload
: BLOBpayload_hash
: SHA256 of the serialized certificate collection for the domain.
dirty
tabledomain_id
: PK, SHA256 of each of the modified domains.
SMT tables:
tree
table, remains the same as beforeid
: PK, auto increment.key32
: index, whatever the SMT library uses as key, 32 bytes.value
: whatever the SMT library uses as value.
root
table. Should contain zero or one elements.key32
: PK, 32 bytes, SHA256 of the root of the SMT.
The dirty
table should always be non-empty when the SMT update process starts,
as it contains the domains that have been altered, and those that will be
sent to the SMT to update.
Update Process
We describe the update process with the following steps:
- Obtain the data.
- Create (
upsert
or similar) a new record per new certificate C and domain D. - Write the modified domains into a table
dirty
(formerly known as theupdates
table). - In DB and via a stored procedure, serialize the certificate collection (following certain rules) and write it, plus its SHA256, to the table.
- Wait until all batches have finished.
- Update the SMT with the material from (4), and using the domains in
dirty
. - Store the
tree
table in DB. - Truncate the
dirty
table.