Skip to content

Commit

Permalink
refactor(experimental): added unsafe f64 type (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec authored Aug 25, 2023
1 parent 4f2f123 commit d0412ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 9 additions & 0 deletions packages/rpc-core/src/rpc-methods/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export type Slot = U64UnsafeBeyond2Pow53Minus1;
// the JSON-RPC transport.
export type U64UnsafeBeyond2Pow53Minus1 = bigint;

// FIXME(solana-labs/solana/issues/30341)
// <https://stackoverflow.com/questions/45929493/node-js-maximum-safe-floating-point-number/57225494#57225494>
// Beware that floating-point value precision can vary widely:
// - For precision of 1 decimal place, anything above 562949953421311
// - For precision of 2 decimal places, anything above 70368744177663
// can be truncated or rounded because of a downcast to JavaScript `number` between your calling
// code and the JSON-RPC transport.
export type F64UnsafeSeeDocumentation = number;

export type RpcResponse<TValue> = Readonly<{
context: Readonly<{
slot: Slot;
Expand Down
12 changes: 6 additions & 6 deletions packages/rpc-core/src/rpc-methods/getInflationGovernor.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Commitment } from './common';
import { Commitment, F64UnsafeSeeDocumentation } from './common';

type GetInflationGovernorApiResponse = Readonly<{
/** The initial inflation percentage from time 0 */
initial: number; // Until we land on best type for `f64`
initial: F64UnsafeSeeDocumentation;
/** Percentage of total inflation allocated to the foundation */
foundation: number; // Until we land on best type for `f64`
foundation: F64UnsafeSeeDocumentation;
/** Duration of foundation pool inflation in years */
foundationTerm: number; // Until we land on best type for `f64`
foundationTerm: F64UnsafeSeeDocumentation;
/**
* Rate per year at which inflation is lowered.
* (Rate reduction is derived using the target
* slot time in genesis config)
*/
taper: number; // Until we land on best type for `f64`
taper: F64UnsafeSeeDocumentation;
/** Terminal inflation percentage */
terminal: number; // Until we land on best type for `f64`
terminal: F64UnsafeSeeDocumentation;
}>;

export interface GetInflationGovernorApi {
Expand Down
8 changes: 4 additions & 4 deletions packages/rpc-core/src/rpc-methods/getInflationRate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { U64UnsafeBeyond2Pow53Minus1 } from './common';
import { F64UnsafeSeeDocumentation, U64UnsafeBeyond2Pow53Minus1 } from './common';

type GetInflationRateApiResponse = Readonly<{
/** Epoch for which these values are valid */
epoch: U64UnsafeBeyond2Pow53Minus1;
/** Inflation allocated to the foundation */
foundation: number; // Until we land on best type for `f64`
foundation: F64UnsafeSeeDocumentation;
/** Total inflation */
total: number; // Until we land on best type for `f64`
total: F64UnsafeSeeDocumentation;
/** Inflation allocated to validators */
validator: number; // Until we land on best type for `f64`
validator: F64UnsafeSeeDocumentation;
}>;

export interface GetInflationRateApi {
Expand Down

0 comments on commit d0412ab

Please sign in to comment.