From 156b6085567a870b4dc8a9985768fbf926306fe2 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:22:15 -0500 Subject: [PATCH 01/17] Add additional cost values to capacity-gating of blocks during replay --- ledger/src/blockstore_processor.rs | 20 ++++++++++++++++++-- runtime/src/cost_model.rs | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 5b9b83bc9510b8..2d93c130a13c55 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -155,6 +155,20 @@ fn aggregate_total_execution_units(execute_timings: &ExecuteTimings) -> u64 { execute_cost_units } +fn sum_additional_costs(batch: &TransactionBatch) -> u64 { + let mut additional_costs: u64 = 0; + let transactions = batch.sanitized_transactions(); + let cost_model = CostModel::new(); + + for transaction in transactions { + let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + additional_costs += transaction_cost.signature_cost; + additional_costs += transaction_cost.write_lock_cost; + additional_costs += transaction_cost.data_bytes_cost; + } + additional_costs +} + fn execute_batch( batch: &TransactionBatch, bank: &Arc, @@ -190,16 +204,18 @@ fn execute_batch( .is_active(&feature_set::gate_large_block::id()) { let execution_cost_units = aggregate_total_execution_units(timings) - pre_process_units; + let additional_cost_units = sum_additional_costs(batch); let remaining_block_cost_cap = cost_capacity_meter .write() .unwrap() - .accumulate(execution_cost_units); + .accumulate(execution_cost_units + additional_cost_units); debug!( - "bank {} executed a batch, number of transactions {}, total execute cu {}, remaining block cost cap {}", + "bank {} executed a batch, number of transactions {}, total execute cu {}, total additional cu {}, remaining block cost cap {}", bank.slot(), batch.sanitized_transactions().len(), execution_cost_units, + additional_cost_units, remaining_block_cost_cap, ); diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index eaeb049d547a10..ecdfb04ad3f0e5 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -86,7 +86,7 @@ impl CostModel { let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS); tx_cost.signature_cost = self.get_signature_cost(transaction); - self.get_write_lock_cost(&mut tx_cost, transaction); + tx_cost.write_lock_cost = self.get_write_lock_cost(&mut tx_cost, transaction); tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction); tx_cost.execution_cost = self.get_transaction_cost(transaction); tx_cost.account_data_size = self.calculate_account_data_size(transaction); @@ -122,7 +122,8 @@ impl CostModel { &self, tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, - ) { + ) -> u64 { + let write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() @@ -133,9 +134,10 @@ impl CostModel { if is_writable { tx_cost.writable_accounts.push(*k); - tx_cost.write_lock_cost += WRITE_LOCK_UNITS; + write_lock_cost += WRITE_LOCK_UNITS; } }); + write_lock_cost } fn get_data_bytes_cost(&self, transaction: &SanitizedTransaction) -> u64 { From 747c4a412889fca9f50e40f8417c4295960b9bec Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:49:36 -0500 Subject: [PATCH 02/17] Fix a bug and cleanup get_write_lock_cost() --- runtime/src/cost_model.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index ecdfb04ad3f0e5..d2723ed1ceb427 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -123,16 +123,14 @@ impl CostModel { tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, ) -> u64 { - let write_lock_cost: u64 = 0; + let mut write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() .iter() .enumerate() .for_each(|(i, k)| { - let is_writable = message.is_writable(i); - - if is_writable { + if message.is_writable(i) { tx_cost.writable_accounts.push(*k); write_lock_cost += WRITE_LOCK_UNITS; } From 67a2a89bfd7e0c7fe30a5c659edbf052e1ae18c8 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:57:05 -0500 Subject: [PATCH 03/17] Typo fix --- ledger/src/blockstore_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 2d93c130a13c55..0b6af310eedab9 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -161,7 +161,7 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { - let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + let transaction_cost = cost_model.calculate_cost(transaction); additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From 6fb2d9947dd221e44b85462638779e0c9168f515 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:22:15 -0500 Subject: [PATCH 04/17] Add additional cost values to capacity-gating of blocks during replay --- ledger/src/blockstore_processor.rs | 20 ++++++++++++++++++-- runtime/src/cost_model.rs | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 9cd67c5e6ea4c0..4768b0933653a3 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -157,6 +157,20 @@ fn aggregate_total_execution_units(execute_timings: &ExecuteTimings) -> u64 { execute_cost_units } +fn sum_additional_costs(batch: &TransactionBatch) -> u64 { + let mut additional_costs: u64 = 0; + let transactions = batch.sanitized_transactions(); + let cost_model = CostModel::new(); + + for transaction in transactions { + let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + additional_costs += transaction_cost.signature_cost; + additional_costs += transaction_cost.write_lock_cost; + additional_costs += transaction_cost.data_bytes_cost; + } + additional_costs +} + fn execute_batch( batch: &TransactionBatch, bank: &Arc, @@ -192,16 +206,18 @@ fn execute_batch( .is_active(&feature_set::gate_large_block::id()) { let execution_cost_units = aggregate_total_execution_units(timings) - pre_process_units; + let additional_cost_units = sum_additional_costs(batch); let remaining_block_cost_cap = cost_capacity_meter .write() .unwrap() - .accumulate(execution_cost_units); + .accumulate(execution_cost_units + additional_cost_units); debug!( - "bank {} executed a batch, number of transactions {}, total execute cu {}, remaining block cost cap {}", + "bank {} executed a batch, number of transactions {}, total execute cu {}, total additional cu {}, remaining block cost cap {}", bank.slot(), batch.sanitized_transactions().len(), execution_cost_units, + additional_cost_units, remaining_block_cost_cap, ); diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index 0f7c6d6679fe86..dfa63f741b6aa5 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -95,7 +95,7 @@ impl CostModel { let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS); tx_cost.signature_cost = self.get_signature_cost(transaction); - self.get_write_lock_cost(&mut tx_cost, transaction); + tx_cost.write_lock_cost = self.get_write_lock_cost(&mut tx_cost, transaction); tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction); (tx_cost.builtins_execution_cost, tx_cost.bpf_execution_cost) = self.get_transaction_cost(transaction); @@ -133,7 +133,8 @@ impl CostModel { &self, tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, - ) { + ) -> u64 { + let write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() @@ -144,9 +145,10 @@ impl CostModel { if is_writable { tx_cost.writable_accounts.push(*k); - tx_cost.write_lock_cost += WRITE_LOCK_UNITS; + write_lock_cost += WRITE_LOCK_UNITS; } }); + write_lock_cost } fn get_data_bytes_cost(&self, transaction: &SanitizedTransaction) -> u64 { From 20c481547becd553b2f610959df3e1797b21f361 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:49:36 -0500 Subject: [PATCH 05/17] Fix a bug and cleanup get_write_lock_cost() --- runtime/src/cost_model.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index dfa63f741b6aa5..2f9193cb94d093 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -134,16 +134,14 @@ impl CostModel { tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, ) -> u64 { - let write_lock_cost: u64 = 0; + let mut write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() .iter() .enumerate() .for_each(|(i, k)| { - let is_writable = message.is_writable(i); - - if is_writable { + if message.is_writable(i) { tx_cost.writable_accounts.push(*k); write_lock_cost += WRITE_LOCK_UNITS; } From ac6d1402a18e3afccf493f03595b3ab09ded6fa1 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:57:05 -0500 Subject: [PATCH 06/17] Typo fix --- ledger/src/blockstore_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 4768b0933653a3..c5bf3ca7c96294 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -163,7 +163,7 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { - let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + let transaction_cost = cost_model.calculate_cost(transaction); additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From ccee9f5f59656d27933707c19d74484b499ceb00 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:22:15 -0500 Subject: [PATCH 07/17] Add additional cost values to capacity-gating of blocks during replay --- ledger/src/blockstore_processor.rs | 20 ++++++++++++++++++-- runtime/src/cost_model.rs | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 1160c6e1cbec19..f967f9c04028f5 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -154,6 +154,20 @@ fn aggregate_total_execution_units(execute_timings: &ExecuteTimings) -> u64 { execute_cost_units } +fn sum_additional_costs(batch: &TransactionBatch) -> u64 { + let mut additional_costs: u64 = 0; + let transactions = batch.sanitized_transactions(); + let cost_model = CostModel::new(); + + for transaction in transactions { + let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + additional_costs += transaction_cost.signature_cost; + additional_costs += transaction_cost.write_lock_cost; + additional_costs += transaction_cost.data_bytes_cost; + } + additional_costs +} + fn execute_batch( batch: &TransactionBatch, bank: &Arc, @@ -189,16 +203,18 @@ fn execute_batch( .is_active(&feature_set::gate_large_block::id()) { let execution_cost_units = aggregate_total_execution_units(timings) - pre_process_units; + let additional_cost_units = sum_additional_costs(batch); let remaining_block_cost_cap = cost_capacity_meter .write() .unwrap() - .accumulate(execution_cost_units); + .accumulate(execution_cost_units + additional_cost_units); debug!( - "bank {} executed a batch, number of transactions {}, total execute cu {}, remaining block cost cap {}", + "bank {} executed a batch, number of transactions {}, total execute cu {}, total additional cu {}, remaining block cost cap {}", bank.slot(), batch.sanitized_transactions().len(), execution_cost_units, + additional_cost_units, remaining_block_cost_cap, ); diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index 0f7c6d6679fe86..dfa63f741b6aa5 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -95,7 +95,7 @@ impl CostModel { let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS); tx_cost.signature_cost = self.get_signature_cost(transaction); - self.get_write_lock_cost(&mut tx_cost, transaction); + tx_cost.write_lock_cost = self.get_write_lock_cost(&mut tx_cost, transaction); tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction); (tx_cost.builtins_execution_cost, tx_cost.bpf_execution_cost) = self.get_transaction_cost(transaction); @@ -133,7 +133,8 @@ impl CostModel { &self, tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, - ) { + ) -> u64 { + let write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() @@ -144,9 +145,10 @@ impl CostModel { if is_writable { tx_cost.writable_accounts.push(*k); - tx_cost.write_lock_cost += WRITE_LOCK_UNITS; + write_lock_cost += WRITE_LOCK_UNITS; } }); + write_lock_cost } fn get_data_bytes_cost(&self, transaction: &SanitizedTransaction) -> u64 { From 10dbfd947ff8c63246f1c4529f5ff97918684528 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:49:36 -0500 Subject: [PATCH 08/17] Fix a bug and cleanup get_write_lock_cost() --- runtime/src/cost_model.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index dfa63f741b6aa5..2f9193cb94d093 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -134,16 +134,14 @@ impl CostModel { tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, ) -> u64 { - let write_lock_cost: u64 = 0; + let mut write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() .iter() .enumerate() .for_each(|(i, k)| { - let is_writable = message.is_writable(i); - - if is_writable { + if message.is_writable(i) { tx_cost.writable_accounts.push(*k); write_lock_cost += WRITE_LOCK_UNITS; } From b1a11927986220caf0c581a0056aaf003ffda582 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:57:05 -0500 Subject: [PATCH 09/17] Typo fix --- ledger/src/blockstore_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index f967f9c04028f5..23ff0bc8178903 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -160,7 +160,7 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { - let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + let transaction_cost = cost_model.calculate_cost(transaction); additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From 987e246dd50c1060f1e98ea017bce14d8e8ca373 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:22:15 -0500 Subject: [PATCH 10/17] Add additional cost values to capacity-gating of blocks during replay --- ledger/src/blockstore_processor.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 23ff0bc8178903..3c05f7591bd0e8 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -160,7 +160,11 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { +<<<<<<< HEAD let transaction_cost = cost_model.calculate_cost(transaction); +======= + let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this +>>>>>>> 156b608556 (Add additional cost values to capacity-gating of blocks during replay) additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From d66f090efd978961f68cda02c3665144ddbdf0dd Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Mon, 25 Apr 2022 16:44:49 -0500 Subject: [PATCH 11/17] Rebasing --- ledger/src/blockstore_processor.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 3c05f7591bd0e8..23ff0bc8178903 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -160,11 +160,7 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { -<<<<<<< HEAD let transaction_cost = cost_model.calculate_cost(transaction); -======= - let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this ->>>>>>> 156b608556 (Add additional cost values to capacity-gating of blocks during replay) additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From 2e303c1d90c66065e78836c566123cd7b11e46c3 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:22:15 -0500 Subject: [PATCH 12/17] Add additional cost values to capacity-gating of blocks during replay --- ledger/src/blockstore_processor.rs | 20 ++++++++++++++++++-- runtime/src/cost_model.rs | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 1160c6e1cbec19..f967f9c04028f5 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -154,6 +154,20 @@ fn aggregate_total_execution_units(execute_timings: &ExecuteTimings) -> u64 { execute_cost_units } +fn sum_additional_costs(batch: &TransactionBatch) -> u64 { + let mut additional_costs: u64 = 0; + let transactions = batch.sanitized_transactions(); + let cost_model = CostModel::new(); + + for transaction in transactions { + let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + additional_costs += transaction_cost.signature_cost; + additional_costs += transaction_cost.write_lock_cost; + additional_costs += transaction_cost.data_bytes_cost; + } + additional_costs +} + fn execute_batch( batch: &TransactionBatch, bank: &Arc, @@ -189,16 +203,18 @@ fn execute_batch( .is_active(&feature_set::gate_large_block::id()) { let execution_cost_units = aggregate_total_execution_units(timings) - pre_process_units; + let additional_cost_units = sum_additional_costs(batch); let remaining_block_cost_cap = cost_capacity_meter .write() .unwrap() - .accumulate(execution_cost_units); + .accumulate(execution_cost_units + additional_cost_units); debug!( - "bank {} executed a batch, number of transactions {}, total execute cu {}, remaining block cost cap {}", + "bank {} executed a batch, number of transactions {}, total execute cu {}, total additional cu {}, remaining block cost cap {}", bank.slot(), batch.sanitized_transactions().len(), execution_cost_units, + additional_cost_units, remaining_block_cost_cap, ); diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index 0f7c6d6679fe86..dfa63f741b6aa5 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -95,7 +95,7 @@ impl CostModel { let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS); tx_cost.signature_cost = self.get_signature_cost(transaction); - self.get_write_lock_cost(&mut tx_cost, transaction); + tx_cost.write_lock_cost = self.get_write_lock_cost(&mut tx_cost, transaction); tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction); (tx_cost.builtins_execution_cost, tx_cost.bpf_execution_cost) = self.get_transaction_cost(transaction); @@ -133,7 +133,8 @@ impl CostModel { &self, tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, - ) { + ) -> u64 { + let write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() @@ -144,9 +145,10 @@ impl CostModel { if is_writable { tx_cost.writable_accounts.push(*k); - tx_cost.write_lock_cost += WRITE_LOCK_UNITS; + write_lock_cost += WRITE_LOCK_UNITS; } }); + write_lock_cost } fn get_data_bytes_cost(&self, transaction: &SanitizedTransaction) -> u64 { From a1a0ea54c2e170d71106c639515600e2d8c177e6 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:49:36 -0500 Subject: [PATCH 13/17] Fix a bug and cleanup get_write_lock_cost() --- runtime/src/cost_model.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index dfa63f741b6aa5..2f9193cb94d093 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -134,16 +134,14 @@ impl CostModel { tx_cost: &mut TransactionCost, transaction: &SanitizedTransaction, ) -> u64 { - let write_lock_cost: u64 = 0; + let mut write_lock_cost: u64 = 0; let message = transaction.message(); message .account_keys() .iter() .enumerate() .for_each(|(i, k)| { - let is_writable = message.is_writable(i); - - if is_writable { + if message.is_writable(i) { tx_cost.writable_accounts.push(*k); write_lock_cost += WRITE_LOCK_UNITS; } From 61cd5055b1dc4c329a44d70d36ffe94f48a12041 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:57:05 -0500 Subject: [PATCH 14/17] Typo fix --- ledger/src/blockstore_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index f967f9c04028f5..23ff0bc8178903 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -160,7 +160,7 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { - let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this + let transaction_cost = cost_model.calculate_cost(transaction); additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From 06a74e15f0702038d254306fc3772584a823f831 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Thu, 21 Apr 2022 16:22:15 -0500 Subject: [PATCH 15/17] Add additional cost values to capacity-gating of blocks during replay --- ledger/src/blockstore_processor.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 23ff0bc8178903..3c05f7591bd0e8 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -160,7 +160,11 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { +<<<<<<< HEAD let transaction_cost = cost_model.calculate_cost(transaction); +======= + let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this +>>>>>>> 156b608556 (Add additional cost values to capacity-gating of blocks during replay) additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From ce390ce57cde3a9ac04d17e2eecd8342a3a1ad43 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Mon, 25 Apr 2022 16:44:49 -0500 Subject: [PATCH 16/17] Rebasing --- ledger/src/blockstore_processor.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 3c05f7591bd0e8..23ff0bc8178903 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -160,11 +160,7 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { let cost_model = CostModel::new(); for transaction in transactions { -<<<<<<< HEAD let transaction_cost = cost_model.calculate_cost(transaction); -======= - let transaction_cost = cost_model.calculate_costs(transaction); // computing a lot more than it needs to.. make sub-functions public and replace this ->>>>>>> 156b608556 (Add additional cost values to capacity-gating of blocks during replay) additional_costs += transaction_cost.signature_cost; additional_costs += transaction_cost.write_lock_cost; additional_costs += transaction_cost.data_bytes_cost; From 8c14233cede05fad13454f6c2cd6153021adf6a0 Mon Sep 17 00:00:00 2001 From: Jason Davis Date: Wed, 27 Apr 2022 10:35:47 -0500 Subject: [PATCH 17/17] Update to use saturating adds --- ledger/src/blockstore_processor.rs | 7 ++++--- runtime/src/cost_model.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 23ff0bc8178903..daa257d9ee84dd 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -161,9 +161,10 @@ fn sum_additional_costs(batch: &TransactionBatch) -> u64 { for transaction in transactions { let transaction_cost = cost_model.calculate_cost(transaction); - additional_costs += transaction_cost.signature_cost; - additional_costs += transaction_cost.write_lock_cost; - additional_costs += transaction_cost.data_bytes_cost; + additiona_costs.saturating_add_in_place(transaction_cost.signature_cost); + additiona_costs.saturating_add_in_place(transaction_cost.write_lock_cost); + additiona_costs.saturating_add_in_place(transaction_cost.data_bytes_cost); + additiona_costs.saturating_add_in_place(transaction_cost.builtins_execution_cost); } additional_costs } diff --git a/runtime/src/cost_model.rs b/runtime/src/cost_model.rs index 2f9193cb94d093..ef07e545104c79 100644 --- a/runtime/src/cost_model.rs +++ b/runtime/src/cost_model.rs @@ -143,7 +143,7 @@ impl CostModel { .for_each(|(i, k)| { if message.is_writable(i) { tx_cost.writable_accounts.push(*k); - write_lock_cost += WRITE_LOCK_UNITS; + write_lock_cost.saturating_add_in_place(WRITE_LOCK_UNITS); } }); write_lock_cost