You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change hash representation from slice to 32-byte array
This change is non-functional, just a clean-up, reducing tech debt.
This codebase manipulates many 32-byte hashes, such as block hashes,
transaction IDs, and merkle roots. These should always have been
represented as fixed-size 32-byte arrays rather than variable-length
slices. This prevents bugs (a slice that's supposed to be of length
32 bytes could be a different length) and makes assigning, comparing,
function argument passing, and function return value passing simpler
and less fragile.
The new hash type, hash32.T, which is defined as [32]byte (32-byte
array of bytes), can be treated like any simple variable, such as an
integer. A slice, in contrast, is like a string; it's really a structure
that includes a length, capacity, and pointer to separately-allocated
memory to hold the elements of the slice.
The only point of friction is that protobuf doesn't support fixed-sized
arrays, only (in effect) slices. So conversion must be done in each
direction.
0 commit comments