Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8164dd3
XC-342: Add support for `rewards` parameter for `getBlock` RPC method
lpahlavi May 30, 2025
736b816
XC-342: Fix serialization unit test
lpahlavi May 30, 2025
c1286fe
XC-342: Add request builder methods and rustdoc
lpahlavi May 30, 2025
3eb2e0b
XC-342: Fix Candid interface
lpahlavi May 30, 2025
8fc3b8b
XC-342: Fix Candid formatting
lpahlavi May 30, 2025
1c3231e
XC-342: Clippy
lpahlavi May 30, 2025
bb45a67
XC-342: Clippy
lpahlavi May 30, 2025
775718c
XC-342: Rustdoc
lpahlavi May 30, 2025
aa57cf7
XC-342: Increase cycles when `rewards=true`
lpahlavi May 30, 2025
55470b8
XC-342: Small clean-ups in Solana validator tests
lpahlavi Jun 2, 2025
7dc0e54
Merge branch 'main' into lpahlavi/XC-342-add-rewards-request-param
lpahlavi Jun 2, 2025
026d1e8
XC-342: Clippy
lpahlavi Jun 2, 2025
3da27d2
XC-342: Debugging message
lpahlavi Jun 2, 2025
29a987f
XC-342: Update response size estimate based on rewards parameter
lpahlavi Jun 2, 2025
03ea5e9
Merge branch 'main' into lpahlavi/XC-342-add-rewards-request-param
lpahlavi Jun 2, 2025
44dc861
XC-342: Update limitations for `getBlock`
lpahlavi Jun 2, 2025
2f0835e
XC-342: Remove panic
lpahlavi Jun 2, 2025
416579b
XC-342: Clippy
lpahlavi Jun 2, 2025
b3bb171
XC-342: Remove panic
lpahlavi Jun 2, 2025
655b42b
XC-342: Update cycles when changing transaction details and rewards
lpahlavi Jun 2, 2025
edc5762
XC-342: Update cycles cost
lpahlavi Jun 2, 2025
6c24b91
XC-342: Add `transactionDetails` `accounts`
lpahlavi Jun 3, 2025
2f3df1c
Revert "XC-342: Add `transactionDetails` `accounts`"
lpahlavi Jun 3, 2025
12e70de
Merge branch 'main' into lpahlavi/XC-342-add-rewards-request-param
lpahlavi Jun 4, 2025
0c52902
XC-342: Use `opt false` instead of `null`
lpahlavi Jun 4, 2025
f2e6eab
XC-342: Rename `get_rewards` method
lpahlavi Jun 4, 2025
e9862ee
XC-342: Fix account info test asserts
lpahlavi Jun 4, 2025
5559b91
XC-342: Remove unnecessary comment
lpahlavi Jun 4, 2025
0c96e9e
XC-342: Update `numRewardPartitions` doc
lpahlavi Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ The table below summarizes the supported endpoints and the necessary changes (if
* :scissors: one or several fields are either not supported in the request parameters, or removed from the raw response.
* :hammer_and_wrench: the raw response is more heavily transformed (e.g. rounding, subset, etc.).

| Solana method | Support | Known limitations |
|-------------------------------------------------------------------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`getAccountInfo`](https://solana.com/de/docs/rpc/http/getaccountinfo) | :scissors: | <ul><li>The field `context` is removed from the response</li></ul> |
| [`getBalance`](https://solana.com/de/docs/rpc/http/getbalance) | :scissors: | <ul><li>The field `context` is removed from the response</li></ul> |
| [`getBlock`](https://solana.com/de/docs/rpc/http/getblock) | :scissors: | <ul><li>Only the `signatures` and `none` values for the `transactionDetails` request parameter are supported. If not specified, the default value is `none`.</li></ul><ul><li>The `encoding` and `rewards` request parameters are not supported. If not specified, the default value of `rewards` is `false`.</li></ul> |
| [`getRecenPrioritizationFees`](https://solana.com/de/docs/rpc/http/getrecentprioritizationfees) | :hammer_and_wrench: | <ul><li>Returns a subset of the response (configurable by caller)</li></ul> |
| [`getSignaturesForAddress`](https://solana.com/de/docs/rpc/http/getsignaturesforaddress) | :white_check_mark: | <ul><li>Use the field `before` to have idempotent responses</li></ul> |
| [`getSignatureStatuses`](https://solana.com/de/docs/rpc/http/getsignaturestatuses) | :scissors: | <ul><li>The field `confirmations` is removed from the response</li></ul><ul><li>The field `context` is removed from the response</li></ul> |
| [`getSlot`](https://solana.com/de/docs/rpc/http/getslot) | :hammer_and_wrench: | <ul><li>The result is rounded down (configurable by caller)</li></ul> |
| [`getTokenAccountBalance`](https://solana.com/de/docs/rpc/http/gettokenaccountbalance) | :scissors: | <ul><li>The field `context` is removed from the response</li></ul> |
| [`getTransaction`](https://solana.com/de/docs/rpc/http/gettransaction) | :scissors: | <ul><li>Only the `base64` and `base58` values for the `encoding` request parameter are supported.</li></ul> |
| [`sendTransaction`](https://solana.com/de/docs/rpc/http/sendtransaction) | :white_check_mark: | |
| Solana method | Support | Known limitations |
|-------------------------------------------------------------------------------------------------|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`getAccountInfo`](https://solana.com/de/docs/rpc/http/getaccountinfo) | :scissors: | <ul><li>The field `context` is removed from the response</li></ul> |
| [`getBalance`](https://solana.com/de/docs/rpc/http/getbalance) | :scissors: | <ul><li>The field `context` is removed from the response</li></ul> |
| [`getBlock`](https://solana.com/de/docs/rpc/http/getblock) | :scissors: | <ul><li>Only the `signatures` and `none` values for the `transactionDetails` request parameter are supported. If not specified, the default value is `none`.</li></ul><ul><li>The `encoding` request parameter is not supported.</li></ul> |
| [`getRecenPrioritizationFees`](https://solana.com/de/docs/rpc/http/getrecentprioritizationfees) | :hammer_and_wrench: | <ul><li>Returns a subset of the response (configurable by caller)</li></ul> |
| [`getSignaturesForAddress`](https://solana.com/de/docs/rpc/http/getsignaturesforaddress) | :white_check_mark: | <ul><li>Use the field `before` to have idempotent responses</li></ul> |
| [`getSignatureStatuses`](https://solana.com/de/docs/rpc/http/getsignaturestatuses) | :scissors: | <ul><li>The field `confirmations` is removed from the response</li></ul><ul><li>The field `context` is removed from the response</li></ul> |
| [`getSlot`](https://solana.com/de/docs/rpc/http/getslot) | :hammer_and_wrench: | <ul><li>The result is rounded down (configurable by caller)</li></ul> |
| [`getTokenAccountBalance`](https://solana.com/de/docs/rpc/http/gettokenaccountbalance) | :scissors: | <ul><li>The field `context` is removed from the response</li></ul> |
| [`getTransaction`](https://solana.com/de/docs/rpc/http/gettransaction) | :scissors: | <ul><li>Only the `base64` and `base58` values for the `encoding` request parameter are supported.</li></ul> |
| [`sendTransaction`](https://solana.com/de/docs/rpc/http/sendtransaction) | :white_check_mark: | |


## Supported Solana JSON-RPC Providers
Expand Down
1 change: 1 addition & 0 deletions canister/scripts/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ GET_BLOCK_PARAMS="(
commitment = opt variant { finalized };
transactionDetails = opt variant { signatures };
maxSupportedTransactionVersion = opt (0 : nat8);
rewards = opt false;
},
)"
CYCLES=$(dfx canister call sol_rpc getBlockCyclesCost "$GET_BLOCK_PARAMS" $FLAGS --output json | jq '.Ok' --raw-output || exit 1)
Expand Down
16 changes: 14 additions & 2 deletions canister/sol_rpc_canister.did
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ type GetBlockParams = record {
// Slot number of the block to fetch.
slot: Slot;
// Specifies what transaction details to include in the response.
// If this field is not specified, the default value of "none" will be used.
//
// *Warning:* If this value is not specified, the default value of `none` will be used, which
// is different from the default value in the Solana RPC API. This is because the default value
// of `full` for the Solana RPC API results in response sizes that are generally too large to
// be supported by the ICP.
transactionDetails: opt TransactionDetails;
// The commitment describes how finalized a block is at that point in time.
commitment: opt variant { confirmed; finalized };
Expand All @@ -379,6 +383,8 @@ type GetBlockParams = record {
// * If this parameter is omitted, only legacy transactions will be returned, and a block
// containing any versioned transaction will prompt the error.
maxSupportedTransactionVersion: opt nat8;
// Whether to populate the rewards array. If not provided, the default includes rewards.
rewards: opt bool;
};

// Unix timestamp (seconds since the Unix epoch).
Expand All @@ -387,7 +393,7 @@ type GetBlockParams = record {
type Timestamp = int64;

// The result of a Solana `getBlock` RPC method call.
// TODO XC-342: Add `transactions`, `signatures`, `rewards` and `num_reward_partitions` fields.
// TODO XC-342: Add `transactions` field.
type ConfirmedBlock = record {
// The blockhash of this block's parent, as base-58 encoded string; if the parent block is not
// available due to ledger cleanup, this field will return "11111111111111111111111111111111".
Expand All @@ -403,6 +409,12 @@ type ConfirmedBlock = record {
// The signatures of the transactions in this block. Included if the request parameter `transactionDetails` is not
// `none`.
signatures: opt vec Signature;
// Array of rewards distributed in this block.
rewards: opt vec Reward;
// The epoch rewards are distributed over `1 + numRewardPartition` blocks. See the
// [Partitioned Inflationary Rewards Distribution](https://docs.anza.xyz/proposals/partitioned-inflationary-rewards-distribution/)
// feature for more details.
numRewardPartition: opt nat64;
};

// Represents the result of a call to the `getBlock` Solana RPC method.
Expand Down
14 changes: 9 additions & 5 deletions canister/src/rpc_client/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,25 @@ impl From<GetBalanceParams> for (String, Option<GetBalanceConfig>) {
pub struct GetBlockParams(Slot, Option<GetBlockConfig>);

impl GetBlockParams {
pub fn get_transaction_details(&self) -> Option<&TransactionDetails> {
pub fn get_transaction_details(&self) -> Option<TransactionDetails> {
self.1
.as_ref()
.and_then(|config| config.transaction_details.as_ref())
.and_then(|config| config.transaction_details)
}

pub fn include_rewards(&self) -> Option<bool> {
self.1.as_ref().and_then(|config| config.rewards)
}
}

impl From<sol_rpc_types::GetBlockParams> for GetBlockParams {
fn from(params: sol_rpc_types::GetBlockParams) -> Self {
// TODO XC-342: Check if all config fields are null, and if so, serialize it as null.
// Currently, we do not want it to be null since rewards=false is not the default value.
// We always use a non-null config since the default value for `transaction_details` is
// `none` which is different from the Solana RPC API default of `full`.
let config = Some(GetBlockConfig {
encoding: None,
transaction_details: Some(params.transaction_details.unwrap_or_default()),
rewards: Some(false),
rewards: params.rewards,
commitment: params.commitment,
max_supported_transaction_version: params.max_supported_transaction_version,
});
Expand Down
3 changes: 3 additions & 0 deletions canister/src/rpc_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ impl GetBlockRequest {
match params.get_transaction_details() {
None | Some(TransactionDetails::None) => 2048,
Some(TransactionDetails::Signatures) => 512 * 1024,
} + match params.include_rewards() {
None | Some(true) => 256,
Some(false) => 0,
} + HEADER_SIZE_LIMIT,
);

Expand Down
8 changes: 3 additions & 5 deletions canister/src/rpc_client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ mod request_serialization_tests {
GetBlockParams::from(123),
)
.unwrap(),
json!([
123,
{"rewards": false, "transactionDetails": "none"}
]),
json!([123, {"transactionDetails": "none"}]),
);
assert_params_eq(
GetBlockRequest::get_block(
Expand All @@ -300,13 +297,14 @@ mod request_serialization_tests {
commitment: Some(GetBlockCommitmentLevel::Finalized),
max_supported_transaction_version: Some(2u8),
transaction_details: Some(TransactionDetails::Signatures),
rewards: Some(true),
},
)
.unwrap(),
json!([
123,
{
"rewards": false,
"rewards": true,
"transactionDetails": "signatures",
"commitment": "finalized",
"maxSupportedTransactionVersion": 2
Expand Down
Loading