git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 5f6b460515d272f0c4dcfce10ff08f1efd953318

create parentPort for root contract

wanderer committed on 5/7/2017, 11:28:59 AM
Parent: 3caa963721b6de8700ae2769edf1ce8f78bc0718

Files changed

index.jschanged
kernel.jschanged
portManager.jschanged
tests/index.jschanged
index.jsView
@@ -16,9 +16,9 @@
1616 // load the container from the state
1717 await this.graph.tree(port, 2)
1818 const parentID = await this.generateID(port.id['/'].parent)
1919 const parentKernel = await this._vmInstances.get(parentID)
20- const parentPort = parentKernel.entryPort
20+ const parentPort = parentKernel.entryPort || null
2121
2222 kernel = await this.createInstanceFromPort(port, parentPort)
2323 // don't delete the root contracts
2424 if (id) {
kernel.jsView
@@ -112,8 +112,9 @@
112112
113113 // returns a promise that resolves once the kernel hits the threshould tick
114114 // count
115115 async wait (threshold, fromPort) {
116+ console.log('wait', threshold, fromPort, this.ticks, this.vmState, this.entryPort)
116117 if (threshold <= this.ticks) {
117118 return this.ticks
118119 } else if (this.vmState === 'idle') {
119120 return this.ports.wait(threshold, fromPort)
portManager.jsView
@@ -37,10 +37,12 @@
3737 })
3838
3939 // create the parent port
4040 await Promise.all(ports)
41- const id = await this.hypervisor.generateID(this.parentPort)
42- this._portMap.set(id, new Port(ENTRY))
41+ if (this.parentPort !== undefined) {
42+ const id = await this.hypervisor.generateID(this.parentPort)
43+ this._portMap.set(id, new Port(ENTRY))
44+ }
4345 }
4446
4547 async _mapPort (name, port) {
4648 const id = await this.hypervisor.generateID(port)
@@ -67,16 +69,16 @@
6769 }
6870
6971 // waits till all ports have reached a threshold tick count
7072 async wait (threshold, fromPort) {
71- // console.log('wait', threshold, 'id', this.entryPort)
7273 // find the ports that have a smaller tick count then the threshold tick count
7374 const unkownPorts = [...this._portMap].filter(([id, port]) => {
7475 return (port.hasSent || port.name === ENTRY) &&
7576 port.ticks < threshold &&
7677 fromPort !== port
7778 })
7879
80+ // console.log(unkownPorts, this.entryPort)
7981 const promises = unkownPorts.map(async ([id, port]) => {
8082 const portObj = port.name === ENTRY ? this.parentPort : this.ports[port.name]
8183 // update the port's tick count
8284 port.ticks = await this.hypervisor.wait(portObj, threshold, this.entryPort)
tests/index.jsView
@@ -22,9 +22,9 @@
2222 console.log(err)
2323 })
2424
2525 node.on('start', () => {
26- tape.only('basic', async t => {
26+ tape('basic', async t => {
2727 const message = new Message()
2828 const expectedState = {
2929 '/': 'zdpuAntkdU7yBJojcBT5Q9wBhrK56NmLnwpHPKaEGMFnAXpv7'
3030 }
@@ -34,22 +34,26 @@
3434 t.true(m === message, 'should recive a message')
3535 }
3636 }
3737
38- const hypervisor = new Hypervisor({dag: node.dag})
39- hypervisor.registerContainer('test', testVMContainer)
38+ try {
39+ const hypervisor = new Hypervisor({dag: node.dag})
40+ hypervisor.registerContainer('test', testVMContainer)
4041
41- const rootContainer = await hypervisor.createInstance('test')
42- const port = await rootContainer.createPort('test', 'first')
42+ const rootContainer = await hypervisor.createInstance('test')
43+ const port = await rootContainer.createPort('test', 'first')
4344
44- await rootContainer.send(port, message)
45+ await rootContainer.send(port, message)
4546
46- const stateRoot = await hypervisor.createStateRoot(rootContainer, Infinity)
47- t.deepEquals(stateRoot, expectedState, 'expected root!')
47+ const stateRoot = await hypervisor.createStateRoot(rootContainer, Infinity)
48+ t.deepEquals(stateRoot, expectedState, 'expected root!')
49+ } catch (e) {
50+ console.log(e)
51+ }
4852 t.end()
4953 })
5054
51- tape('one child contract', async t => {
55+ tape.only('one child contract', async t => {
5256 let message = new Message()
5357 const expectedState = { '/': 'zdpuAqtY43BMaTCB5nTt7kooeKAWibqGs44Uwy9jJQHjTnHRK' }
5458 let hasResolved = false
5559
@@ -67,13 +71,14 @@
6771 }
6872
6973 class testVMContainer extends BaseContainer {
7074 async run (m) {
75+ // console.log('here', this.kernel.entryPort)
7176 const port = await this.kernel.createPort('test2', 'child')
7277 try {
7378 await this.kernel.send(port, m)
7479 } catch (e) {
75- console.log(e)
80+ console.log('error!', e)
7681 }
7782 this.kernel.incrementTicks(1)
7883 }
7984 }

Built with git-ssb-web