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

Fix contract hang #32

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- ./seed-backup.json:/root/.vsc-seed-backup.json
- ./.git/refs/heads/main:/root/git_commit
- ./src:/home/github/app/src
- ./dist:/home/github/app/dist

mongo:
container_name: mongo_vsc_dev
Expand Down
3 changes: 3 additions & 0 deletions src/services/new/contractEngineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class VmContext {

async init() {
let args = {
debug: true,
state: {

},
Expand All @@ -61,7 +62,9 @@ class VmContext {
}
this.vm = new VmContainer(args)

console.log('vm init')
await this.vm.init()
console.log('vm readying')
await this.vm.onReady()
}

Expand Down
7 changes: 5 additions & 2 deletions src/services/new/vm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,11 @@ export class VmContainer {
this.child.kill()
}

onReady() {
return new Promise((resolve) => {
async onReady() {
if (this.ready) {
return
}
return new Promise<void>((resolve) => {
this.events.on('ready', resolve)
})
}
Expand Down
11 changes: 9 additions & 2 deletions src/services/new/vm/vm-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,12 @@ class VmRunner {

let modules = {}
for (let [contract_id, code] of Object.entries<string>(this.modules)) {
const binaryData = await ipfs.block.get(IPFS.CID.parse(code))
modules[contract_id] = await WebAssembly.compile(binaryData)
const binaryData = await ipfs.dag.get(IPFS.CID.parse(code))
try {
modules[contract_id] = await WebAssembly.compile(binaryData.value)
} catch (e) {
console.error(`invalid contract code ${contract_id}`, e)
vaultec81 marked this conversation as resolved.
Show resolved Hide resolved
}
}

let state = {}
Expand Down Expand Up @@ -763,6 +767,7 @@ class VmRunner {
type: 'execute-stop',
ret: str,
logs,
error: null,
// reqId: message.reqId,
IOGas,
}
Expand All @@ -785,6 +790,7 @@ class VmRunner {
return {
type: 'execute-stop',
ret: null,
error: ex.toString(),
errorType: ContractErrorType.RUNTIME_UNKNOWN,
logs,
// reqId: message.reqId,
Expand All @@ -798,6 +804,7 @@ class VmRunner {
type: 'execute-stop',
ret: null,
logs,
error: ex.toString(),
errorType: ContractErrorType.RUNTIME_SETUP,
// reqId: message.reqId,
IOGas,
Expand Down
3 changes: 3 additions & 0 deletions src/services/new/witness/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export class WitnessServiceV2 {
console.log('contractIds', contractIds)
const vmContext = this.self.contractEngine.vmContext(contractIds);
await vmContext.init()
console.log('initalized vm')

let results: Record<string, Array<any>> = {

Expand All @@ -395,7 +396,9 @@ export class WitnessServiceV2 {
for(let tx of transactions) {
if(tx.data.contract_id) {
const contract_id = tx.data.contract_id
console.log('processing tx', JSON.stringify(tx, null, 2))
const contractCallResult = await vmContext.processTx(tx)
console.log('completed tx', JSON.stringify(contractCallResult, null, 2))
if(!results[contract_id]) {
results[contract_id] = []
}
Expand Down