Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { makeBlockTransaction } from '@entities/block-data/__fixtures__/block-builders';
import { address } from '@solana/kit';
import { ComputeBudgetProgram } from '@solana/web3.js';
import { ComputeBudgetProgram, type ParsedInstruction, PublicKey } from '@solana/web3.js';
import { Cluster } from '@utils/cluster';

import { alloc, writeUint32LE } from '@/app/shared/lib/bytes';

import { estimateRequestedComputeUnits, getReservedComputeUnits } from '../compute-units-schedule';
import {
estimateRequestedComputeUnits,
estimateRequestedComputeUnitsForParsedTransaction,
getReservedComputeUnits,
} from '../compute-units-schedule';

describe('getReservedComputeUnits', () => {
describe('mainnet', () => {
Expand Down Expand Up @@ -65,6 +69,14 @@ describe('getReservedComputeUnits', () => {
).toEqual(200_000);
});

it.each([
'Stake11111111111111111111111111111111111111',
'Config1111111111111111111111111111111111111',
'AddressLookupTab1e1111111111111111111111111',
])('should return default compute units for %s, which runs as a Core BPF program', programId => {
expect(getReservedComputeUnits({ cluster: Cluster.Mainnet, epoch: 1097n, programId })).toEqual(200_000);
});

it('should handle feature gate program migration correctly', () => {
// Before migration (epoch 753), feature gate is builtin
expect(
Expand Down Expand Up @@ -304,6 +316,17 @@ describe('estimateRequestedComputeUnits', () => {
expect(estimateRequestedComputeUnits(tx, 759n, Cluster.Mainnet)).toEqual(203_000);
});

// Mainnet 5aKTtG79yJycua2vNZQbWWsvaEv6qzsxmrVGsoSYQPVRhy9LpvnixFwm8ntFuapeV5ice5V9xLoUzta3oZg8ybfM logs
// `Stake11111111111111111111111111111111111111 consumed 12186 of 202850` after the System instruction used 150.
it('should reserve the default for a Stake instruction', () => {
const tx = createMockTransaction([
{ data: new Uint8Array([4, 0, 0, 0]), programId: '11111111111111111111111111111111' },
{ data: new Uint8Array([1, 0, 0, 0]), programId: 'Stake11111111111111111111111111111111111111' },
]);

expect(estimateRequestedComputeUnits(tx, 1097n, Cluster.Mainnet)).toEqual(203_000);
});

it('should handle feature gate program correctly across epochs', () => {
const tx = createMockTransaction([
{
Expand Down Expand Up @@ -439,3 +462,33 @@ describe('estimateRequestedComputeUnits', () => {
});
});
});

describe('estimateRequestedComputeUnitsForParsedTransaction', () => {
// Mainnet 5PjwEDEdNSLv7uYTe3cjoyRcqDA7PGVnGXq1LoH1LDEy17ymV4ePvPfZy3Gz8CLnS3LiPdyu9LhAUQUqkY45NRgf logs
// `Stake11111111111111111111111111111111111111 consumed 16053 of 200000 compute units`.
it('should reserve the default for an RPC-parsed Stake instruction', () => {
const delegate: ParsedInstruction = {
parsed: {
info: {
clockSysvar: 'SysvarC1ock11111111111111111111111111111111',
stakeAccount: '4otjzF3rD3ExDJw3UL4zhdUsiNXJKKT5Gnp1sadRYmvN',
stakeAuthority: '59L2oxymiQQ9Hvhh92nt8Y7nDYjsauFkdb3SybdnsG6h',
stakeConfigAccount: 'StakeConfig11111111111111111111111111111111',
stakeHistorySysvar: 'SysvarStakeHistory1111111111111111111111111',
voteAccount: 'H74qox1GASBWd94FWMyy6GVAbRVLf9SAMgbJ1tzSUAst',
},
type: 'delegate',
},
program: 'stake',
programId: new PublicKey('Stake11111111111111111111111111111111111111'),
};

expect(
estimateRequestedComputeUnitsForParsedTransaction(
{ message: { instructions: [delegate] } },
1097n,
Cluster.Mainnet,
),
).toEqual(200_000);
});
});
4 changes: 1 addition & 3 deletions app/entities/compute-unit/lib/compute-units-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ const BASE58_ENCODER = getBase58Encoder();
* Built-in programs that have minimal reserved compute units (3k)
* This list is based on the feature gate C9oAhLxDBm3ssWtJx1yBGzPY55r2rArHmN1pbQn6HogH
* Source: https://solana.com/docs/references/feature-gates/reserve-minimal-cus-for-builtins
* Stake, Config and Address Lookup Table run as Core BPF programs now, so the runtime reserves the default for them.
*/
const BUILTIN_PROGRAMS_3K: readonly string[] = [
'11111111111111111111111111111111', // System Program
'Stake11111111111111111111111111111111111111', // Stake Program

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question/issue: Removing Stake and ALT from BUILTIN_PROGRAMS_3K changes the reserve for every epoch, so transactions from before each migration show 200,000 where master shows the correct 3,000. I think it's an issue and we should take epoch into account. What do you think @Woody4618 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good point, i added an entry for each migration, so alt keeps 3k until epoch 762 and stake until 823 on mainnet (devnet 849/917, testnet 756/813). config was already core bpf before the 3k change on every cluster, now it stays out of the list

'Config1111111111111111111111111111111111111', // Config Program
'AddressLookupTab1e1111111111111111111111111', // Address Lookup Table Program
'BPFLoaderUpgradeab1e11111111111111111111111', // BPF Loader Upgradeable
'BPFLoader1111111111111111111111111111111111', // BPF Loader
'BPFLoader2111111111111111111111111111111111', // BPF Loader 2
Expand Down