Skip to content
Closed
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
1 change: 1 addition & 0 deletions doc/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The type number is the identifier used in `RequestResponseHeader` (defined in `h
- `RequestAssets`, type 52, defined in `assets.h`.
- `RespondAssets` and `RespondAssetsWithSiblings`, type 53, defined in `assets.h`.
- `TryAgain`, type 54, defined in `common_response.h`.
- `RequestedCustomMiningVerification`, type 55, defined in `custom_mining.h`.
- `SpecialCommand`, type 255, defined in `special_command.h`.

Addon messages (supported if addon is enabled):
Expand Down
1 change: 1 addition & 0 deletions src/Qubic.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ClInclude Include="network_messages\common_response.h" />
<ClInclude Include="network_messages\computors.h" />
<ClInclude Include="network_messages\contract.h" />
<ClInclude Include="network_messages\custom_mining.h" />
<ClInclude Include="network_messages\entity.h" />
<ClInclude Include="network_messages\header.h" />
<ClInclude Include="network_messages\logging.h" />
Expand Down
3 changes: 3 additions & 0 deletions src/Qubic.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
<ClInclude Include="contracts\TestExampleC.h">
<Filter>contracts</Filter>
</ClInclude>
<ClInclude Include="network_messages\custom_mining.h">
<Filter>network_messages</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="platform">
Expand Down
1 change: 1 addition & 0 deletions src/network_messages/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#include "tick.h"
#include "transactions.h"
#include "system_info.h"
#include "custom_mining.h"
14 changes: 14 additions & 0 deletions src/network_messages/custom_mining.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

struct RequestedCustomMiningVerification
{
enum
{
type = 55,
};
unsigned long long everIncreasingNonceAndCommandType;
unsigned long long taskIndex;
unsigned int nonce;
unsigned int padding; // use later
};

77 changes: 60 additions & 17 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ static CustomMiningSharesCounter gCustomMiningSharesCounter;
static volatile char gCustomMiningSharesCountLock = 0;
static char gIsInCustomMiningState = 0;
static volatile char gIsInCustomMiningStateLock = 0;
static unsigned long long gCustomMinninglatestOperatorNonce = 0;

struct revenueScore
{
Expand Down Expand Up @@ -242,6 +243,7 @@ struct
unsigned int numberOfMiners;
unsigned int numberOfTransactions;
unsigned long long lastLogId;
unsigned char customMiningSharesCounterData[CustomMiningSharesCounter::_customMiningSolutionCounterDataSize];
} nodeStateBuffer;
#endif
static bool saveComputer(CHAR16* directory = NULL);
Expand Down Expand Up @@ -540,23 +542,23 @@ static void processBroadcastMessage(const unsigned long long processorNumber, Re
customMiningMessageCounters[i]++;

// Only record shares in idle phase
char recordSolutions = 0;
ACQUIRE(gIsInCustomMiningStateLock);
recordSolutions = gIsInCustomMiningState;
RELEASE(gIsInCustomMiningStateLock);

if (recordSolutions)
{
// Record the solution
const CustomMiningSolution* solution = ((CustomMiningSolution*)((unsigned char*)request + sizeof(BroadcastMessage)));

// Check the computor idx of this solution
unsigned short computorID = solution->nonce % NUMBER_OF_COMPUTORS;

ACQUIRE(gCustomMiningSharesCountLock);
gCustomMiningSharesCount[computorID]++;
RELEASE(gCustomMiningSharesCountLock);
}
//char recordSolutions = 0;
//ACQUIRE(gIsInCustomMiningStateLock);
//recordSolutions = gIsInCustomMiningState;
//RELEASE(gIsInCustomMiningStateLock);

//if (recordSolutions)
//{
// // Record the solution
// const CustomMiningSolution* solution = ((CustomMiningSolution*)((unsigned char*)request + sizeof(BroadcastMessage)));

// // Check the computor idx of this solution
// unsigned short computorID = solution->nonce % NUMBER_OF_COMPUTORS;

// ACQUIRE(gCustomMiningSharesCountLock);
// gCustomMiningSharesCount[computorID]++;
// RELEASE(gCustomMiningSharesCountLock);
//}
}

break;
Expand Down Expand Up @@ -1264,6 +1266,39 @@ static void processRequestSystemInfo(Peer* peer, RequestResponseHeader* header)
enqueueResponse(peer, sizeof(respondedSystemInfo), RESPOND_SYSTEM_INFO, header->dejavu(), &respondedSystemInfo);
}

static void processCustomMiningRequest(Peer* peer, RequestResponseHeader* header)
{
RequestedCustomMiningVerification* request = header->getPayload<RequestedCustomMiningVerification>();
if (header->size() >= sizeof(RequestResponseHeader) + sizeof(RequestedCustomMiningVerification) + SIGNATURE_SIZE
&& (request->everIncreasingNonceAndCommandType & 0xFFFFFFFFFFFFFF) > gCustomMinninglatestOperatorNonce)
{
unsigned char digest[32];
KangarooTwelve(request, header->size() - sizeof(RequestResponseHeader) - SIGNATURE_SIZE, digest, sizeof(digest));
if (verify(operatorPublicKey.m256i_u8, digest, ((const unsigned char*)header + (header->size() - SIGNATURE_SIZE))))
{
gCustomMinninglatestOperatorNonce = request->everIncreasingNonceAndCommandType & 0xFFFFFFFFFFFFFF;

// Update the share counting
// Only record shares in idle phase
char recordSolutions = 0;
ACQUIRE(gIsInCustomMiningStateLock);
recordSolutions = gIsInCustomMiningState;
RELEASE(gIsInCustomMiningStateLock);

if (recordSolutions)
{
// Check the computor idx of this solution
const unsigned short computorID = request->nonce % NUMBER_OF_COMPUTORS;

ACQUIRE(gCustomMiningSharesCountLock);
gCustomMiningSharesCount[computorID]++;
RELEASE(gCustomMiningSharesCountLock);
}

}
}
}

static void processSpecialCommand(Peer* peer, RequestResponseHeader* header)
{
SpecialCommand* request = header->getPayload<SpecialCommand>();
Expand Down Expand Up @@ -1681,6 +1716,12 @@ static void requestProcessor(void* ProcedureArgument)
}
break;

case RequestedCustomMiningVerification::type:
{
processCustomMiningRequest(peer, header);
}
break;

case SpecialCommand::type:
{
processSpecialCommand(peer, header);
Expand Down Expand Up @@ -4078,6 +4119,7 @@ static bool saveAllNodeStates()
nodeStateBuffer.numberOfTransactions = numberOfTransactions;
nodeStateBuffer.lastLogId = logger.logId;
voteCounter.saveAllDataToArray(nodeStateBuffer.voteCounterData);
gCustomMiningSharesCounter.saveAllDataToArray(nodeStateBuffer.customMiningSharesCounterData);

CHAR16 NODE_STATE_FILE_NAME[] = L"snapshotNodeMiningState";
savedSize = save(NODE_STATE_FILE_NAME, sizeof(nodeStateBuffer), (unsigned char*)&nodeStateBuffer, directory);
Expand Down Expand Up @@ -4216,6 +4258,7 @@ static bool loadAllNodeStates()
logger.logId = nodeStateBuffer.lastLogId;
loadMiningSeedFromFile = true;
voteCounter.loadAllDataFromArray(nodeStateBuffer.voteCounterData);
gCustomMiningSharesCounter.loadAllDataFromArray(nodeStateBuffer.customMiningSharesCounterData);

// update own computor indices
for (unsigned int i = 0; i < NUMBER_OF_COMPUTORS; i++)
Expand Down
Loading