-
Notifications
You must be signed in to change notification settings - Fork 41
Description
I'm running into cases where I need to "clone" a VM so that I can run multiple go-routines with the "same" VM concurrently (cloning so that I can avoid downstream panics from concurrent read/writes).
Pseudo code like:
for range N {
wg.Add(1)
go func() {
defer wg.Done()
snapshotCopy := vm.Snapshot()
useVm, err := w3vm.New(
w3vm.WithFork(w3Client, vmBlock),
w3vm.WithStateDB(snapshotCopy),
)
if err != nil {
return nil, err
}
DoStuffWithVM(useVm)
}
}
Note vmBlock there - which, in my test cases, I am passing in to have it correspond with the parent VM I passed. Plus, having to take the snapshot to copy the stateDB.
This is "fine" but unwieldy, especially in a test case where I want to WithTB - it feels wrong to be passing testing.T into non-test code, amongst all the other arguments needed to recreate an identical vm and have to be drilled all the way down into some child function call.
It'd be great if there was a VM.Clone() that returned a new VM, copying all the opts / config / db from its parent. Then I can just pass VM around and call Clone() if some downstream thing suddenly needs separate routines. Rather than having to pass all sorts of stuff all the way down a function chain.
Thank you for considering this proposal!