From 08811402f74e547ffafd597d37fb43b7c4afe365 Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Mon, 1 Dec 2025 15:48:09 +0100 Subject: [PATCH 1/3] add save in saveComputer --- src/public_settings.h | 2 ++ src/qubic.cpp | 51 ++++++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/public_settings.h b/src/public_settings.h index 22b36f465..b02d95f4b 100644 --- a/src/public_settings.h +++ b/src/public_settings.h @@ -83,6 +83,8 @@ static unsigned short SCORE_CACHE_FILE_NAME[] = L"score.???"; static unsigned short CONTRACT_FILE_NAME[] = L"contract????.???"; static unsigned short CUSTOM_MINING_REVENUE_END_OF_EPOCH_FILE_NAME[] = L"custom_revenue.eoe"; static unsigned short CUSTOM_MINING_CACHE_FILE_NAME[] = L"custom_mining_cache.???"; +static unsigned short CONTRACT_EXEC_FEES_ACC_FILE_NAME[] = L"contract_exec_fees_acc.???"; +static unsigned short CONTRACT_EXEC_FEES_REC_FILE_NAME[] = L"contract_exec_fees_rec.???"; static constexpr unsigned long long NUMBER_OF_INPUT_NEURONS = 512; // K static constexpr unsigned long long NUMBER_OF_OUTPUT_NEURONS = 512; // L diff --git a/src/qubic.cpp b/src/qubic.cpp index d200233c9..58a53dc25 100644 --- a/src/qubic.cpp +++ b/src/qubic.cpp @@ -3539,6 +3539,14 @@ static void beginEpoch() CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0'; CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0'; + CONTRACT_EXEC_FEES_ACC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0'; + CONTRACT_EXEC_FEES_ACC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0'; + CONTRACT_EXEC_FEES_ACC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0'; + + CONTRACT_EXEC_FEES_REC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0'; + CONTRACT_EXEC_FEES_REC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0'; + CONTRACT_EXEC_FEES_REC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0'; + score->initMemory(); score->resetTaskQueue(); setMem(minerSolutionFlags, NUMBER_OF_MINER_SOLUTION_FLAGS / 8, 0); @@ -5291,8 +5299,8 @@ static bool saveComputer(CHAR16* directory) const unsigned long long beginningTick = __rdtsc(); - bool ok = true; unsigned long long totalSize = 0; + long long savedSize = 0; for (unsigned int contractIndex = 0; contractIndex < contractCount; contractIndex++) { @@ -5301,27 +5309,35 @@ static bool saveComputer(CHAR16* directory) CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 7] = (contractIndex % 100) / 10 + L'0'; CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 6] = contractIndex % 10 + L'0'; contractStateLock[contractIndex].acquireRead(); - long long savedSize = save(CONTRACT_FILE_NAME, contractDescriptions[contractIndex].stateSize, contractStates[contractIndex], directory); + savedSize = save(CONTRACT_FILE_NAME, contractDescriptions[contractIndex].stateSize, contractStates[contractIndex], directory); contractStateLock[contractIndex].releaseRead(); totalSize += savedSize; if (savedSize != contractDescriptions[contractIndex].stateSize) { - ok = false; - - break; + return false; } } - if (ok) + logToConsole(L"Saving contract execution fee files..."); + savedSize += save(CONTRACT_EXEC_FEES_ACC_FILE_NAME, sizeof(contractExecutionTimePerPhase), (unsigned char*)contractExecutionTimePerPhase, directory); + if (savedSize != sizeof(contractExecutionTimePerPhase)) { - setNumber(message, totalSize, TRUE); - appendText(message, L" bytes of the computer data are saved ("); - appendNumber(message, (__rdtsc() - beginningTick) * 1000000 / frequency, TRUE); - appendText(message, L" microseconds)."); - logToConsole(message); - return true; + return false; } - return false; + totalSize += savedSize; + savedSize = executionFeeReportCollector.save(CONTRACT_EXEC_FEES_REC_FILE_NAME); + if (savedSize < 0) + { + return false; + } + totalSize += savedSize; + + setNumber(message, totalSize, TRUE); + appendText(message, L" bytes of the computer data are saved ("); + appendNumber(message, (__rdtsc() - beginningTick) * 1000000 / frequency, TRUE); + appendText(message, L" microseconds)."); + logToConsole(message); + return true; } static bool saveSystem(CHAR16* directory) @@ -6492,6 +6508,15 @@ static void processKeyPresses() CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 4] = L'0'; CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 3] = L'0'; CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 2] = L'0'; + + CONTRACT_EXEC_FEES_ACC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME[0]) - 4] = L'0'; + CONTRACT_EXEC_FEES_ACC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME[0]) - 3] = L'0'; + CONTRACT_EXEC_FEES_ACC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_ACC_FILE_NAME[0]) - 2] = L'0'; + + CONTRACT_EXEC_FEES_REC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME[0]) - 4] = L'0'; + CONTRACT_EXEC_FEES_REC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME[0]) - 3] = L'0'; + CONTRACT_EXEC_FEES_REC_FILE_NAME[sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME) / sizeof(CONTRACT_EXEC_FEES_REC_FILE_NAME[0]) - 2] = L'0'; + saveComputer(); #ifdef ENABLE_PROFILING From 18658fd292566aa9d6ea058e47984773b8d385be Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Mon, 1 Dec 2025 17:04:51 +0100 Subject: [PATCH 2/3] add save methods to ExecutionTimeAccumulator and ExecutionFeeReportCollector --- .../execution_time_accumulator.h | 13 ++++++++- src/qubic.cpp | 28 ++++++++++--------- src/ticking/execution_fee_report_collector.h | 9 ++++++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/contract_core/execution_time_accumulator.h b/src/contract_core/execution_time_accumulator.h index df2509792..d66f4733c 100644 --- a/src/contract_core/execution_time_accumulator.h +++ b/src/contract_core/execution_time_accumulator.h @@ -1,5 +1,7 @@ #pragma once +#include "platform/file_io.h" + // A class for accumulating contract execution time over a phase. // Also saves the accumulation result of the previous phase. class ExecutionTimeAccumulator @@ -12,7 +14,7 @@ class ExecutionTimeAccumulator // TODO: check if this overflows with CPU clock cycles, if it does, save in different unit (e.g. milliseconds) long long contractExecutionTimePerPhase[2][contractCount]; - bool contractExecutionTimeActiveArrayIndex; + bool contractExecutionTimeActiveArrayIndex = 0; volatile char lock = 0; public: @@ -59,4 +61,13 @@ class ExecutionTimeAccumulator return contractExecutionTimePerPhase[!contractExecutionTimeActiveArrayIndex]; } + bool saveToFile(const CHAR16* fileName, const CHAR16* directory = NULL) + { + long long savedSize = save(fileName, sizeof(ExecutionTimeAccumulator), (unsigned char*)this, directory); + if (savedSize == sizeof(ExecutionTimeAccumulator)) + return true; + else + return false; + } + }; diff --git a/src/qubic.cpp b/src/qubic.cpp index 58a53dc25..9452444f9 100644 --- a/src/qubic.cpp +++ b/src/qubic.cpp @@ -5297,7 +5297,7 @@ static bool saveComputer(CHAR16* directory) { logToConsole(L"Saving contract files..."); - const unsigned long long beginningTick = __rdtsc(); + unsigned long long beginningTick = __rdtsc(); unsigned long long totalSize = 0; long long savedSize = 0; @@ -5318,25 +5318,27 @@ static bool saveComputer(CHAR16* directory) } } + setNumber(message, totalSize, TRUE); + appendText(message, L" bytes of the contract state files are saved ("); + appendNumber(message, (__rdtsc() - beginningTick) * 1000000 / frequency, TRUE); + appendText(message, L" microseconds)."); + logToConsole(message); + logToConsole(L"Saving contract execution fee files..."); - savedSize += save(CONTRACT_EXEC_FEES_ACC_FILE_NAME, sizeof(contractExecutionTimePerPhase), (unsigned char*)contractExecutionTimePerPhase, directory); - if (savedSize != sizeof(contractExecutionTimePerPhase)) - { + + beginningTick = __rdtsc(); + + if (!executionTimeAccumulator.saveToFile(CONTRACT_EXEC_FEES_ACC_FILE_NAME, directory)) return false; - } - totalSize += savedSize; - savedSize = executionFeeReportCollector.save(CONTRACT_EXEC_FEES_REC_FILE_NAME); - if (savedSize < 0) - { + + if (!executionFeeReportCollector.saveToFile(CONTRACT_EXEC_FEES_REC_FILE_NAME, directory)) return false; - } - totalSize += savedSize; - setNumber(message, totalSize, TRUE); - appendText(message, L" bytes of the computer data are saved ("); + setText(message, L"Accumulated execution times and received fee reports are saved ("); appendNumber(message, (__rdtsc() - beginningTick) * 1000000 / frequency, TRUE); appendText(message, L" microseconds)."); logToConsole(message); + return true; } diff --git a/src/ticking/execution_fee_report_collector.h b/src/ticking/execution_fee_report_collector.h index ee483bb96..fe798f776 100644 --- a/src/ticking/execution_fee_report_collector.h +++ b/src/ticking/execution_fee_report_collector.h @@ -125,4 +125,13 @@ class ExecutionFeeReportCollector reset(); } + + bool saveToFile(const CHAR16* fileName, const CHAR16* directory = NULL) + { + long long savedSize = save(fileName, sizeof(ExecutionFeeReportCollector), (unsigned char*)this, directory); + if (savedSize == sizeof(ExecutionFeeReportCollector)) + return true; + else + return false; + } }; From 5b26a5db5d3e8575de2335ccbb28cb720fad2297 Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Tue, 2 Dec 2025 14:58:34 +0100 Subject: [PATCH 3/3] add loadFromFile to ExecutionTimeAccumulator and ExecutionFeeReportCollector --- src/contract_core/execution_time_accumulator.h | 9 +++++++++ src/qubic.cpp | 13 +++++++++++++ src/ticking/execution_fee_report_collector.h | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/src/contract_core/execution_time_accumulator.h b/src/contract_core/execution_time_accumulator.h index d66f4733c..1d1beef2d 100644 --- a/src/contract_core/execution_time_accumulator.h +++ b/src/contract_core/execution_time_accumulator.h @@ -70,4 +70,13 @@ class ExecutionTimeAccumulator return false; } + bool loadFromFile(const CHAR16* fileName, const CHAR16* directory = NULL) + { + long long loadedSize = load(fileName, sizeof(ExecutionTimeAccumulator), (unsigned char*)this, directory); + if (loadedSize == sizeof(ExecutionTimeAccumulator)) + return true; + else + return false; + } + }; diff --git a/src/qubic.cpp b/src/qubic.cpp index 9452444f9..cddc1be62 100644 --- a/src/qubic.cpp +++ b/src/qubic.cpp @@ -5290,6 +5290,19 @@ static bool loadComputer(CHAR16* directory, bool forceLoadFromFile) logToConsole(message); } } + + logToConsole(L"All contract files successfully loaded or initialized."); + + logToConsole(L"Loading contract execution fee files..."); + + if (!executionTimeAccumulator.loadFromFile(CONTRACT_EXEC_FEES_ACC_FILE_NAME, directory)) + return false; + + if (!executionFeeReportCollector.loadFromFile(CONTRACT_EXEC_FEES_REC_FILE_NAME, directory)) + return false; + + logToConsole(L"Accumulated execution times and received fee reports successfully loaded."); + return true; } diff --git a/src/ticking/execution_fee_report_collector.h b/src/ticking/execution_fee_report_collector.h index fe798f776..30628c14c 100644 --- a/src/ticking/execution_fee_report_collector.h +++ b/src/ticking/execution_fee_report_collector.h @@ -134,4 +134,13 @@ class ExecutionFeeReportCollector else return false; } + + bool loadFromFile(const CHAR16* fileName, const CHAR16* directory = NULL) + { + long long loadedSize = load(fileName, sizeof(ExecutionFeeReportCollector), (unsigned char*)this, directory); + if (loadedSize == sizeof(ExecutionFeeReportCollector)) + return true; + else + return false; + } };