Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/contract_core/execution_time_accumulator.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -59,4 +61,22 @@ 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;
}

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;
}

};
2 changes: 2 additions & 0 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 56 additions & 16 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -5282,17 +5290,30 @@ 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;
}

static bool saveComputer(CHAR16* directory)
{
logToConsole(L"Saving contract files...");

const unsigned long long beginningTick = __rdtsc();
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++)
{
Expand All @@ -5301,27 +5322,37 @@ 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)
{
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;
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...");

beginningTick = __rdtsc();

if (!executionTimeAccumulator.saveToFile(CONTRACT_EXEC_FEES_ACC_FILE_NAME, directory))
return false;

if (!executionFeeReportCollector.saveToFile(CONTRACT_EXEC_FEES_REC_FILE_NAME, directory))
return false;

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;
}

static bool saveSystem(CHAR16* directory)
Expand Down Expand Up @@ -6492,6 +6523,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
Expand Down
18 changes: 18 additions & 0 deletions src/ticking/execution_fee_report_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,22 @@ 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;
}

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;
}
};