Files
zeekay 518613b5f7 The P-chain reads and writes its wire out of a schema
Every offset the C++ P-chain had was stated by hand, in four places that had
to agree: txs.hpp named the envelope and each of nineteen transactions'
fields, txs_wire.hpp named the strides, txs_wire.cpp did the arithmetic, and
block.hpp said it again for blocks. Four more files — genesis, warp, warpmsg
and components — each named their own. That is the same number written down
six times, and the fix for it is a generator.

Four schemas now say it once, and zapgen prints the readers, the builders and
the offsets from them:

    schema/wire.zap     transactions, blocks, credentials, an owner set,
                        and the two fx envelopes an output is ordered by
    schema/genesis.zap  the genesis blob
    schema/warp.zap     the message and the aggregated proof over it
    schema/warpmsg.zap  what an L1 and the P-chain say to each other

One schema per namespace, because a package name is what a backend renders as
a namespace and a file declares one.

What is left beside them — 283 lines, down from 1,463 — holds not one offset.
It holds the ARRANGEMENT, which is a fact about this chain rather than about
the format: an output's owner addresses do not live in the output, they live
in one run shared by the whole transaction, and the output names a slice of
it. That is what lets a transaction be read without walking it, and it was a
decision this chain made, so it is stated once instead of at the nineteen
places a transaction is built.

The bytes did not move, and that is checked rather than asserted. txs_test,
block_test, genesis_test and components_test compare 39 buffers against hex
the GO REFERENCE printed — a round trip would only prove this port agrees
with itself, which is what a fork also does. All 18 suites pass, and the
chain's answers to all 159 P-chain corpus vectors are byte-identical to the
answers it gave before.

Two things came out of doing it. The generator now refuses a field named as
the struct that holds it: warp's Hash message has a Hash field, and the
accessor for it is a constructor with a return type that the compiler rejects
three files from the schema that caused it — one rule in the front end, all
three backends. And zap.cmake pinned the generator to the runtime's tag, a
version that does not exist in the generator's repository, so that target had
never run; the generator has its own pin now, at zap-proto/go v1.9.0, which
reproduces every committed header byte for byte.
2026-09-06 13:20:10 -07:00

31 lines
770 B
Plaintext

# SPDX-License-Identifier: BSD-3-Clause-Eco
# The warp message wire, and the aggregated proof over it.
#
# A signed message is the unsigned bytes and the signature bytes, each a whole
# message of its own, so what a signer signed is carried verbatim rather than
# reconstructed.
package lux.platformvm.warp.wire
type id32 = bytes_fixed[32]
type proof = bytes_fixed[96]
struct Unsigned {
NetworkID u32 @0
Source id32 @4
Payload bytes @36
}
struct Signed {
Unsigned bytes @0
Signature bytes @8
}
# One aggregate signature and the bit vector saying who is in it. The vector
# is a big-endian big integer, which is why it is a byte run and not a list.
struct BitSet {
Kind u8 @0
Signature proof @1
Signers bytes @97
}