Commit 5f6b460515d272f0c4dcfce10ff08f1efd953318
create parentPort for root contract
wanderer committed on 5/7/2017, 11:28:59 AMParent: 3caa963721b6de8700ae2769edf1ce8f78bc0718
Files changed
index.js | changed |
kernel.js | changed |
portManager.js | changed |
tests/index.js | changed |
index.js | ||
---|---|---|
@@ -16,9 +16,9 @@ | ||
16 | 16 | // load the container from the state |
17 | 17 | await this.graph.tree(port, 2) |
18 | 18 | const parentID = await this.generateID(port.id['/'].parent) |
19 | 19 | const parentKernel = await this._vmInstances.get(parentID) |
20 | - const parentPort = parentKernel.entryPort | |
20 | + const parentPort = parentKernel.entryPort || null | |
21 | 21 | |
22 | 22 | kernel = await this.createInstanceFromPort(port, parentPort) |
23 | 23 | // don't delete the root contracts |
24 | 24 | if (id) { |
kernel.js | ||
---|---|---|
@@ -112,8 +112,9 @@ | ||
112 | 112 | |
113 | 113 | // returns a promise that resolves once the kernel hits the threshould tick |
114 | 114 | // count |
115 | 115 | async wait (threshold, fromPort) { |
116 | + console.log('wait', threshold, fromPort, this.ticks, this.vmState, this.entryPort) | |
116 | 117 | if (threshold <= this.ticks) { |
117 | 118 | return this.ticks |
118 | 119 | } else if (this.vmState === 'idle') { |
119 | 120 | return this.ports.wait(threshold, fromPort) |
portManager.js | ||
---|---|---|
@@ -37,10 +37,12 @@ | ||
37 | 37 | }) |
38 | 38 | |
39 | 39 | // create the parent port |
40 | 40 | 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 | + } | |
43 | 45 | } |
44 | 46 | |
45 | 47 | async _mapPort (name, port) { |
46 | 48 | const id = await this.hypervisor.generateID(port) |
@@ -67,16 +69,16 @@ | ||
67 | 69 | } |
68 | 70 | |
69 | 71 | // waits till all ports have reached a threshold tick count |
70 | 72 | async wait (threshold, fromPort) { |
71 | - // console.log('wait', threshold, 'id', this.entryPort) | |
72 | 73 | // find the ports that have a smaller tick count then the threshold tick count |
73 | 74 | const unkownPorts = [...this._portMap].filter(([id, port]) => { |
74 | 75 | return (port.hasSent || port.name === ENTRY) && |
75 | 76 | port.ticks < threshold && |
76 | 77 | fromPort !== port |
77 | 78 | }) |
78 | 79 | |
80 | + // console.log(unkownPorts, this.entryPort) | |
79 | 81 | const promises = unkownPorts.map(async ([id, port]) => { |
80 | 82 | const portObj = port.name === ENTRY ? this.parentPort : this.ports[port.name] |
81 | 83 | // update the port's tick count |
82 | 84 | port.ticks = await this.hypervisor.wait(portObj, threshold, this.entryPort) |
tests/index.js | ||
---|---|---|
@@ -22,9 +22,9 @@ | ||
22 | 22 | console.log(err) |
23 | 23 | }) |
24 | 24 | |
25 | 25 | node.on('start', () => { |
26 | - tape.only('basic', async t => { | |
26 | + tape('basic', async t => { | |
27 | 27 | const message = new Message() |
28 | 28 | const expectedState = { |
29 | 29 | '/': 'zdpuAntkdU7yBJojcBT5Q9wBhrK56NmLnwpHPKaEGMFnAXpv7' |
30 | 30 | } |
@@ -34,22 +34,26 @@ | ||
34 | 34 | t.true(m === message, 'should recive a message') |
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
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) | |
40 | 41 | |
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') | |
43 | 44 | |
44 | - await rootContainer.send(port, message) | |
45 | + await rootContainer.send(port, message) | |
45 | 46 | |
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 | + } | |
48 | 52 | t.end() |
49 | 53 | }) |
50 | 54 | |
51 | - tape('one child contract', async t => { | |
55 | + tape.only('one child contract', async t => { | |
52 | 56 | let message = new Message() |
53 | 57 | const expectedState = { '/': 'zdpuAqtY43BMaTCB5nTt7kooeKAWibqGs44Uwy9jJQHjTnHRK' } |
54 | 58 | let hasResolved = false |
55 | 59 | |
@@ -67,13 +71,14 @@ | ||
67 | 71 | } |
68 | 72 | |
69 | 73 | class testVMContainer extends BaseContainer { |
70 | 74 | async run (m) { |
75 | + // console.log('here', this.kernel.entryPort) | |
71 | 76 | const port = await this.kernel.createPort('test2', 'child') |
72 | 77 | try { |
73 | 78 | await this.kernel.send(port, m) |
74 | 79 | } catch (e) { |
75 | - console.log(e) | |
80 | + console.log('error!', e) | |
76 | 81 | } |
77 | 82 | this.kernel.incrementTicks(1) |
78 | 83 | } |
79 | 84 | } |
Built with git-ssb-web