Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use unsafe.Sizeof() if struct contains a Uint128 #8

Open
lucasoares opened this issue Apr 1, 2024 · 2 comments
Open

Unable to use unsafe.Sizeof() if struct contains a Uint128 #8

lucasoares opened this issue Apr 1, 2024 · 2 comments

Comments

@lucasoares
Copy link

lucasoares commented Apr 1, 2024

If a struct contains bin.Uint128 fields, the result of unsafe.Sizeof for the struct will be 16 bytes higher for each bin.Uint128 field it contains... The result of unsafe.Offsetof will also differ based on the location of the struct's fields.

How can we use unsafe helpers when using the Solana SDK to filter requests (subscriptions, etc) when using the Uint128?

It seems this library is not a good option to use when working with Solana programs for now, but how can we make it be? For now I'm using a slice of uint64 with 2 positions to represent uint128 :(

@gagliardetto
Copy link
Owner

when using the Solana SDK to filter requests (subscriptions, etc)

Can you tell me more?

@lucasoares
Copy link
Author

lucasoares commented Apr 1, 2024

when using the Solana SDK to filter requests (subscriptions, etc)

Can you tell me more?

Example of something I can't do with the current implementation if I use Uint128:

	info := AmmInfo{}
	subscription, err = wsConnection.ProgramSubscribeWithOpts(
		<other parameters>,
		[]rpc.RPCFilter{
			{
				DataSize: uint64(unsafe.Sizeof(info)),
			},
			{
				Memcmp: &rpc.RPCFilterMemcmp{
					Offset: uint64(unsafe.Offsetof(info.PcVaultMint)),
					Bytes:  SOL[:],
				},
			},
			{
				Memcmp: &rpc.RPCFilterMemcmp{
					Offset: uint64(unsafe.Offsetof(info.MarketProgram)),
					Bytes:  open_book.MAINNET_OPENBOOK_MARKET[:],
				},
			},
		},
	)

If the AmmInfo struct contains any UInt128, the result of Sizeof and Offsetof will be incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants