I'm currently learning Solana development with Rust.
I'm trying to understand why do we have a Program Account and a Program Executable Data Account. I already know that the Program Account contains a reference to a Program Executable Data Account, and that the latter contains the actual code.
My question is why do we have to split the actual code from the Program Account into a separate account? My initial thoughts were:
- Maybe this has to do with being able to upgrade your program code. Maybe when you upgrade your program, a new Executable Data Account is created and the reference in the Program Account is updated.
That is not the case, since after upgrading a program, the reference (the address) to the Executable Data Account is the same.
- Maybe this has to do with ownership of accounts. Maybe one account is owned by the developer and the other by the BPF Program.
That is neither the case because both accounts are owned by the BPF Program, and the developer is just the Upgrade Authority
Why do we need 2 accounts for a program? Why not store the actual code in the data slot of the Program Account?
I hope this makes sense.