Skip to content

Commit 9252202

Browse files
ravyu-jumpripatel-fd
authored andcommitted
types: add length metadata in short_vector
Update types_walk to reproduce a quirk in Rust's bincode serde tree for vectors with a compressed length prefix.
1 parent 6cfce67 commit 9252202

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/flamenco/types/fd_types.c

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/types/fixtures/gossip_pull_resp_contact_info_v2.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ push_msg:
101101
commit: 0
102102
feature_set: 367846227
103103
client: 0
104+
addrs_len: 1
104105
addrs:
105106
- ip4:
106107
- 127
107108
- 0
108109
- 0
109110
- 1
111+
sockets_len: 12
110112
sockets:
111113
- key: 0
112114
index: 0
@@ -144,6 +146,7 @@ push_msg:
144146
- key: 3
145147
index: 0
146148
offset: 1
149+
extensions_len: 0
147150
- signature: '64dzXW7Yv2U6qvME4ZnQWgQqos3eqAqQj9Z3q21r6XKgg66rAk2z6dNBptqExgWL7shZ7Dgr86TiGs97ApcAzyM5'
148151
data:
149152
node_instance:

src/flamenco/types/gen_stubs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,15 @@ def emitSize(self, inner, indent=''):
707707
}
708708

709709
def emitWalk(self, inner, indent=''):
710+
# The `serialize` function in Rust's `short_vec` (analagous to our `walk()` implementation) handles serializing
711+
# the vector's length independently, rather than relying on the Serializer (i.e., the `walk` function callback)
712+
# to do it. To remain consistent, we have to replicate this behavior here.
713+
# Reference: https://docs.rs/solana-short-vec/latest/src/solana_short_vec/lib.rs.html#166-185
714+
# Additionally, does this imply that `short_vec` encodes lengths twice? No, because it uses the `serialize_tuple`
715+
# callback (which, in Bincode's implementation, does not encode the sequence length) rather than `serialize_seq`.
716+
# Reference: https://docs.rs/bincode/latest/src/bincode/features/serde/ser.rs.html#226-228 (see the `serialize_seq` implementation above for comparison)
717+
if self.compact:
718+
print(f'{indent} fun( w, &self->{self.name}_len, "{self.name}_len", FD_FLAMENCO_TYPE_USHORT, "ushort", level );', file=body)
710719
if self.element == "uchar":
711720
print(f'{indent} if( self->{self.name}_len ) {{', file=body)
712721
print(f'{indent} fun(w, self->{self.name}, "{self.name}", FD_FLAMENCO_TYPE_UCHAR, "{self.element}", level );', file=body)

0 commit comments

Comments
 (0)