diff --git a/src/full_node/blockchain.py b/src/full_node/blockchain.py index b71e8b2f2a770..7abc7102c1bdb 100644 --- a/src/full_node/blockchain.py +++ b/src/full_node/blockchain.py @@ -635,7 +635,10 @@ class Blockchain: if not block.transactions_generator: return Err.UNKNOWN # Get List of names removed, puzzles hashes for removed coins and conditions crated - error, npc_list, cost = calculate_cost_of_program(block.transactions_generator) + error, npc_list, cost = calculate_cost_of_program( + block.transactions_generator, + self.constants["CLVM_COST_RATIO_CONSTANT"] + ) # 2. Check that cost <= MAX_BLOCK_COST_CLVM if cost > self.constants["MAX_BLOCK_COST_CLVM"]: diff --git a/src/full_node/full_node.py b/src/full_node/full_node.py index 9ee4dd4e59eee..b2a14d306dd44 100644 --- a/src/full_node/full_node.py +++ b/src/full_node/full_node.py @@ -1283,7 +1283,10 @@ class FullNode: # Calculate the cost of transactions cost = uint64(0) if solution_program: - _, _, cost = calculate_cost_of_program(solution_program) + _, _, cost = calculate_cost_of_program( + solution_program, + self.constants.CLVM_COST_RATIO_CONSTANT + ) extension_data: bytes32 = bytes32([0] * 32) diff --git a/src/full_node/mempool_manager.py b/src/full_node/mempool_manager.py index 57c8a2a57096c..92c3eed29c2bd 100644 --- a/src/full_node/mempool_manager.py +++ b/src/full_node/mempool_manager.py @@ -122,7 +122,10 @@ class MempoolManager: # Calculate the cost and fees program = best_solution_program(new_spend) # npc contains names of the coins removed, puzzle_hashes and their spend conditions - fail_reason, npc_list, cost = calculate_cost_of_program(program) + fail_reason, npc_list, cost = calculate_cost_of_program( + program, + self.constants.CLVM_COST_RATIO_CONSTANT, + ) if fail_reason: return None, MempoolInclusionStatus.FAILED, fail_reason diff --git a/src/util/cost_calculator.py b/src/util/cost_calculator.py index 3570c26cba155..f9f6e73012f0c 100644 --- a/src/util/cost_calculator.py +++ b/src/util/cost_calculator.py @@ -1,6 +1,5 @@ from typing import Tuple, Optional, List -from src.consensus.constants import constants from src.consensus.condition_costs import ConditionCost from src.types.condition_opcodes import ConditionOpcode from src.types.program import Program @@ -12,6 +11,7 @@ from src.util.mempool_check_conditions import get_name_puzzle_conditions def calculate_cost_of_program( program: Program, + clvm_cost_ratio_constant: int, ) -> Tuple[Optional[Err], List[NPC], uint64]: """ This function calculates the total cost of either block or a spendbundle @@ -60,6 +60,6 @@ def calculate_cost_of_program( # Add raw size of the program total_vbyte_cost += len(bytes(program)) - total_clvm_cost += total_vbyte_cost * constants["CLVM_COST_RATIO_CONSTANT"] + total_clvm_cost += total_vbyte_cost * clvm_cost_ratio_constant return error, npc_list, uint64(total_clvm_cost) diff --git a/tests/test_cost_calculation.py b/tests/test_cost_calculation.py index add0fd3bde326..36a9f2273f388 100644 --- a/tests/test_cost_calculation.py +++ b/tests/test_cost_calculation.py @@ -40,12 +40,13 @@ class TestCostCalculation: assert spend_bundle is not None program = best_solution_program(spend_bundle) - error, npc_list, clvm_cost = calculate_cost_of_program(program) + ratio = test_constants["CLVM_COST_RATIO_CONSTANT"] + + error, npc_list, clvm_cost = calculate_cost_of_program(program, ratio) error, npc_list, cost = get_name_puzzle_conditions(program) # Create condition + agg_sig_condition + length + cpu_cost - ratio = test_constants["CLVM_COST_RATIO_CONSTANT"] assert ( clvm_cost == 200 * ratio + 20 * ratio + len(bytes(program)) * ratio + cost )