Skip to content

Commit 3efa50a

Browse files
feat Updates for parsers generator: (#700)
* `feat` Updates for parsers generator: - Add support for omitted optional accounts strategy - Add more strict deserialization checking deserialized bytes lenght - Add better error monitoring with tracing - Add support for number types discriminators (for accounts and ixs) - Add feature flag to generated parsers to opt in for shared transaction data * `fix`: - Update next_account functions to use solana_pubkey crate - Update proto enum variants imports to support variants with same names - Correct impl for struct enum variants inside proto * `fix` remove not needed reference * `feat` Allow crate description customization * `feat` expose vixen render toolchain to rust sdk render * `feat` Add customImplFolder boolean flag * `feat` Use deserialize_checked strategy instead of custom_impl * `chore` Update e2e example tests * Create wicked-bees-smoke.md * `chore` set semver bump to minor
1 parent 7b7dc00 commit 3efa50a

File tree

111 files changed

+2188
-1221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2188
-1221
lines changed

.changeset/wicked-bees-smoke.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@codama/renderers-vixen-parser": minor
3+
---
4+
5+
`feat` Updates for parsers generator:
6+
- Add support for omitted optional accounts strategy
7+
- Add more strict deserialization checking deserialized bytes lenght
8+
- Add better error monitoring with tracing
9+
- Add support for number types discriminators (for accounts and ixs)
10+
- Add feature flag to generated parsers to opt in for shared transaction data

packages/renderers-vixen-parser/e2e/orca-whirlpool-parser/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
name = "yellowstone-vixen-orca-whirlpool-parser"
55
version = "0.1.0"
66
edition = "2021"
7+
description = ""
8+
license = "MIT"
9+
repository = "https://github.com/rpcpool/yellowstone-vixen"
710

811

912
[dependencies]
1013
prost = "0.13.1"
14+
yellowstone-vixen-core = { git = "https://github.com/rpcpool/yellowstone-vixen", branch = "main",features = ["proto"] }
1115
tonic = { version = "0.12.1", features = ["gzip", "zstd"] }
1216
solana-account-info = "2.2.1"
1317
solana-cpi = "2.2.1"
@@ -18,7 +22,6 @@ solana-msg = "2.2.1"
1822
solana-program-entrypoint = "2.2.1"
1923
solana-program-error = "2.2.1"
2024
borsh = "^0.10"
21-
yellowstone-vixen-core = { git = "https://github.com/rpcpool/yellowstone-vixen", branch = "main",features = ["proto"] }
2225
num-derive = "0.4"
2326
thiserror = "1.0.64"
2427
num-traits = "^0.2"
@@ -33,7 +36,8 @@ serde = []
3336
test-sbf = []
3437
fetch = []
3538
tracing = ["dep:tracing", "dep:strum", "dep:strum_macros"]
39+
# Exposes shared transaction data like tx signature, slot and more, to be available in Vixen Handlers
40+
shared-data = []
3641

3742
[build-dependencies]
3843
prost-build = "0.13.1"
39-

packages/renderers-vixen-parser/e2e/orca-whirlpool-parser/src/generated_parser/accounts_parser.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::accounts::WhirlpoolsConfig;
1616
use crate::accounts::WhirlpoolsConfigExtension;
1717
use crate::ID;
1818

19+
use crate::deserialize_checked;
20+
1921
/// Whirlpool Program State
2022
#[allow(clippy::large_enum_variant)]
2123
#[derive(Debug)]
@@ -37,33 +39,33 @@ impl WhirlpoolProgramState {
3739
let acc_discriminator: [u8; 8] = data_bytes[0..8].try_into()?;
3840
let acc = match acc_discriminator {
3941
[157, 20, 49, 224, 217, 87, 193, 254] => Ok(WhirlpoolProgramState::WhirlpoolsConfig(
40-
WhirlpoolsConfig::from_bytes(data_bytes)?,
42+
deserialize_checked(data_bytes, &acc_discriminator)?,
4143
)),
4244
[2, 99, 215, 163, 240, 26, 153, 58] => {
4345
Ok(WhirlpoolProgramState::WhirlpoolsConfigExtension(
44-
WhirlpoolsConfigExtension::from_bytes(data_bytes)?,
46+
deserialize_checked(data_bytes, &acc_discriminator)?,
4547
))
4648
}
4749
[56, 75, 159, 76, 142, 68, 190, 105] => Ok(WhirlpoolProgramState::FeeTier(
48-
FeeTier::from_bytes(data_bytes)?,
50+
deserialize_checked(data_bytes, &acc_discriminator)?,
4951
)),
5052
[106, 47, 238, 159, 124, 12, 160, 192] => Ok(WhirlpoolProgramState::LockConfig(
51-
LockConfig::from_bytes(data_bytes)?,
53+
deserialize_checked(data_bytes, &acc_discriminator)?,
5254
)),
5355
[170, 188, 143, 228, 122, 64, 247, 208] => Ok(WhirlpoolProgramState::Position(
54-
Position::from_bytes(data_bytes)?,
56+
deserialize_checked(data_bytes, &acc_discriminator)?,
5557
)),
5658
[129, 169, 175, 65, 185, 95, 32, 100] => Ok(WhirlpoolProgramState::PositionBundle(
57-
PositionBundle::from_bytes(data_bytes)?,
59+
deserialize_checked(data_bytes, &acc_discriminator)?,
5860
)),
5961
[69, 97, 189, 190, 110, 7, 66, 187] => Ok(WhirlpoolProgramState::TickArray(
60-
TickArray::from_bytes(data_bytes)?,
62+
deserialize_checked(data_bytes, &acc_discriminator)?,
6163
)),
6264
[116, 219, 204, 229, 249, 116, 255, 150] => Ok(WhirlpoolProgramState::TokenBadge(
63-
TokenBadge::from_bytes(data_bytes)?,
65+
deserialize_checked(data_bytes, &acc_discriminator)?,
6466
)),
6567
[63, 149, 209, 12, 225, 128, 99, 9] => Ok(WhirlpoolProgramState::Whirlpool(
66-
Whirlpool::from_bytes(data_bytes)?,
68+
deserialize_checked(data_bytes, &acc_discriminator)?,
6769
)),
6870
_ => Err(yellowstone_vixen_core::ParseError::from(
6971
"Invalid Account discriminator".to_owned(),
@@ -122,7 +124,22 @@ impl yellowstone_vixen_core::Parser for AccountParser {
122124
.account
123125
.as_ref()
124126
.ok_or(solana_program_error::ProgramError::InvalidArgument)?;
125-
WhirlpoolProgramState::try_unpack(&inner.data)
127+
let res = WhirlpoolProgramState::try_unpack(&inner.data);
128+
129+
#[cfg(feature = "tracing")]
130+
if let Err(e) = &res {
131+
let acc_discriminator: [u8; 8] = inner.data[0..8].try_into()?;
132+
tracing::info!(
133+
name: "incorrectly_parsed_account",
134+
name = "account_update",
135+
program = ID.to_string(),
136+
account = "deserialization_error",
137+
discriminator = ?acc_discriminator,
138+
error = ?e
139+
);
140+
}
141+
142+
res
126143
}
127144
}
128145

0 commit comments

Comments
 (0)