Skip to content

Project 9 Token Lottery - "Program log: AnchorError occurred. Error Code: RandomnessAlreadyRevealed. Error Number: 6004. Error Message: Randomness already revealed." #45

@pzpzpz

Description

@pzpzpz

hello, when I send transaction including randomness commit instruction and my program commit instruction together,
just like the following:

    const sbCommitIx = await randomness.commitIx(sb.ON_DEMAND_DEVNET_QUEUE);
    const commitIx = await program.methods
      .commitAWinner()
      .accounts({
        randomnessAccountData: randomness.pubkey,
      })
      .instruction();

    const commitTx = await sb.asV0Tx({
      connection: switchboardProgram.provider.connection,
      ixs: [sbCommitIx, commitIx],
      payer: wallet.publicKey,
      signers: [wallet.payer],
      computeUnitPrice: 75_000,
      computeUnitLimitMultiple: 1.3,
    });

    const commitSignature = await connection.sendTransaction(commitTx);

it will fail with logs:

- Error: Simulation failed.
- Message: Transaction simulation failed: Error processing Instruction 1: custom program error: 0x1774.
- Logs:
- [
-   "Program log: SEED_SLOT: 383132566",
-   "Program log: SEED_SLOTHASH: [84, 96, 99, 175, 3, 67, 25, 176, 108, 21, 48, 139, 161, 129, 32, 225, 111, 135, 169, 61, 182, 23, 208, 35, 242, 14, 68, 147, 176, 48, 131, 51]",
-   "Program data: WDysWnAKzpMr1p9mh94R5L4j08FosPBP+y7z1xu72PHVGrJT0pHtI+dVu00IozrVVkRgFIa0l2mm8cQ/Zt/at+A58+xKMVhfliPWFgAAAABUYGOvA0MZsGwVMIuhgSDhb4epPbYX0CPyDkSTsDCDMw==",
-   "Program Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2 consumed 16978 of 28433 compute units",
-   "Program Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2 success",
-   "Program AR4nA8QFekt4FwAe96pRBPJEjZEG6kcbAuQfGZdfus3W invoke [1]",
-   "Program log: Instruction: CommitAWinner",
-   "Program log: AnchorError occurred. Error Code: RandomnessAlreadyRevealed. Error Number: 6004. Error Message: Randomness already revealed.",
-   "Program AR4nA8QFekt4FwAe96pRBPJEjZEG6kcbAuQfGZdfus3W consumed 5002 of 11455 compute units",
-   "Program AR4nA8QFekt4FwAe96pRBPJEjZEG6kcbAuQfGZdfus3W failed: custom program error: 0x1774"
- ].

This error should have occurred in these lines of code in program:

pub fn commit_a_winner(ctx: Context<CommitWinner>) -> Result<()> {
......
if randomness_data.seed_slot != clock.slot - 1 {
         return Err(ErrorCode::RandomnessAlreadyRevealed.into());
     }
......
}

but when I set “skipPreflight” to “true” on send option in the last line like this:

 const commitSignature = await connection.sendTransaction(commitTx, {
      skipPreflight: true,
    });

the transaction secceed to send and confirm!!!
Is there anyone can explain this?
Thanks you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions