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

Add support for new compute budget instruction #411

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 48 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//@ts-check

// https://pnpm.io/pnpmfile
// https://github.com/pnpm/pnpm/issues/4214
// https://github.com/pnpm/pnpm/issues/5391

const rootPkg = require('./package.json');

console.log (`Checking for package peerDependency overrides`);

const remapPeerDependencies = [
{ package: '@solana-program/compute-budget', packageVersion: '0.6.1', peerDependency: '@solana/web3.js', newVersion: '2.0.0' },
];

function overridesPeerDependencies(pkg) {
if (pkg.peerDependencies) {
remapPeerDependencies.map(dep => {
if (pkg.name === dep.package && pkg.version.startsWith(dep.packageVersion)) {
console.log(` - Checking ${pkg.name}@${pkg.version}`); // , pkg.peerDependencies);

if (dep.peerDependency in pkg.peerDependencies) {
try {
console.log(` - Overriding ${pkg.name}@${pkg.version} peerDependency ${dep.peerDependency}@${pkg.peerDependencies[dep.peerDependency]}`);

// First add a new dependency to the package and then remove the peer dependency.
// This approach has the added advantage that scoped overrides should now work, too.
pkg.dependencies[dep.peerDependency] = dep.newVersion;
delete pkg.peerDependencies[dep.peerDependency];

console.log(` - Overrode ${pkg.name}@${pkg.version} peerDependency ${dep.peerDependency}@${pkg.dependencies[dep.peerDependency]}`);
} catch (err) {
console.error(err);
}
}
}
});
}
}

module.exports = {
hooks: {
readPackage(pkg, _context) {
// skipDeps(pkg);
overridesPeerDependencies(pkg);
return pkg;
},
},
};
74 changes: 64 additions & 10 deletions app/components/instruction/ComputeBudgetDetailsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Address } from '@components/common/Address';
import { SolBalance } from '@components/common/SolBalance';
import { useCluster } from '@providers/cluster';
import { ComputeBudgetInstruction, SignatureResult, TransactionInstruction } from '@solana/web3.js';
import { SignatureResult, TransactionInstruction } from '@solana/web3.js';
import {
ComputeBudgetInstruction,
identifyComputeBudgetInstruction,
parseRequestHeapFrameInstruction,
parseRequestUnitsInstruction,
parseSetComputeUnitLimitInstruction,
parseSetComputeUnitPriceInstruction,
parseSetLoadedAccountsDataSizeLimitInstruction,
} from '@solana-program/compute-budget';
import { microLamportsToLamportsString } from '@utils/index';
import React from 'react';
import { address } from 'web3js-experimental';

import { InstructionCard } from './InstructionCard';

