-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #872 from o1-labs/feature/workers-when-needed-new
Start workers only when needed
- Loading branch information
Showing
46 changed files
with
718 additions
and
1,067 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import fs from 'node:fs/promises'; | ||
|
||
const file = process.argv[2]; | ||
|
||
let src = await fs.readFile(file, 'utf8'); | ||
|
||
src = src.replace( | ||
"imports['env'] = require('env');", | ||
` | ||
let { isMainThread, workerData } = require('worker_threads'); | ||
let env = {}; | ||
if (isMainThread) { | ||
env.memory = new WebAssembly.Memory({ | ||
initial: 20, | ||
maximum: 65536, | ||
shared: true, | ||
}); | ||
} else { | ||
env.memory = workerData.memory; | ||
} | ||
imports['env'] = env; | ||
` | ||
); | ||
|
||
await fs.writeFile(file, src, 'utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Tests that snarkyjs can be imported and used from commonJS files | ||
*/ | ||
let { | ||
Field, | ||
State, | ||
PrivateKey, | ||
SmartContract, | ||
Mina, | ||
AccountUpdate, | ||
declareState, | ||
declareMethods, | ||
} = require('snarkyjs'); | ||
|
||
class SimpleZkapp extends SmartContract { | ||
constructor(address) { | ||
super(address); | ||
this.x = State(); | ||
} | ||
|
||
events = { update: Field }; | ||
|
||
init() { | ||
super.init(); | ||
this.x.set(initialState); | ||
} | ||
|
||
update(y) { | ||
this.emitEvent('update', y); | ||
this.emitEvent('update', y); | ||
this.account.balance.assertEquals(this.account.balance.get()); | ||
let x = this.x.get(); | ||
this.x.assertEquals(x); | ||
this.x.set(x.add(y)); | ||
} | ||
} | ||
declareState(SimpleZkapp, { x: Field }); | ||
declareMethods(SimpleZkapp, { update: [Field] }); | ||
|
||
let Local = Mina.LocalBlockchain(); | ||
Mina.setActiveInstance(Local); | ||
|
||
let feePayerKey = Local.testAccounts[0].privateKey; | ||
let feePayer = Local.testAccounts[0].publicKey; | ||
|
||
let zkappKey = PrivateKey.random(); | ||
let zkappAddress = zkappKey.toPublicKey(); | ||
|
||
let initialState = Field(1); | ||
let zkapp = new SimpleZkapp(zkappAddress); | ||
|
||
main(); | ||
|
||
async function main() { | ||
console.log('compile'); | ||
await SimpleZkapp.compile(); | ||
|
||
console.log('deploy'); | ||
let tx = await Mina.transaction(feePayer, () => { | ||
AccountUpdate.fundNewAccount(feePayer); | ||
zkapp.deploy(); | ||
}); | ||
await tx.sign([feePayerKey, zkappKey]).send(); | ||
|
||
console.log('initial state: ' + zkapp.x.get()); | ||
|
||
console.log('update'); | ||
tx = await Mina.transaction(feePayer, () => zkapp.update(Field(3))); | ||
await tx.prove(); | ||
await tx.sign([feePayerKey]).send(); | ||
console.log('final state: ' + zkapp.x.get()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.