-
Notifications
You must be signed in to change notification settings - Fork 121
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
Unlimited account update support #1919
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b41ba14
add enforceTransactionLimits parameter for network
youtpout 0fee009
add test transaction
youtpout 3b43614
update enforce variable verification
youtpout b6e9023
remove console log from tests
youtpout 0aec72b
update changelog
youtpout 7e5fb96
rename test, change parameter name to bypassTransactionLimits
youtpout cdf9d17
Merge branch 'o1-labs:main' into zeko
youtpout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -104,21 +104,24 @@ function Network(options: { | |||||||||||||
mina: string | string[]; | ||||||||||||||
archive?: string | string[]; | ||||||||||||||
lightnetAccountManager?: string; | ||||||||||||||
enforceTransactionLimits?: boolean; | ||||||||||||||
}): Mina; | ||||||||||||||
function Network( | ||||||||||||||
options: | ||||||||||||||
| { | ||||||||||||||
networkId?: NetworkId; | ||||||||||||||
mina: string | string[]; | ||||||||||||||
archive?: string | string[]; | ||||||||||||||
lightnetAccountManager?: string; | ||||||||||||||
} | ||||||||||||||
networkId?: NetworkId; | ||||||||||||||
mina: string | string[]; | ||||||||||||||
archive?: string | string[]; | ||||||||||||||
lightnetAccountManager?: string; | ||||||||||||||
enforceTransactionLimits?: boolean; | ||||||||||||||
} | ||||||||||||||
| string | ||||||||||||||
): Mina { | ||||||||||||||
let minaNetworkId: NetworkId = 'testnet'; | ||||||||||||||
let minaGraphqlEndpoint: string; | ||||||||||||||
let archiveEndpoint: string; | ||||||||||||||
let lightnetAccountManagerEndpoint: string; | ||||||||||||||
let enforceTransactionLimits: boolean = true; | ||||||||||||||
|
||||||||||||||
if (options && typeof options === 'string') { | ||||||||||||||
minaGraphqlEndpoint = options; | ||||||||||||||
|
@@ -158,6 +161,11 @@ function Network( | |||||||||||||
lightnetAccountManagerEndpoint = options.lightnetAccountManager; | ||||||||||||||
Fetch.setLightnetAccountManagerEndpoint(lightnetAccountManagerEndpoint); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (options.enforceTransactionLimits !== undefined && | ||||||||||||||
typeof options.enforceTransactionLimits === 'boolean') { | ||||||||||||||
enforceTransactionLimits = options.enforceTransactionLimits; | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I still think this would be more understandable, while respecting the argument agreement with the other function |
||||||||||||||
} else { | ||||||||||||||
throw new Error( | ||||||||||||||
"Network: malformed input. Please provide a string or an object with 'mina' and 'archive' endpoints." | ||||||||||||||
|
@@ -251,7 +259,7 @@ function Network( | |||||||||||||
}, | ||||||||||||||
sendTransaction(txn) { | ||||||||||||||
return toPendingTransactionPromise(async () => { | ||||||||||||||
verifyTransactionLimits(txn.transaction); | ||||||||||||||
if (enforceTransactionLimits) verifyTransactionLimits(txn.transaction); | ||||||||||||||
|
||||||||||||||
let [response, error] = await Fetch.sendZkapp(txn.toJSON()); | ||||||||||||||
let errors: string[] = []; | ||||||||||||||
|
youtpout marked this conversation as resolved.
Show resolved
Hide resolved
|
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,200 @@ | ||
import { | ||
State, | ||
state, | ||
UInt64, | ||
Bool, | ||
SmartContract, | ||
Mina, | ||
AccountUpdate, | ||
method, | ||
PublicKey, | ||
Permissions, | ||
VerificationKey, | ||
Field, | ||
Int64, | ||
TokenId, | ||
TokenContract as TokenContractBase, | ||
AccountUpdateForest, | ||
PrivateKey, | ||
} from 'o1js'; | ||
|
||
|
||
|
||
const defaultNetwork = Mina.Network({ | ||
networkId: "testnet", | ||
mina: "https://example.com/graphql", | ||
archive: "https://example.com//graphql" | ||
}); | ||
|
||
const enforcedNetwork = Mina.Network({ | ||
networkId: "testnet", | ||
mina: "https://example.com/graphql", | ||
archive: "https://example.com//graphql", | ||
enforceTransactionLimits: true | ||
}); | ||
|
||
const unlimitedNetwork = Mina.Network({ | ||
networkId: "testnet", | ||
mina: "https://unlimited.com/graphql", | ||
archive: "https://unlimited.com//graphql", | ||
enforceTransactionLimits: false | ||
}); | ||
|
||
describe('Test default network', () => { | ||
let bobAccount: PublicKey, | ||
bobKey: PrivateKey; | ||
|
||
beforeAll(async () => { | ||
|
||
Mina.setActiveInstance(defaultNetwork); | ||
bobKey = PrivateKey.random(); | ||
bobAccount = bobKey.toPublicKey(); | ||
}); | ||
|
||
|
||
it('Simple account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(1)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
}); | ||
await txn.prove(); | ||
await txn.sign([bobKey]).safeSend(); | ||
|
||
}); | ||
|
||
it('Multiple account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
for (let index = 0; index < 2; index++) { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
} | ||
}); | ||
await txn.prove(); | ||
await txn.sign([bobKey]).safeSend(); | ||
|
||
}); | ||
|
||
it('More than limit account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
for (let index = 0; index < 12; index++) { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
} | ||
}); | ||
await txn.prove(); | ||
// failure with default enforceTransactionLimits | ||
await expect(txn.sign([bobKey]).safeSend()).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('Test enforced network', () => { | ||
let bobAccount: PublicKey, | ||
bobKey: PrivateKey; | ||
|
||
beforeAll(async () => { | ||
|
||
Mina.setActiveInstance(enforcedNetwork); | ||
bobKey = PrivateKey.random(); | ||
bobAccount = bobKey.toPublicKey(); | ||
}); | ||
|
||
|
||
it('Simple account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(1)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
}); | ||
await txn.prove(); | ||
await txn.sign([bobKey]).safeSend(); | ||
|
||
}); | ||
|
||
it('Multiple account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
for (let index = 0; index < 2; index++) { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
} | ||
}); | ||
await txn.prove(); | ||
await txn.sign([bobKey]).safeSend(); | ||
|
||
}); | ||
|
||
it('More than limit account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
for (let index = 0; index < 12; index++) { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
} | ||
}); | ||
await txn.prove(); | ||
// failure with enforceTransactionLimits = true | ||
await expect(txn.sign([bobKey]).safeSend()).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('Test unlimited network', () => { | ||
let bobAccount: PublicKey, | ||
bobKey: PrivateKey; | ||
|
||
beforeAll(async () => { | ||
|
||
Mina.setActiveInstance(unlimitedNetwork); | ||
bobKey = PrivateKey.random(); | ||
bobAccount = bobKey.toPublicKey(); | ||
}); | ||
|
||
|
||
it('Simple account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(1)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
}); | ||
await txn.prove(); | ||
await txn.sign([bobKey]).safeSend(); | ||
|
||
}); | ||
|
||
it('Multiple account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
for (let index = 0; index < 2; index++) { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
} | ||
}); | ||
await txn.prove(); | ||
await txn.sign([bobKey]).safeSend(); | ||
|
||
}); | ||
|
||
it('More than limit account update', async () => { | ||
|
||
let txn = await Mina.transaction(async () => { | ||
for (let index = 0; index < 12; index++) { | ||
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index)); | ||
accountUpdateBob.account.balance.requireEquals(UInt64.zero); | ||
accountUpdateBob.balance.addInPlace(UInt64.one); | ||
} | ||
}); | ||
await txn.prove(); | ||
// success with enforceTransactionLimits = false | ||
await txn.sign([bobKey]).safeSend(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be cleaner to name the option
bypassTransactionLimits
. That wayundefined
andfalse
both resolve to the default behavior. Then I think this could beenforceTransactionLimits = options.bypassTransactionLimits ? false : true;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to reuse the same name than LocalBlockchain :
async function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits = true, } = {}) {
o1js/src/lib/mina/local-blockchain.ts
Line 74 in a0f0f34