You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add new DefaultMachineRunner trait for initialization work (#470)
* feat: Add new DefaultMachineRunner trait for initialization work
Previously, all different machines in ckb-vm might use slightly
different initialization process. This commit introduces a new
DefaultMachineRunner trait, so the same initialization & usage workflow
can be used for all types implementing this trait.
This is a cherry-pick of #469
to the develop branch. 2 more changes are applied on the develop branch:
* Since AsmCoreMachine is now constant, we can simply use AsmCoreMachine
instead of `Box<AsmCoreMachine>`.
* #343 was mostly reverted. Upon
more thinking, I think the change earlier does not make sense now. It's better
we provide unified initialization for the whole machine, not just for the memory
part.
Due to the new InstDecoder / TraceDecoder structure introduced in develop
branch, more changes are required in the develop branch than 0.24.x releases.
Some of those changes include:
* Assembly machines now require TraceDecoder instead of InstDecoder. This means
we cannot use DefaultMachineBuilder to build DefaultMachine structures for both
types of VMs. The assembly machine types require more constraints. Given this
consideration, DefaultMachineBuilder is removed in this commit. 2 new types
RustDefaultMachineBuilder and AsmDefaultMachineBuilder are added for 2 types of
VMs respectively.
* A new set of types that begin with `Abstract`, such as AbstractDefaultMachineBuilder,
AbstractAsmMachine, AbstractTraceMachine are introduced. One is only expected to
use those types when one wants to tweak the inst/trace decoder used. Otherwise,
one is safe to pick AsmMachine/AsmDefaultMachineBuilder or TraceMachine/RustDefaultMachineBuilder.
So the current workflow is like following:
1. Pick a type implementing DefaultMachineRunner traits. Most likely, one would
pick either AsmMachine or TraceMachine.
2. Instantiate a core machine using DefaultMachineRunner::Inner::new.
3. Based on the type picked in step 1, use AsmDefaultMachineBuilder or
RustDefaultMachineBuilder to build a default machine with possible instruction
cycle func, syscalls and debugger plugin.
4. Finally, use DefaultMachineRunner::new to create the final runnable machine
from the default machine.
For advanced usages where the decoder is customized, one can use AbstractAsmMachine
or AbstractTraceMachine type. Then use AbstractDefaultMachineBuilder
to build the default machine. And finally create the runnable machine. All those
types accept an additional InstDecoder / TraceDecoder trait impl that allows one
to customize the decoder for optimizations.
* chore: Remove unneeded PhantomData
0 commit comments