Skip to content

Commit

Permalink
Revert breaking changes on PR 4619
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Besancon committed Jan 17, 2025
1 parent 97be10e commit d212c1a
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 218 deletions.
2 changes: 0 additions & 2 deletions massa-api-exports/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ pub struct APIConfig {
pub last_start_period: u64,
/// chain id
pub chain_id: u64,
/// Delta to compute upper bounds when fetching deferred credits
pub deferred_credits_delta: MassaTime,
/// minimal fees to include an operation in a block
pub minimal_fees: Amount,
/// deferred calls config
Expand Down
15 changes: 1 addition & 14 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,21 +993,8 @@ impl MassaRpcServer for API<Public> {
.collect()
};

// Compute a limit (as a slot) for deferred credits as it can be quite huge
let bound_ts = MassaTime::now().saturating_add(self.0.api_settings.deferred_credits_delta);

let deferred_credit_max_slot = timeslots::get_closest_slot_to_timestamp(
self.0.api_settings.thread_count,
self.0.api_settings.t0,
self.0.api_settings.genesis_timestamp,
bound_ts,
);

// get execution info
let execution_infos = self.0.execution_controller.get_addresses_infos(
&addresses,
std::ops::Bound::Included(deferred_credit_max_slot),
);
let execution_infos = self.0.execution_controller.get_addresses_infos(&addresses);

// get future draws from selector
let selection_draws = {
Expand Down
2 changes: 0 additions & 2 deletions massa-api/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ pub(crate) fn get_apiv2_server(addr: &SocketAddr) -> (API<ApiV2>, APIConfig) {
periods_per_cycle: PERIODS_PER_CYCLE,
last_start_period: 0,
chain_id: *CHAINID,
deferred_credits_delta: MassaTime::from_millis(24 * 3600 * 2),
minimal_fees: Amount::zero(),
deferred_calls_config: Default::default(),
};
Expand Down Expand Up @@ -145,7 +144,6 @@ pub(crate) fn start_public_api(addr: SocketAddr) -> (API<Public>, APIConfig) {
periods_per_cycle: PERIODS_PER_CYCLE,
last_start_period: 0,
chain_id: *CHAINID,
deferred_credits_delta: MassaTime::from_millis(24 * 3600 * 2),
minimal_fees: Amount::zero(),
deferred_calls_config: Default::default(),
};
Expand Down
2 changes: 1 addition & 1 deletion massa-api/src/tests/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ async fn get_addresses() {
let (mut api_public, config) = start_public_api(addr);

let mut exec_ctrl = MockExecutionController::new();
exec_ctrl.expect_get_addresses_infos().returning(|a, _s| {
exec_ctrl.expect_get_addresses_infos().returning(|a| {
a.iter()
.map(|_addr| ExecutionAddressInfo {
candidate_balance: Amount::from_str("100000").unwrap(),
Expand Down
1 change: 0 additions & 1 deletion massa-async-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ impl AsyncPool {
self.message_info_cache.insert(message_id, message.into());
}

// The -1 is to remove the IDENT byte at the end of the key
last_id = Some(
serialized_message_id[ASYNC_POOL_PREFIX.len()..serialized_message_id.len() - 1]
.to_vec(),
Expand Down
6 changes: 1 addition & 5 deletions massa-execution-exports/src/controller_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ pub trait ExecutionController: Send + Sync {
) -> (bool, bool);

/// Gets information about a batch of addresses
fn get_addresses_infos(
&self,
addresses: &[Address],
deferred_credits_max_slot: std::ops::Bound<Slot>,
) -> Vec<ExecutionAddressInfo>;
fn get_addresses_infos(&self, addresses: &[Address]) -> Vec<ExecutionAddressInfo>;

/// Get execution statistics
fn get_stats(&self) -> ExecutionStats;
Expand Down
4 changes: 1 addition & 3 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,19 +1357,17 @@ impl ExecutionContext {
}

/// Get future deferred credits of an address
/// With optionally a limit slot (excluded)
pub fn get_address_future_deferred_credits(
&self,
address: &Address,
thread_count: u8,
max_slot: std::ops::Bound<Slot>,
) -> BTreeMap<Slot, Amount> {
let min_slot = self
.slot
.get_next_slot(thread_count)
.expect("unexpected slot overflow in context.get_addresses_deferred_credits");
self.speculative_roll_state
.get_address_deferred_credits(address, (std::ops::Bound::Included(min_slot), max_slot))
.get_address_deferred_credits(address, min_slot)
}

/// in case of
Expand Down
10 changes: 2 additions & 8 deletions massa-execution-worker/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,7 @@ impl ExecutionController for ExecutionControllerImpl {
}

/// Gets information about a batch of addresses
fn get_addresses_infos(
&self,
addresses: &[Address],
deferred_credits_max_slot: std::ops::Bound<Slot>,
) -> Vec<ExecutionAddressInfo> {
fn get_addresses_infos(&self, addresses: &[Address]) -> Vec<ExecutionAddressInfo> {
let mut res = Vec::with_capacity(addresses.len());
let exec_state = self.execution_state.read();
for addr in addresses {
Expand All @@ -481,16 +477,14 @@ impl ExecutionController for ExecutionControllerImpl {
exec_state.get_final_and_candidate_balance(addr);
let (final_roll_count, candidate_roll_count) =
exec_state.get_final_and_candidate_rolls(addr);
let future_deferred_credits =
exec_state.get_address_future_deferred_credits(addr, deferred_credits_max_slot);
res.push(ExecutionAddressInfo {
final_datastore_keys: final_datastore_keys.unwrap_or_default(),
candidate_datastore_keys: candidate_datastore_keys.unwrap_or_default(),
final_balance: final_balance.unwrap_or_default(),
candidate_balance: candidate_balance.unwrap_or_default(),
final_roll_count,
candidate_roll_count,
future_deferred_credits,
future_deferred_credits: exec_state.get_address_future_deferred_credits(addr),
cycle_infos: exec_state.get_address_cycle_infos(addr),
});
}
Expand Down
28 changes: 6 additions & 22 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2611,16 +2611,8 @@ impl ExecutionState {
}

/// Get future deferred credits of an address
pub fn get_address_future_deferred_credits(
&self,
address: &Address,
max_slot: std::ops::Bound<Slot>,
) -> BTreeMap<Slot, Amount> {
context_guard!(self).get_address_future_deferred_credits(
address,
self.config.thread_count,
max_slot,
)
pub fn get_address_future_deferred_credits(&self, address: &Address) -> BTreeMap<Slot, Amount> {
context_guard!(self).get_address_future_deferred_credits(address, self.config.thread_count)
}

/// Get future deferred credits of an address
Expand All @@ -2630,17 +2622,11 @@ impl ExecutionState {
address: &Address,
) -> (BTreeMap<Slot, Amount>, BTreeMap<Slot, Amount>) {
// get values from final state
let res_final: BTreeMap<Slot, Amount> = self
let res_final = self
.final_state
.read()
.get_pos_state()
.get_deferred_credits_range(.., Some(address))
.credits
.iter()
.filter_map(|(slot, addr_amount)| {
addr_amount.get(address).map(|amount| (*slot, *amount))
})
.collect();
.get_address_deferred_credits(address);

// get values from active history, backwards
let mut res_speculative: BTreeMap<Slot, Amount> = BTreeMap::default();
Expand All @@ -2652,12 +2638,10 @@ impl ExecutionState {
};
}
}

// fill missing speculative entries with final entries
for (slot, amount) in &res_final {
res_speculative.entry(*slot).or_insert(*amount);
for (s, v) in res_final.iter() {
res_speculative.entry(*s).or_insert(*v);
}

// remove zero entries from speculative
res_speculative.retain(|_s, a| !a.is_zero());

Expand Down
19 changes: 8 additions & 11 deletions massa-execution-worker/src/speculative_roll_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl SpeculativeRollState {
addr: &Address,
amount: &Amount,
) -> Amount {
let credits = self.get_address_deferred_credits(addr, slot..);
let credits = self.get_address_deferred_credits(addr, *slot);

let mut remaining_to_slash = *amount;
for (credit_slot, credit_amount) in credits.iter() {
Expand Down Expand Up @@ -305,22 +305,19 @@ impl SpeculativeRollState {
}

/// Get deferred credits of an address starting from a given slot
pub fn get_address_deferred_credits<R>(
pub fn get_address_deferred_credits(
&self,
address: &Address,
slot_range: R,
) -> BTreeMap<Slot, Amount>
where
R: std::ops::RangeBounds<Slot> + Clone,
{
min_slot: Slot,
) -> BTreeMap<Slot, Amount> {
let mut res: HashMap<Slot, Amount> = HashMap::default();

// get added values
for (slot, addr_amount) in self
.added_changes
.deferred_credits
.credits
.range(slot_range.clone())
.range(min_slot..)
{
if let Some(amount) = addr_amount.get(address) {
res.entry(*slot).or_insert(*amount);
Expand All @@ -336,7 +333,7 @@ impl SpeculativeRollState {
.pos_changes
.deferred_credits
.credits
.range(slot_range.clone())
.range(min_slot..)
{
if let Some(amount) = addr_amount.get(address) {
res.entry(*slot).or_insert(*amount);
Expand All @@ -350,7 +347,7 @@ impl SpeculativeRollState {
let final_state = self.final_state.read();
for (slot, addr_amount) in final_state
.get_pos_state()
.get_deferred_credits_range(slot_range, Some(address))
.get_deferred_credits_range(min_slot..)
.credits
{
if let Some(amount) = addr_amount.get(address) {
Expand Down Expand Up @@ -579,7 +576,7 @@ impl SpeculativeRollState {
.final_state
.read()
.get_pos_state()
.get_deferred_credits_range(..=slot, None);
.get_deferred_credits_range(..=slot);

// fetch active history deferred credits
credits.extend(
Expand Down
4 changes: 1 addition & 3 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3719,9 +3719,7 @@ fn datastore_manipulations() {
],
});
// Just checking that is works no asserts for now
universe
.module_controller
.get_addresses_infos(&[addr], std::ops::Bound::Unbounded);
universe.module_controller.get_addresses_infos(&[addr]);
}

/// This test checks causes a history rewrite in slot sequencing and ensures that emitted events match
Expand Down
2 changes: 0 additions & 2 deletions massa-node/base_config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
enable_ws = false
# whether to broadcast for blocks, endorsements and operations
enable_broadcast = false
# deferred credits delta (in milliseconds)
deferred_credits_delta = 7776000000 # ~ 3 months (90×24×60×60×1000) in milliseconds

[grpc]
[grpc.public]
Expand Down
1 change: 0 additions & 1 deletion massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ async fn launch(
periods_per_cycle: PERIODS_PER_CYCLE,
last_start_period: final_state.read().get_last_start_period(),
chain_id: *CHAINID,
deferred_credits_delta: SETTINGS.api.deferred_credits_delta,
minimal_fees: SETTINGS.pool.minimal_fees,
deferred_calls_config,
};
Expand Down
1 change: 0 additions & 1 deletion massa-node/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ pub struct APISettings {
pub enable_ws: bool,
// whether to broadcast for blocks, endorsement and operations
pub enable_broadcast: bool,
pub deferred_credits_delta: MassaTime,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down
Loading

0 comments on commit d212c1a

Please sign in to comment.