Open Stebalien opened 2 years ago
We can get better guarantees in rust by;
trait ReadStore { fn get(&self, mh_code: Code, block: &Block) -> Result<Cid>; } trait WriteStore: ReadStore { fn put(&self, mh_code: Code, block: &Block) -> Result<Cid>; } trait TransactionRuntime { type WriteStore: WriteStore; type ReadStore: ReadStore; // Reading state is always fine. fn state<C: Cbor>(&self) -> Result<C, ActorError>; fn store(&self) -> Result<&Self::ReadStore, ActorError>; fn resolve_address(&self, address: &Address) -> Option<Address>; fn current_balance(&self) -> TokenAmount; // etc... } trait FullRuntime: TransactionRuntime { type TransactionRuntime: TransactionRuntime; // 1. Inside the closure, the actor cannot use the FullRuntime // (cannot send, cannot open new transactions). // 2. Outside the closure, the actor cannot create new blocks. The actor cannot // keep a reference to the writeable blockstore either. fn transaction<R>( &mut self, f: impl FnOnce( &mut Self::TransactionRuntime, &Self::WriteStore, &mut impl Cbor, ) -> Result<R, ActorError>, ); // Cannot be called in a transaction. fn send( &mut self, to: Address, method: MethodNum, params: RawBytes, value: TokenAmount, ) -> Result<RawBytes, ActorError>; }
(This is not required for FVM M1 and can be potentially built by the rust SDK level.
We can get better guarantees in rust by;