Skip to content
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
22 changes: 15 additions & 7 deletions contracts/FlowTransactionScheduler.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ access(all) contract FlowTransactionScheduler {

// Get the mapping of how much effort has been used
// for each priority for the timestamp
let slotPriorityEffortsUsed = self.slotUsedEffort[sanitizedTimestamp]!
let slotPriorityEffortsUsed = &self.slotUsedEffort[sanitizedTimestamp]! as &{Priority: UInt64}

// Get the exclusive reserves for each priority
let highReserve = self.config.priorityEffortReserve[Priority.High]!
Expand Down Expand Up @@ -1053,8 +1053,8 @@ access(all) contract FlowTransactionScheduler {
}

// Add this transaction id to the slot
let slotQueue = self.slotQueue[slot]!
if let priorityQueue = slotQueue[txData.priority] {
let slotQueue = &self.slotQueue[slot]! as auth(Mutate) &{Priority: {UInt64: UInt64}}
if let priorityQueue = *slotQueue[txData.priority] {
priorityQueue[txData.id] = txData.executionEffort
slotQueue[txData.priority] = priorityQueue
} else {
Comment on lines +1057 to 1060
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest that we avoid copying the priorityQueue mapping here but it looks like we can't get an auth(Mutate) reference to the inner mapping which is unfortunate. I would think the outer authorized reference enables us to access the inner values as authorized as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I thought that would be true too, but I could see it potentially unintentionally exposing something.

Expand All @@ -1063,17 +1063,14 @@ access(all) contract FlowTransactionScheduler {
}
}

self.slotQueue[slot] = slotQueue

// Add the execution effort for this transaction to the total for the slot's priority
let slotEfforts = self.slotUsedEffort[slot]!
let slotEfforts = &self.slotUsedEffort[slot]! as auth(Mutate) &{Priority: UInt64}
var newPriorityEffort = slotEfforts[txData.priority]! + txData.executionEffort
slotEfforts[txData.priority] = newPriorityEffort
var newTotalEffort: UInt64 = 0
for priority in slotEfforts.keys {
newTotalEffort = newTotalEffort.saturatingAdd(slotEfforts[priority]!)
}
self.slotUsedEffort[slot] = slotEfforts

// Need to potentially reschedule low priority transactions to make room for the new transaction
// Iterate through them and record which ones to reschedule until the total effort is less than the limit
Expand Down Expand Up @@ -1466,6 +1463,17 @@ access(all) contract FlowTransactionScheduler {
)
}

/// Allows users to calculate the fee for a scheduled transaction without having to call the expensive estimate function
/// @param executionEffort: The execution effort of the transaction
/// @param priority: The priority of the transaction
/// @param dataSizeMB: The size of the data to be stored with the scheduled transaction
/// The user must calculate this data size themselves before calling this function
/// But should be done in a separate script or transaction to avoid the expensive getSizeOfData function
/// @return UFix64: The fee in Flow tokens that is required to pay for the transaction
access(all) fun calculateFee(executionEffort: UInt64, priority: Priority, dataSizeMB: UFix64): UFix64 {
return self.sharedScheduler.borrow()!.calculateFee(executionEffort: executionEffort, priority: priority, dataSizeMB: dataSizeMB)
}

access(all) fun cancel(scheduledTx: @ScheduledTransaction): @FlowToken.Vault {
let id = scheduledTx.id
destroy scheduledTx
Expand Down
Loading
Loading