Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDEA: Stronger transaction guarantees #137

Open
Stebalien opened this issue Mar 25, 2022 · 1 comment
Open

IDEA: Stronger transaction guarantees #137

Stebalien opened this issue Mar 25, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Stebalien
Copy link
Member

We can get better guarantees in rust by;

  1. Splitting the runtime into a "transaction runtime" and the "full runtime".
  2. Splitting the blockstore into a read/write half.
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>;
}
@jennijuju
Copy link
Member

(This is not required for FVM M1 and can be potentially built by the rust SDK level.

@anorth anorth added enhancement New feature or request good first issue Good for newcomers labels Aug 11, 2022
@Stebalien Stebalien removed the good first issue Good for newcomers label Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants