Skip to content

Commit

Permalink
Merge pull request #88 from qubic/release/v1.199
Browse files Browse the repository at this point in the history
Release/v1.199 to main
  • Loading branch information
philippwerner authored Apr 10, 2024
2 parents 8ddf625 + 9526543 commit 13bcccc
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 230 deletions.
5 changes: 4 additions & 1 deletion src/network_messages/system_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#define RESPOND_SYSTEM_INFO 47

#pragma pack(push, 1)
struct RespondSystemInfo
{
short version;
Expand All @@ -27,6 +28,8 @@ struct RespondSystemInfo
unsigned int numberOfTransactions;

m256i randomMiningSeed;
int solutionThreshold;
};
#pragma pack(pop)

static_assert(sizeof(RespondSystemInfo) == 2 + 2 + 4 + 4 + 4 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 4 + 32 + 4, "Something is wrong with the struct size of RespondSystemInfo.");
static_assert(sizeof(RespondSystemInfo) == (2 + 2 + 4 + 4 + 4) + (2 + 1 + 1 + 1 + 1 + 1 + 1) + (4 + 4) + (32 + 4), "Something is wrong with the struct size of RespondSystemInfo.");
12 changes: 6 additions & 6 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
// Set START_NETWORK_FROM_SCRATCH to 0 if you start the node for syncing with the already ticking network.
// If this flag is 1, it indicates that the whole network (all 676 IDs) will start from scratch and agree that the very first tick time will be set at (2022-04-13 Wed 12:00:00.000UTC).
// If this flag is 0, the node will try to fetch the initial tick of the epoch from other nodes, because the tick's timestamp may differ from (2022-04-13 Wed 12:00:00.000UTC).
#define START_NETWORK_FROM_SCRATCH 0
#define START_NETWORK_FROM_SCRATCH 1

//////////////////////////////////////////////////////////////////////////
// Config options that should NOT be changed by operators

#define VERSION_A 1
#define VERSION_B 198
#define VERSION_B 199
#define VERSION_C 0

#define EPOCH 103
#define TICK 13218818
#define EPOCH 104
#define TICK 13360000

#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"

Expand All @@ -47,8 +47,8 @@ static unsigned short CONTRACT_FILE_NAME[] = L"contract????.???";

#define DATA_LENGTH 256
#define INFO_LENGTH 128
#define NUMBER_OF_INPUT_NEURONS 2048
#define NUMBER_OF_OUTPUT_NEURONS 2048
#define NUMBER_OF_INPUT_NEURONS 4096
#define NUMBER_OF_OUTPUT_NEURONS 4096
#define MAX_INPUT_DURATION 256
#define MAX_OUTPUT_DURATION 256
#define NEURON_VALUE_LIMIT 1LL
Expand Down
84 changes: 75 additions & 9 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ static struct
RequestedTickTransactions requestedTickTransactions;
} requestedTickTransactions;




static struct {
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char second;
} threadTimeCheckin[MAX_NUMBER_OF_PROCESSORS];

static void logToConsole(const CHAR16* message)
{
Expand Down Expand Up @@ -1050,6 +1053,7 @@ static void processRequestContractFunction(Peer* peer, const unsigned long long
RespondContractFunction* response = (RespondContractFunction*)contractFunctionOutputs[processorNumber];

RequestContractFunction* request = header->getPayload<RequestContractFunction>();
ACQUIRE(executedContractIndexLock);
executedContractIndex = request->contractIndex;
if (header->size() != sizeof(RequestResponseHeader) + sizeof(RequestContractFunction) + request->inputSize
|| !executedContractIndex || executedContractIndex >= sizeof(contractDescriptions) / sizeof(contractDescriptions[0])
Expand All @@ -1074,6 +1078,7 @@ static void processRequestContractFunction(Peer* peer, const unsigned long long

enqueueResponse(peer, contractUserFunctionOutputSizes[executedContractIndex][request->inputType], response->type, header->dejavu(), response);
}
RELEASE(executedContractIndexLock);
}

static void processRequestSystemInfo(Peer* peer, RequestResponseHeader* header)
Expand All @@ -1098,6 +1103,7 @@ static void processRequestSystemInfo(Peer* peer, RequestResponseHeader* header)
respondedSystemInfo.numberOfTransactions = numberOfTransactions;

respondedSystemInfo.randomMiningSeed = score->initialRandomSeed;
respondedSystemInfo.solutionThreshold = (system.epoch < MAX_NUMBER_EPOCH) ? solutionThreshold[system.epoch] : SOLUTION_THRESHOLD_DEFAULT;

enqueueResponse(peer, sizeof(respondedSystemInfo), RESPOND_SYSTEM_INFO, header->dejavu(), &respondedSystemInfo);
}
Expand Down Expand Up @@ -1229,6 +1235,15 @@ static void processSpecialCommand(Peer* peer, RequestResponseHeader* header)
}
}

// a tracker to detect if a thread is crashed
static void checkinTime(unsigned long long processorNumber)
{
threadTimeCheckin[processorNumber].second = time.Second;
threadTimeCheckin[processorNumber].minute = time.Minute;
threadTimeCheckin[processorNumber].hour = time.Hour;
threadTimeCheckin[processorNumber].day = time.Day;
}

static void requestProcessor(void* ProcedureArgument)
{
enableAVX();
Expand All @@ -1240,6 +1255,7 @@ static void requestProcessor(void* ProcedureArgument)
RequestResponseHeader* header = (RequestResponseHeader*)processor->buffer;
while (!shutDownNode)
{
checkinTime(processorNumber);
// in epoch transition, wait here
if (epochTransitionState)
{
Expand Down Expand Up @@ -1421,6 +1437,13 @@ static void requestProcessor(void* ProcedureArgument)
}
}

// Return reference to fee reserve of contract for changing its value (data stored in state of contract 0)
static long long & contractFeeReserve(unsigned int contractIndex)
{
contractStateChangeFlags[0] |= 1ULL;
return ((Contract0State*)contractStates[0])->contractFeeReserves[contractIndex];
}

static void __beginFunctionOrProcedure(const unsigned int functionOrProcedureId)
{
// TODO
Expand Down Expand Up @@ -1473,8 +1496,7 @@ static long long __burn(long long amount)

if (decreaseEnergy(index, amount))
{
Contract0State* contract0State = (Contract0State*)contractStates[0];
contract0State->contractFeeReserves[executedContractIndex] += amount;
contractFeeReserve(executedContractIndex) += amount;

const Burning burning = { currentContract , amount };
logBurning(burning);
Expand Down Expand Up @@ -1891,6 +1913,8 @@ static void contractProcessor(void*)
unsigned long long processorNumber;
mpServicesProtocol->WhoAmI(mpServicesProtocol, &processorNumber);

ACQUIRE(executedContractIndexLock);

switch (contractProcessorPhase)
{
case INITIALIZE:
Expand Down Expand Up @@ -1993,6 +2017,8 @@ static void contractProcessor(void*)
}
break;
}

RELEASE(executedContractIndexLock);
}

static void processTick(unsigned long long processorNumber)
Expand Down Expand Up @@ -2147,10 +2173,12 @@ static void processTick(unsigned long long processorNumber)
// only 32 bits are used for the contract index.
m256i maskedDestinationPublicKey = transaction->destinationPublicKey;
maskedDestinationPublicKey.m256i_u64[0] &= ~(MAX_NUMBER_OF_CONTRACTS - 1ULL);
executedContractIndex = (unsigned int)transaction->destinationPublicKey.m256i_u64[0];
unsigned int contractIndex = (unsigned int)transaction->destinationPublicKey.m256i_u64[0];
if (isZero(maskedDestinationPublicKey)
&& executedContractIndex < sizeof(contractDescriptions) / sizeof(contractDescriptions[0]))
&& contractIndex < sizeof(contractDescriptions) / sizeof(contractDescriptions[0]))
{
ACQUIRE(executedContractIndexLock);
executedContractIndex = contractIndex;
if (system.epoch < contractDescriptions[executedContractIndex].constructionEpoch)
{
if (!transaction->amount
Expand Down Expand Up @@ -2253,6 +2281,7 @@ static void processTick(unsigned long long processorNumber)
contractTotalExecutionTicks[executedContractIndex] += __rdtsc() - startTick;
}
}
RELEASE(executedContractIndexLock);
}
else
{
Expand Down Expand Up @@ -2743,7 +2772,6 @@ static void endEpoch()
getUniverseDigest(etalonTick.prevUniverseDigest);
getComputerDigest(etalonTick.prevComputerDigest);

Contract0State* contract0State = (Contract0State*)contractStates[0];
for (unsigned int contractIndex = 1; contractIndex < sizeof(contractDescriptions) / sizeof(contractDescriptions[0]); contractIndex++)
{
if (system.epoch < contractDescriptions[contractIndex].constructionEpoch)
Expand Down Expand Up @@ -2794,7 +2822,7 @@ static void endEpoch()
logQuTransfer(quTransfer);
}

contract0State->contractFeeReserves[contractIndex] = finalPrice * NUMBER_OF_COMPUTORS;
contractFeeReserve(contractIndex) = finalPrice * NUMBER_OF_COMPUTORS;
}
}

Expand Down Expand Up @@ -3044,6 +3072,7 @@ static void tickProcessor(void*)
unsigned int latestProcessedTick = 0;
while (!shutDownNode)
{
checkinTime(processorNumber);
const unsigned long long curTimeTick = __rdtsc();
const unsigned int nextTick = system.tick + 1;

Expand Down Expand Up @@ -4598,6 +4627,43 @@ static void processKeyPresses()
appendText(message, L"&");
appendText(message, (mainAuxStatus & 2) ? L"MAIN" : L"aux");
logToConsole(message);

// print statuses of thread
// this accepts a small error when switching day to first day of the next month
bool allThreadsAreGood = true;
setText(message, L"Thread status: ");
for (int i = 0; i < nTickProcessorIDs; i++)
{
unsigned long long tid = tickProcessorIDs[i];
long long diffInSecond = 86400 * (time.Day - threadTimeCheckin[tid].day) + 3600 * (time.Hour - threadTimeCheckin[tid].hour)
+ 60 * (time.Minute - threadTimeCheckin[tid].minute) + (time.Second - threadTimeCheckin[tid].second);
if (diffInSecond > 120) // if they don't check in in 2 minutes, we can assume the thread is already crashed
{
allThreadsAreGood = false;
appendText(message, L"Tick Processor #");
appendNumber(message, tid, false);
appendText(message, L" is not responsive | ");
}
}

for (int i = 0; i < nRequestProcessorIDs; i++)
{
unsigned long long tid = requestProcessorIDs[i];
long long diffInSecond = 86400 * (time.Day - threadTimeCheckin[tid].day) + 3600 * (time.Hour - threadTimeCheckin[tid].hour)
+ 60 * (time.Minute - threadTimeCheckin[tid].minute) + (time.Second - threadTimeCheckin[tid].second);
if (diffInSecond > 120) // if they don't check in in 2 minutes, we can assume the thread is already crashed
{
allThreadsAreGood = false;
appendText(message, L"Request Processor #");
appendNumber(message, tid, false);
appendText(message, L" is not responsive | ");
}
}
if (allThreadsAreGood)
{
appendText(message, L"All threads are healthy.");
}
logToConsole(message);
}
break;

Expand Down
Loading

0 comments on commit 13bcccc

Please sign in to comment.