mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-12-01 20:05:43 +03:00
Pass clvm_cost_ratio_constant
to calculate_cost_of_program
.
This commit is contained in:
parent
9220b90373
commit
e83e7db3ce
@ -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"]:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user