Reading Anchor accounts
Eight bytes before the fields
What the first eight bytes are
Anchor account data begins with an eight-byte discriminator. It is there so the program can tell one account type from another before it trusts the rest of the bytes. The value is the first eight bytes of a hash of a namespaced name: the account struct’s name, prefixed so it cannot collide with an instruction name.
Instruction data uses the same idea with a different prefix. When a Thursday packet says ‘skip eight bytes’, it means the fields you came to read start after that marker. Starting at zero will make every integer look nonsense.
Why the room still computes one by hand
We do not ask visitors to hash by hand for long. We do ask them to watch one discriminator get checked at the top of a decode, and to see the program reject a buffer that belongs to a different struct. That rejection is a feature. It is how a vault account is kept from being passed where a user record was expected.
The September Desk Hours on this topic used a two-struct program: a deal record and a receipt. Same owner, different discriminators. Swapping them is the exercise. The handler that forgets the check will happily read a receipt as a deal until a later field fails a bounds check and hides the real mistake.
Field order still matters
After the discriminator, Borsh lays fields out in the order they are declared. A u64 is eight bytes. A public key is thirty-two. An optional value has a prefix byte. Moving a field in the struct changes every offset after it, which is why the circle treats a ‘small cleanup’ of field order as a new account layout, not as tidying.
The catch-up sheet for evening two of the Source Circle is only this: discriminator, then fields in source order, with widths written beside them. Visitors who already know it can turn the sheet over and start on the instruction accounts.
A reading habit
When you open an account in the reading room, say the discriminator check aloud before you name a field. It sounds slow. It stops the group from debugging a ‘corrupt amount’ that was never an amount. The amount was eight bytes further along, behind the marker.