-
Notifications
You must be signed in to change notification settings - Fork 53
FEATURE: Transaction scheduling #489
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
Merged
Merged
Changes from all commits
Commits
Show all changes
97 commits
Select commit
Hold shift + click to select a range
3df0e1d
add safe scheduler contract
devbugging 6dd02f7
adding tests for estimate
devbugging 618c07b
remove some tests
devbugging 352c6c6
fix test issues
devbugging a31805e
add estiamted callback error
devbugging 2e141a4
update tests to check estiamte error
devbugging dce16ac
prune statuses
devbugging a3462c9
add todo
devbugging 556e3bb
add schedule tests
devbugging 3b38e5c
clean up test
devbugging b352a51
pr review feedback
devbugging 8fc371f
todo tests
devbugging fd9db06
address other PR comments
joshuahannan ab6b82d
fix priority enum, add fees deposit, and revert pre-conditions change
joshuahannan a6db6b4
make ci
joshuahannan 8c87d0a
rearrange error messages in estimate and update tests
joshuahannan 81c74f4
change EstimatedCallback to non-optional
joshuahannan e343b96
move transaction and update test
joshuahannan 898a583
more schedule tests and scripts
joshuahannan 8bff865
revert setStatus
joshuahannan 7ba2096
update error handling for low priority callbacks
joshuahannan 49b3a1d
add comments and update status constants in tests
joshuahannan b8e2fce
add first draft of go package for callback scheduling
joshuahannan d4a3e56
update pkg versions so tests pass
joshuahannan 171a103
add schedule utility function
joshuahannan 763b332
add support for adding low priority callbacks to slots during processing
joshuahannan b17ac2e
add additional event arguments
joshuahannan 274a4fe
fix timestamp and slotqueue naming
joshuahannan cf59ea0
Merge branch 'master' into feature/callback-scheduling
janezpodhostnik d4a1f36
Fix initialization issue with low priority slot (#496)
devbugging 6f5e1dd
add cancel logic and tests
joshuahannan 00a51dc
first draft of priority process ordering
joshuahannan d0868d3
initialization of effort
joshuahannan f626531
add cleanup for failed transactions, reorganize code, and add tests
joshuahannan 2a039b3
remove mark failed callback
joshuahannan ce36e22
add calculation for storage fees
joshuahannan 07ebd78
add underflow check
joshuahannan 6ab2c6b
don't clean up failed callbacks
joshuahannan 291fa9a
add ability for owner to configure metadata
joshuahannan e280f27
adds underflow checks
joshuahannan 5c2156a
use saturating subtract
joshuahannan fd2a5d0
make assets
joshuahannan 9a74f0f
add more event parameters and tests
joshuahannan 4b3f275
rename entitlements and events and edit some comments
joshuahannan f776b49
address more PR comments
joshuahannan 042cf6a
return 0 for size of some primitive types
joshuahannan 9ceefaa
rename config metadata to config details
joshuahannan 93c7f82
sanitize timestamp
joshuahannan 00118c4
add 0.0 multiplier check
joshuahannan 8ec6ea9
remove optional from scheduled event
joshuahannan 29940d8
rebase and make assets
joshuahannan e94301b
use interface type for config storage
joshuahannan 9f760a6
handle failed callbacks and store failed statuses
joshuahannan 9897d19
make assets
joshuahannan 52ab078
remove succeeded status from get status
joshuahannan 309bc9e
keep succeeded status
joshuahannan 68fecdd
rename historic timestamp and use earliest historic ID
joshuahannan 224ca21
fix assets
joshuahannan 9ae4443
add unknown status
joshuahannan f96494a
General callback scheduler improvements (#508)
devbugging 5d78437
address Janez and Josh Pr comments
joshuahannan c17f3ae
remove test code
joshuahannan 926eff2
more concise names
joshuahannan 203b43f
Remove shared state access
devbugging 7a4d679
do cleanup in process
joshuahannan 27147d6
refactor finalize and only call after execution
joshuahannan c6aea32
fix initial tests
joshuahannan e0a2950
fix low priority bug and initialize canceled callbacks to 0
joshuahannan 91e6f28
Add low prio slot and correct processing (#513)
joshuahannan ddcbd63
Adds getName, getDescription, and more event parameters (#515)
joshuahannan b4a08d2
Store callback fees in the account's Vault (#516)
joshuahannan 8235bb1
update and reorg tests
joshuahannan 956618b
make ci
joshuahannan 3dcc290
add 9999 effort limit and data limit
joshuahannan 75b435a
remove flake test
joshuahannan 3794b04
fix flaky estimate tests
joshuahannan eba6321
add collection limits
joshuahannan 0271845
tx limit can be equal to zero to allow pausing
joshuahannan d5ef3a9
update default values for config
joshuahannan 43df3a8
change name and description to fields
joshuahannan d0d460b
make ScheduledCallback a resource
joshuahannan 819c6e9
remove capability arg
joshuahannan b78bf08
address process PR comment
joshuahannan 8595d46
add Resolver and cancel event changes
joshuahannan c1a508c
fix test performance and assertions
joshuahannan bd6eef7
revert to getName and getDescription
joshuahannan 4f0de83
remove name and description
joshuahannan 57b0072
rename callback to transaction
joshuahannan ea0613e
update deps
joshuahannan 3b8efbe
add disclaimers for unsafe functions
joshuahannan 8d57a35
Merge remote-tracking branch 'origin/master' into feature/callback-sc…
joshuahannan 394bdee
sort cancelled transactions array
joshuahannan a5a61c0
get type from handler and return nil for fee
joshuahannan 3429889
add test for nil case
joshuahannan f09f1b7
init fix
joshuahannan b24c97b
address PR comments
joshuahannan 08fa8de
fix some tests
joshuahannan 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
contracts/testContracts/TestFlowScheduledTransactionHandler.cdc
This file contains hidden or 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,105 @@ | ||
| import "FlowTransactionScheduler" | ||
| import "FlowToken" | ||
| import "FungibleToken" | ||
|
|
||
| // ⚠️ WARNING: UNSAFE FOR PRODUCTION ⚠️ | ||
| // This is a TEST CONTRACT ONLY and should NEVER be used in production! | ||
| // This contract is designed solely for testing FlowTransactionScheduler functionality | ||
| // and contains unsafe implementations that could lead to loss of funds or security vulnerabilities. | ||
| // | ||
| // DO NOT DEPLOY THIS CONTRACT OR A SIMILAR CONTRACT TO MAINNET OR ANY PRODUCTION ENVIRONMENT | ||
| // UNLESS YOU ARE SURE WHAT YOU ARE DOING! | ||
| // | ||
| // TestFlowScheduledTransactionHandler is a simplified test contract for testing FlowTransactionScheduler | ||
| access(all) contract TestFlowScheduledTransactionHandler { | ||
| access(all) var scheduledTransactions: @{UInt64: FlowTransactionScheduler.ScheduledTransaction} | ||
| access(all) var succeededTransactions: [UInt64] | ||
|
|
||
| access(all) let HandlerStoragePath: StoragePath | ||
| access(all) let HandlerPublicPath: PublicPath | ||
|
|
||
| access(all) resource Handler: FlowTransactionScheduler.TransactionHandler { | ||
|
|
||
| access(all) let name: String | ||
| access(all) let description: String | ||
|
|
||
| init(name: String, description: String) { | ||
| self.name = name | ||
| self.description = description | ||
| } | ||
|
|
||
| access(FlowTransactionScheduler.Execute) | ||
| fun executeTransaction(id: UInt64, data: AnyStruct?) { | ||
| // Most transactions will have string data | ||
| if let dataString = data as? String { | ||
| // intentional failure test case | ||
| if dataString == "fail" { | ||
| panic("Transaction \(id) failed") | ||
| } else if dataString == "cancel" { | ||
| // This should always fail because the transaction can't cancel itself during execution | ||
| destroy <-TestFlowScheduledTransactionHandler.cancelTransaction(id: id) | ||
| } else { | ||
| // All other regular test cases should succeed | ||
| TestFlowScheduledTransactionHandler.succeededTransactions.append(id) | ||
| } | ||
| } else if let dataCap = data as? Capability<auth(FlowTransactionScheduler.Execute) &{FlowTransactionScheduler.TransactionHandler}> { | ||
| // Testing scheduling a transaction with a transaction | ||
| let scheduledTransaction <- FlowTransactionScheduler.schedule( | ||
| handlerCap: dataCap, | ||
| data: "test data", | ||
| timestamp: getCurrentBlock().timestamp + 10.0, | ||
| priority: FlowTransactionScheduler.Priority.High, | ||
| executionEffort: UInt64(1000), | ||
| fees: <-TestFlowScheduledTransactionHandler.getFeeFromVault(amount: 1.0) | ||
| ) | ||
| TestFlowScheduledTransactionHandler.addScheduledTransaction(scheduledTx: <-scheduledTransaction) | ||
| } else { | ||
| panic("TestFlowScheduledTransactionHandler.executeTransaction: Invalid data type for transaction with id \(id). Type is \(data.getType().identifier)") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| access(all) fun createHandler(): @Handler { | ||
| return <- create Handler(name: "Test FlowTransactionHandler Resource", description: "Executes a variety of transactions for different test cases") | ||
| } | ||
|
|
||
| // ⚠️ WARNING: UNSAFE FOR PRODUCTION ⚠️ | ||
| // This function is part of a TEST CONTRACT and should NEVER be used in production! | ||
| // It contains unsafe implementations that could lead to loss of funds or security vulnerabilities. | ||
| access(all) fun addScheduledTransaction(scheduledTx: @FlowTransactionScheduler.ScheduledTransaction) { | ||
| let status = scheduledTx.status() | ||
| if status == nil { | ||
| panic("Invalid status for transaction with id \(scheduledTx.id)") | ||
| } | ||
| self.scheduledTransactions[scheduledTx.id] <-! scheduledTx | ||
| } | ||
|
|
||
| // ⚠️ WARNING: UNSAFE FOR PRODUCTION ⚠️ | ||
| // This function is part of a TEST CONTRACT and should NEVER be used in production! | ||
| // It contains unsafe implementations that could lead to loss of funds or security vulnerabilities. | ||
| access(all) fun cancelTransaction(id: UInt64): @FlowToken.Vault { | ||
| let scheduledTx <- self.scheduledTransactions.remove(key: id) | ||
| ?? panic("Invalid ID: \(id) transaction not found") | ||
| return <-FlowTransactionScheduler.cancel(scheduledTx: <-scheduledTx!) | ||
| } | ||
|
|
||
| access(all) fun getSucceededTransactions(): [UInt64] { | ||
| return self.succeededTransactions | ||
| } | ||
|
|
||
| access(contract) fun getFeeFromVault(amount: UFix64): @FlowToken.Vault { | ||
| // borrow a reference to the vault that will be used for fees | ||
| let vault = self.account.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault) | ||
| ?? panic("Could not borrow FlowToken vault") | ||
|
|
||
| return <- vault.withdraw(amount: amount) as! @FlowToken.Vault | ||
| } | ||
|
|
||
| access(all) init() { | ||
| self.scheduledTransactions <- {} | ||
| self.succeededTransactions = [] | ||
|
|
||
| self.HandlerStoragePath = /storage/testTransactionHandler | ||
| self.HandlerPublicPath = /public/testTransactionHandler | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.