Expand All @@ -24,10 +34,15 @@ export function ComputeBudgetDetailsCard({
}) {
const { url } = useCluster();
try {
const type = ComputeBudgetInstruction.decodeInstructionType(ix);
const type = identifyComputeBudgetInstruction(ix);
switch (type) {
case 'RequestUnits': {
const { units, additionalFee } = ComputeBudgetInstruction.decodeRequestUnits(ix);
case ComputeBudgetInstruction.RequestUnits: {
const {
data: { units, additionalFee },
} = parseRequestUnitsInstruction({
...ix,
programAddress: address(ix.programId.toBase58()),
});
return (
<InstructionCard
ix={ix}
Expand Down Expand Up @@ -60,8 +75,10 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case 'RequestHeapFrame': {
const { bytes } = ComputeBudgetInstruction.decodeRequestHeapFrame(ix);
case ComputeBudgetInstruction.RequestHeapFrame: {
const {
data: { bytes },
} = parseRequestHeapFrameInstruction({ ...ix, programAddress: address(ix.programId.toBase58()) });
return (
<InstructionCard
ix={ix}
Expand All @@ -87,8 +104,10 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case 'SetComputeUnitLimit': {
const { units } = ComputeBudgetInstruction.decodeSetComputeUnitLimit(ix);
case ComputeBudgetInstruction.SetComputeUnitLimit: {
const {
data: { units },
} = parseSetComputeUnitLimitInstruction({ ...ix, programAddress: address(ix.programId.toBase58()) });
return (
<InstructionCard
ix={ix}
Expand All @@ -114,8 +133,13 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case 'SetComputeUnitPrice': {
const { microLamports } = ComputeBudgetInstruction.decodeSetComputeUnitPrice(ix);
case ComputeBudgetInstruction.SetComputeUnitPrice: {
const {
data: { microLamports },
} = parseSetComputeUnitPriceInstruction({
...ix,
programAddress: address(ix.programId.toBase58()),
});
return (
<InstructionCard
ix={ix}
Expand All @@ -141,6 +165,36 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit: {
const {
data: { accountDataSizeLimit },
} = parseSetLoadedAccountsDataSizeLimitInstruction({
...ix,
programAddress: address(ix.programId.toBase58()),
});
return (
<InstructionCard
ix={ix}
index={index}
result={result}
title="Compute Budget Program: Set Loaded Account Data Size Limit"
innerCards={innerCards}
childIndex={childIndex}
>
<tr>
<td>Program</td>
<td className="text-lg-end">
<Address pubkey={ix.programId} alignRight link />
</td>
</tr>

<tr>
<td>Account Data Size Limit</td>
<td className="text-lg-end font-monospace">{`${accountDataSizeLimit} bytes`}</td>
</tr>
</InstructionCard>
);
}
}
} catch (error) {
console.error(error, {
Expand Down
21 changes: 13 additions & 8 deletions app/providers/stats/solanaClusterStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import useTabVisibility from 'use-tab-visibility';
import { createSolanaRpc } from 'web3js-experimental';

import { DashboardInfo, DashboardInfoActionType, dashboardInfoReducer, EpochInfo } from './solanaDashboardInfo';
import { PerformanceInfo, PerformanceInfoActionType, performanceInfoReducer, PerformanceSample } from './solanaPerformanceInfo';
import {
PerformanceInfo,
PerformanceInfoActionType,
performanceInfoReducer,
PerformanceSample,
} from './solanaPerformanceInfo';

export const PERF_UPDATE_SEC = 5;
export const SAMPLE_HISTORY_HOURS = 6;
Expand Down Expand Up @@ -51,11 +56,11 @@ const initialDashboardInfo: DashboardInfo = {
type SetActive = React.Dispatch<React.SetStateAction<boolean>>;
const StatsProviderContext = React.createContext<
| {
setActive: SetActive;
setTimedOut: () => void;
retry: () => void;
active: boolean;
}
setActive: SetActive;
setTimedOut: () => void;
retry: () => void;
active: boolean;
}
| undefined
>(undefined);

Expand Down Expand Up @@ -159,7 +164,7 @@ export function SolanaClusterStatsProvider({ children }: Props) {
epoch: epochInfoResponse.epoch,
slotIndex: epochInfoResponse.slotIndex,
slotsInEpoch: epochInfoResponse.slotsInEpoch,
}
};

if (stale) {
return;
Expand Down Expand Up @@ -193,7 +198,7 @@ export function SolanaClusterStatsProvider({ children }: Props) {
}
dispatchDashboardInfo({
data: {
blockTime: blockTime * 1000,
blockTime: Number(blockTime) * 1000,
slot: lastSlot,
},
type: DashboardInfoActionType.SetLastBlockTime,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@project-serum/serum": "^0.13.61",
"@react-hook/debounce": "^4.0.0",
"@react-hook/previous": "^1.0.1",
"@solana-program/compute-budget": "^0.6.1",
"@solana/buffer-layout": "^3.0.0",
"@solana/spl-account-compression": "^0.1.8",
"@solana/spl-token": "^0.1.8",
Expand Down Expand Up @@ -61,7 +62,7 @@
"typescript": "5.0.4",
"use-async-effect": "^2.2.7",
"use-tab-visibility": "^1.0.9",
"web3js-experimental": "npm:@solana/[email protected]-rc.0"
"web3js-experimental": "npm:@solana/[email protected]"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.1",
Expand Down
Loading
Loading