8 | @@ -9,6 +9,11 @@
9 | #include <random.h>
10 | #include <version.h>
11 |
12 | +/* Check structure sizes are nicely packed */
13 | +static_assert(sizeof(CScript) == 32, "unexpected sizeof(CScript)");
14 | +static_assert(44 <= sizeof(Coin) && sizeof(Coin) <= 48, "unexpected sizeof(Coin)");
15 | +static_assert(48 <= sizeof(CCoinsCacheEntry) && sizeof(CCoinsCacheEntry) <= 56, "unexpected sizeof(CCoinsCacheEntry)");
I don't think it should be a compile error if these are too small or big. This means that for any field added/removed to the structure, or possible for new compilers/architectures, these lines have to be updated.
Agree, mostly wanted them in there to check that there weren't any unexpected changes at least on any of the architectures travis checks. (It's 44/48 for 4-byte pointers and 48/56 for 8-byte pointers). Rebased without that commit.
Yeah, it's good for that.
I later realized there could be a case for checking CScript's size because it's supposed to be 32 bytes no matter the architecture (assuming pointer sizes <= 128 bit :smiley: ), and it's unlikely for fields to be added to it. But I dunno.
CScript seems like it ought to be reasonably robust, and it's got that 28 constant already. Maybe if #17060 or the like makes progress could add some checks then? Figure it only makes sense to worry about the size of the things you're caching a bazillion of...
Actually I think to a degree CScript being 32 is non obvious... e.g. the size could be shifted greater if that were expected to be the "hot case" for fitting most CScripts. It does kind of seem like 28 might be too small, and worth re-measuring. P2SH fits in 32, but a segwit output should be 33 bytes long... unless I'm missing some case where 28 is a common size nowadays.
p2pkh, p2sh and p2wpkh should all fit; p2wsh won't fit though (and neither will p2taproot if/when it exists)