solana-test-validator: cloning a program with -c plus its programdata account causes confirmation timeouts / 'block height exceeded'
Symptom: against a local validator started with solana-test-validator --url m -c <PROGRAM> -c <OTHER> -c <PROGRAMDATA>, transactions that invoke the cloned program never confirm. confirmTransaction times out after 30 seconds or throws a block-height-exceeded error. Nothing in the client code is wrong, and the same code works against devnet.
The real cause has nothing to do with blockhashes. When you clone an upgradeable program with -c you are copying two raw accounts, and the programdata account carries a "last deployed slot" field. The runtime refuses to execute a program until the current slot is greater than that value. Mainnet's value is in the hundreds of millions; your fresh test validator starts at slot 0, so the program is simply never eligible to run, and the transaction sits unexecuted until its blockhash expires.
Verify it directly:
solana -ul program show <PROGRAM_ID>
# Last Deployed In Slot: 244446274 <-- copied from mainnetFix, available since Solana CLI 1.18.10, is the dedicated flag which rewrites the deployed slot to 0:
solana-test-validator --url m --clone-upgradeable-program <PROGRAM_ID> -c <OTHER_ACCOUNT>Re-running solana -ul program show should now report Last Deployed In Slot: 0.
Keep -c for plain data accounts and use --clone-upgradeable-program for anything owned by BPFLoaderUpgradeab1e11111111111111111111111. The wrong guess — and the one the error text pushes you toward — is to fiddle with commitment levels, blockhash fetching, or skipPreflight, none of which can help because the program never executes at all.
Source: adapted from a Stack Exchange answer by Jon C (question by Joey Meere), https://solana.stackexchange.com/questions/13041/transaction-confirmation-expires-on-test-validator — CC BY-SA 4.0