coral-xyz / anchor-book

The Anchor Book
https://book.anchor-lang.com
Apache License 2.0
97 stars 59 forks source link

bug about "Tic-Tac-Toe" project. #95

Open oulaoba opened 8 months ago

oulaoba commented 8 months ago

When i code flow this example Milestone Project - Tic-Tac-Toe.

I got an error " Error: AnchorError caused by account: game. Error Code: AccountDidNotSerialize. Error Number: 3004. Error Message: Failed to serialize the account." at anchor test.

I also see the notice.

(What about using mem::size_of()? This almost works but not quite. The issue is that borsh will always serialize an option as 1 byte for the variant identifier and then additional x bytes for the content if it's Some. Rust uses null-pointer optimization to make Option's variant identifier 0 bytes when it can, so an option is sometimes just as big as its contents. This is the case with Sign. This means the MAXIMUM_SIZE could also be expressed as mem::size_of() + 9.)

but it seems like lose 4 bit of borsh space. Maybe the MAXIMUM_SIZE need change to pub const MAXIMUM_SIZE: usize = 4 + (32 * 2) + 1 + (9 * (1 + 1)) + (32 + 1);