Skip to content

Commit

Permalink
slot remaining gas for async msg
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Jul 25, 2024
1 parent 693cf0e commit 43923d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions massa-deferred-calls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use call::DeferredCall;
use massa_ledger_exports::{SetOrDelete, SetOrKeep};
use massa_models::{
amount::Amount,
config::THREAD_COUNT,
config::{DEFERRED_CALL_MAX_POOL_CHANGES, MAX_ASYNC_GAS, THREAD_COUNT},
deferred_call_id::{DeferredCallId, DeferredCallIdDeserializer, DeferredCallIdSerializer},
slot::Slot,
};
Expand Down Expand Up @@ -62,8 +62,8 @@ impl DeferredCallRegistry {
// TODO args
registry_changes_deserializer: DeferredRegistryChangesDeserializer::new(
THREAD_COUNT,
100_000,
100_000,
MAX_ASYNC_GAS,
DEFERRED_CALL_MAX_POOL_CHANGES,
),
registry_changes_serializer: DeferredRegistryChangesSerializer::new(),
}
Expand Down
4 changes: 0 additions & 4 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,6 @@ impl ExecutionContext {
self.speculative_deferred_calls.get_slot_gas(slot)
}

pub fn deferred_calls_get_slot_base_fee(&mut self, slot: &Slot) -> Amount {
self.speculative_deferred_calls.get_slot_base_fee(slot)
}

pub fn deferred_calls_advance_slot(
&mut self,
current_slot: Slot,
Expand Down
17 changes: 15 additions & 2 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,13 +1426,26 @@ impl ExecutionState {
context.deferred_call_delete(&id, slot.clone());
}

// TODO execute async messages as long as there is remaining gas in the slot (counting both unused max_async_gas and max_block_gas, and the latter can be used in full in case of block miss)
// execute async messages as long as there is remaining gas in the slot (counting both unused max_async_gas and max_block_gas, and the latter can be used in full in case of block miss)

// max_async_gas - calls.slot_gas is the remaining gas for the slot
let mut remaining_async_slot_gas = self.config.max_async_gas.saturating_sub(calls.slot_gas);
let mut remaining_block_gas = self.config.max_gas_per_block.saturating_sub(calls.slot_gas);

// Try executing asynchronous messages.
// Effects are cancelled on failure and the sender is reimbursed.
for (opt_bytecode, message) in messages {
// TODO verify here
if remaining_async_slot_gas == 0 || remaining_block_gas == 0 {
// break if there is no gas left
break;
}
if message.max_gas > remaining_async_slot_gas || message.max_gas > remaining_block_gas {
// Skip message if there is not enough gas left for it
continue;
}

remaining_async_slot_gas = remaining_async_slot_gas.saturating_sub(message.max_gas);
remaining_block_gas = remaining_block_gas.saturating_sub(message.max_gas);
match self.execute_async_message(message, opt_bytecode) {
Ok(_message_return) => {
cfg_if::cfg_if! {
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-worker/src/interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ impl Interface for InterfaceImpl {
// let effective_gas = CONST_ASYNC_GAS + max_gas;
// let fee = get_price(target_slot, effective_gas)?;

// // TODO: make sender pay `coins + fee`
// // make sender pay `coins + fee`

// let call = /* ... */;
// let id = /* ... */ ;
Expand Down

0 comments on commit 43923d1

Please sign in to comment.