Store Public Keys in tiles coordinate-matched to Entry tiles. - #8958
Store Public Keys in tiles coordinate-matched to Entry tiles.#8958ezekiel wants to merge 7 commits into
Conversation
Isolating this change to gauge impact on MTCA Preflight().
| nullEntry := &entry.MTCLogEntry{} | ||
| err := candidate.AppendEntry(nullEntry) | ||
| nullPubkey := &pubkey.MTCPublicKey{} | ||
| err := candidate.AppendEntry(nullEntry, nullPubkey) |
There was a problem hiding this comment.
nit: no need to create standalone variables for these when they're only used once.
| err := candidate.AppendEntry(nullEntry, nullPubkey) | |
| err := candidate.AppendEntry(&entry.MTCLogEntry{}, &pubkey.MTCPublicKey) |
| const entriesTileLayer int = -1 | ||
| const pubkeysTileLayer int = -2 |
There was a problem hiding this comment.
hyper naming nit, feel free to ignore, I just find these names to be easier to think about and say in my head:
| const entriesTileLayer int = -1 | |
| const pubkeysTileLayer int = -2 | |
| const entryTilesLayer int = -1 | |
| const pubkeyTilesLayer int = -2 |
|
|
||
| bundleBytes, err := mtcleBuilder.Bytes() |
There was a problem hiding this comment.
two nits:
- no empty line here, since we didn't just have an
if errstanza; and - no point in calling this a "bundle", since it's a bundle of just one entry.
| bundleBytes, err := mtcleBuilder.Bytes() | |
| entryBytes, err := mtcleBuilder.Bytes() |
|
|
||
| pkBundleBytes, err := mtcpkBuilder.Bytes() |
There was a problem hiding this comment.
same nit here:
| pkBundleBytes, err := mtcpkBuilder.Bytes() | |
| pubkeyBytes, err := mtcpkBuilder.Bytes() |
| // Tile Layer representation constants | ||
| const entriesTileLayer int = -1 | ||
| const pubkeysTileLayer int = -2 | ||
|
|
There was a problem hiding this comment.
Also, consider having an additional constant here representing the "lowest level", so we don't have to have -2 as a magic number when working with the dirty level.
| const lowestLayer int = pubkeyTilesLayer | |
| pkBytes, err := x509.MarshalPKIXPublicKey(mtcpk.pub) | ||
| // MarshalPKIXPublicKey returns an error on nil pubkey, but we want to be able to have nil tiles | ||
| if err != nil && err.Error() != "x509: unsupported public key type: <nil>" { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
Move this code inside the case typeMTCPubkey, and then you don't need the error string special casing.
| // pkBytes is a crypto.x509 SubjectPublicKeyInfo structure | ||
| builder.AddBytes(pkBytes) | ||
| case typeNilPubkey: | ||
| if len(pkBytes) != 0 { |
There was a problem hiding this comment.
Alongside the suggestions above that mtcpk.pub just become a byte slice, this check nicely becomes if len(mtcpk.pub) != 0.
|
|
||
| // FromCryptoPubkey feeds a crypto.PublicKey into position in an MTCPublicKey | ||
| // struct, setting the struct "typ" to nil if the input public key is nil | ||
| func FromCryptoPubkey(in crypto.PublicKey) (*MTCPublicKey, error) { |
There was a problem hiding this comment.
Let's make this more like entry.FromX509, namely: error out on a nil input, marshal the pubkey, and store those marshaled bytes as MTCPublicKey.pub.
| typ uint16 | ||
| pub crypto.PublicKey // a SubjectPublicKeyInfo structure |
There was a problem hiding this comment.
Let's make this bytes, matching entry.MTCLogEntry.value. Then marshal can just do the cryptobyte bits of smashing together the type and this value.
| spki, err := x509.ParsePKIXPublicKey([]byte(val)) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
No need to parse here once mtcpk.pub is just bytes.
This changes the MTCA to include the public key in the pendingEntries submitted for sequencing. Upon sequencing, the subjectPublicKeyInfo structure is bundled just like Entries are bundled, and stored in tiles with the same coordinates as the Entry tiles, but at a different layer (
-2).For writing the public key tiles, we introduce Bundling and Marshaling functions specific to a new MTCPublicKey structure which wraps subjectPublicKeyInfo and facilitates null pubkey placeholders in the tile information tracked in the Frontier.
Fixes #8913