anchor
anchor copied to clipboard
AccountSysvarMismatch while using SlotHashes sysvar
Program:
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
mod sysvars_test {
use super::*;
pub fn sysvars(_ctx: Context<Sysvars>) -> Result<()> {
Ok(())
}
}
#[derive(Accounts)]
pub struct Sysvars<'info> {
pub clock: Sysvar<'info, Clock>,
pub rent: Sysvar<'info, Rent>,
pub stake_history: Sysvar<'info, StakeHistory>,
pub slot_hashes: Sysvar<'info, SlotHashes>,
}
Test:
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { SysvarsTest } from "../target/types/sysvars_test";
describe("sysvars-test", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.SysvarsTest as Program<SysvarsTest>;
it("Is initialized!", async () => {
const tx = await program.methods
.sysvars()
.accounts({
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
stakeHistory: anchor.web3.SYSVAR_STAKE_HISTORY_PUBKEY,
slotHashes: anchor.web3.SYSVAR_SLOT_HASHES_PUBKEY
})
.rpc();
console.log("Your transaction signature", tx);
});
});
throws an error Error: AnchorError caused by account: slot_hashes. Error Code: AccountSysvarMismatch. Error Number: 3015. Error Message: The given public key does not match the required sysvar.
while using anchor-test
. If i remove SYSVAR_SLOT_HASHES_PUBKEY
and slot_hashes
it works.
closing for now...might be a local issue, cannot reproduce. consider rimraffing and getting a fresh clone of the repository.
feel free to reopen if the issue persists.
@mentalrob Hello, did you figure the issue? I am getting the same issue as above.
).accounts({
player: provider.wallet.publicKey,
playerStats: playerStatsPDA,
game: playerGamePDA,
depositWallet: depositWallet,
slotHashes: anchor.web3.SYSVAR_SLOT_HASHES_PUBKEY,
}).rpc().catch((err) => {
pub system_program: Program<'info, System>,
pub slot_hashes: Sysvar<'info, SlotHashes>
}
Is initialized!:
Error: AnchorError caused by account: slot_hashes. Error Code: AccountSysvarMismatch. Error Number: 3015. Error Message: The given public key does not match the required sysvar.
I couldn't fixed it, used a nasty workaround
@mentalrob thanks for quick reply. Is it possible to share the workaround?
@callensm Can we reopen this ticket?
I get the slothash offchain and giving it to the program as a parameter
I get the slothash offchain and giving it to the program as a parameter
oh okay, is there a way to validate/verify the hash sent from client offchain is not fake?
I am still getting this error when trying to use Sysvar SlotHashes
> Program log: AnchorError caused by account: recent_slothashes. Error Code: AccountSysvarMismatch. Error Number: 3015. Error Message: The given public key does not match the required sysvar.```
Getting this error as well. Only for this sysvar.
Ah, here is why. SlotHashes doesn't support from_account_info
.
https://github.com/solana-labs/solana/blob/e9a6bb35e2636275137fc47837f5afce4dbcf630/sdk/program/src/sysvar/slot_hashes.rs#L61
The goal of this sysvar is to be used off chain