Skip to content

Commit

Permalink
Merge pull request #23 from qubic/release/ep88
Browse files Browse the repository at this point in the history
Release/ep88 to main
  • Loading branch information
philippwerner authored Dec 20, 2023
2 parents b7877de + e194cf4 commit bd82eae
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 215 deletions.
1 change: 1 addition & 0 deletions src/Qubic.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ClInclude Include="logging.h" />
<ClInclude Include="network_messages.h" />
<ClInclude Include="peers.h" />
<ClInclude Include="platform\algorithm.h" />
<ClInclude Include="platform\concurrency.h" />
<ClInclude Include="four_q.h" />
<ClInclude Include="kangaroo_twelve.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 @@ -57,6 +57,9 @@
<ClInclude Include="system.h" />
<ClInclude Include="assets.h" />
<ClInclude Include="logging.h" />
<ClInclude Include="platform\algorithm.h">
<Filter>platform</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="smart_contracts">
Expand Down
57 changes: 35 additions & 22 deletions src/assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,65 +71,78 @@ struct Asset
};


#define REQUEST_ISSUED_ASSETS 36

typedef struct
struct RequestIssuedAssets
{
m256i publicKey;
} RequestIssuedAssets;

static_assert(sizeof(RequestIssuedAssets) == 32, "Something is wrong with the struct size.");
enum {
type = 36,
};
};

static_assert(sizeof(RequestIssuedAssets) == 32, "Something is wrong with the struct size.");

#define RESPOND_ISSUED_ASSETS 37

typedef struct
struct RespondIssuedAssets
{
Asset asset;
unsigned int tick;
// TODO: Add siblings
} RespondIssuedAssets;

enum {
type = 37,
};
};

#define REQUEST_OWNED_ASSETS 38

typedef struct
struct RequestOwnedAssets
{
m256i publicKey;
} RequestOwnedAssets;

static_assert(sizeof(RequestOwnedAssets) == 32, "Something is wrong with the struct size.");
enum {
type = 38,
};
};

static_assert(sizeof(RequestOwnedAssets) == 32, "Something is wrong with the struct size.");

#define RESPOND_OWNED_ASSETS 39

typedef struct
{
Asset asset;
Asset issuanceAsset;
unsigned int tick;
// TODO: Add siblings

enum {
type = 39,
};
} RespondOwnedAssets;

#define REQUEST_POSSESSED_ASSETS 40

typedef struct
{
m256i publicKey;

enum {
type = 40,
};
} RequestPossessedAssets;

static_assert(sizeof(RequestPossessedAssets) == 32, "Something is wrong with the struct size.");


#define RESPOND_POSSESSED_ASSETS 41

typedef struct
{
Asset asset;
Asset ownershipAsset;
Asset issuanceAsset;
unsigned int tick;
// TODO: Add siblings

enum {
type = 41,
};
} RespondPossessedAssets;


Expand Down Expand Up @@ -400,7 +413,7 @@ static void processRequestIssuedAssets(Peer* peer, RequestResponseHeader* header
if (universeIndex >= ASSETS_CAPACITY
|| assets[universeIndex].varStruct.issuance.type == EMPTY)
{
enqueueResponse(peer, 0, END_RESPONSE, header->dejavu(), NULL);
enqueueResponse(peer, 0, EndResponse::type, header->dejavu(), NULL);
}
else
{
Expand All @@ -410,7 +423,7 @@ static void processRequestIssuedAssets(Peer* peer, RequestResponseHeader* header
bs->CopyMem(&response.asset, &assets[universeIndex], sizeof(Asset));
response.tick = system.tick;

enqueueResponse(peer, sizeof(response), RESPOND_ISSUED_ASSETS, header->dejavu(), &response);
enqueueResponse(peer, sizeof(response), RespondIssuedAssets::type, header->dejavu(), &response);
}

universeIndex = (universeIndex + 1) & (ASSETS_CAPACITY - 1);
Expand All @@ -435,7 +448,7 @@ static void processRequestOwnedAssets(Peer* peer, RequestResponseHeader* header)
if (universeIndex >= ASSETS_CAPACITY
|| assets[universeIndex].varStruct.issuance.type == EMPTY)
{
enqueueResponse(peer, 0, END_RESPONSE, header->dejavu(), NULL);
enqueueResponse(peer, 0, EndResponse::type, header->dejavu(), NULL);
}
else
{
Expand All @@ -446,7 +459,7 @@ static void processRequestOwnedAssets(Peer* peer, RequestResponseHeader* header)
bs->CopyMem(&response.issuanceAsset, &assets[assets[universeIndex].varStruct.ownership.issuanceIndex], sizeof(Asset));
response.tick = system.tick;

enqueueResponse(peer, sizeof(response), RESPOND_OWNED_ASSETS, header->dejavu(), &response);
enqueueResponse(peer, sizeof(response), RespondOwnedAssets::type, header->dejavu(), &response);
}

universeIndex = (universeIndex + 1) & (ASSETS_CAPACITY - 1);
Expand All @@ -471,7 +484,7 @@ static void processRequestPossessedAssets(Peer* peer, RequestResponseHeader* hea
if (universeIndex >= ASSETS_CAPACITY
|| assets[universeIndex].varStruct.issuance.type == EMPTY)
{
enqueueResponse(peer, 0, END_RESPONSE, header->dejavu(), NULL);
enqueueResponse(peer, 0, EndResponse::type, header->dejavu(), NULL);
}
else
{
Expand All @@ -483,7 +496,7 @@ static void processRequestPossessedAssets(Peer* peer, RequestResponseHeader* hea
bs->CopyMem(&response.issuanceAsset, &assets[assets[assets[universeIndex].varStruct.possession.ownershipIndex].varStruct.ownership.issuanceIndex], sizeof(Asset));
response.tick = system.tick;

enqueueResponse(peer, sizeof(response), RESPOND_POSSESSED_ASSETS, header->dejavu(), &response);
enqueueResponse(peer, sizeof(response), RespondPossessedAssets::type, header->dejavu(), &response);
}

universeIndex = (universeIndex + 1) & (ASSETS_CAPACITY - 1);
Expand Down
1 change: 0 additions & 1 deletion src/four_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "platform/memory.h"
#include "platform/m256.h"

#include "public_settings.h"
#include "kangaroo_twelve.h"


Expand Down
2 changes: 0 additions & 2 deletions src/kangaroo_twelve.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "platform/memory.h"

#include "public_settings.h"


////////// KangarooTwelve \\\\\\\\\\
Expand Down
19 changes: 9 additions & 10 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ struct RequestLog
{
unsigned long long passcode[4];

static constexpr unsigned char type()
{
return 44;
}
enum {
type = 44,
};
};


Expand All @@ -26,10 +25,9 @@ struct RespondLog
{
// Variable-size log;

static constexpr unsigned char type()
{
return 45;
}
enum {
type = 45,
};
};


Expand All @@ -52,6 +50,7 @@ static bool logBufferOverflownFlags[sizeof(logReaderPasscodes) / sizeof(logReade
static bool initLogging()
{
#if LOG_QU_TRANSFERS | LOG_ASSET_ISSUANCES | LOG_ASSET_OWNERSHIP_CHANGES | LOG_ASSET_POSSESSION_CHANGES | LOG_CONTRACT_ERROR_MESSAGES | LOG_CONTRACT_WARNING_MESSAGES | LOG_CONTRACT_INFO_MESSAGES | LOG_CONTRACT_DEBUG_MESSAGES | LOG_CUSTOM_MESSAGES
EFI_STATUS status;
for (unsigned int logReaderIndex = 0; logReaderIndex < sizeof(logReaderPasscodes) / sizeof(logReaderPasscodes[0]); logReaderIndex++)
{
if (status = bs->AllocatePool(EfiRuntimeServicesData, LOG_BUFFER_SIZE, (void**)&logBuffers[logReaderIndex]))
Expand Down Expand Up @@ -310,7 +309,7 @@ static void processRequestLog(Peer* peer, RequestResponseHeader* header)
}
else
{
enqueueResponse(peer, logBufferTails[logReaderIndex], RespondLog::type(), header->dejavu(), logBuffers[logReaderIndex]);
enqueueResponse(peer, logBufferTails[logReaderIndex], RespondLog::type, header->dejavu(), logBuffers[logReaderIndex]);
logBufferTails[logReaderIndex] = 0;
}

Expand All @@ -320,5 +319,5 @@ static void processRequestLog(Peer* peer, RequestResponseHeader* header)
}
}

enqueueResponse(peer, 0, RespondLog::type(), header->dejavu(), NULL);
enqueueResponse(peer, 0, RespondLog::type, header->dejavu(), NULL);
}
23 changes: 15 additions & 8 deletions src/network_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,28 @@ struct RequestResponseHeader
}
};

#define EXCHANGE_PUBLIC_PEERS 0
#define NUMBER_OF_EXCHANGED_PEERS 4

typedef struct
struct ExchangePublicPeers
{
unsigned char peers[NUMBER_OF_EXCHANGED_PEERS][4];
} ExchangePublicPeers;

#define END_RESPONSE 35
enum {
type = 0,
};
};


struct EndResponse
{
enum {
type = 35,
};
};

struct TryAgain // Must be returned if _dejavu is not 0, and the incoming packet cannot be processed (usually when incoming packets queue is full)
{
static constexpr unsigned char type()
{
return 46;
}
enum {
type = 46,
};
};
4 changes: 3 additions & 1 deletion src/peers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

#include "platform/uefi.h"
#include "platform/random.h"
#include "platform/concurrency.h"

#include "network_messages.h"
#include "tcp4.h"
#include "kangaroo_twelve.h"

#define DEJAVU_SWAP_LIMIT 1000000
#define DISSEMINATION_MULTIPLIER 4
Expand Down Expand Up @@ -460,7 +462,7 @@ static void peerReceiveAndTransmit(unsigned int i, unsigned int salt)
{
_InterlockedIncrement64(&numberOfDiscardedRequests);

enqueueResponse(&peers[i], 0, TryAgain::type(), requestResponseHeader->dejavu(), NULL);
enqueueResponse(&peers[i], 0, TryAgain::type, requestResponseHeader->dejavu(), NULL);
}
}
else
Expand Down
20 changes: 20 additions & 0 deletions src/platform/algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#ifdef NO_UEFI

#include <algorithm>

#else

namespace std
{

template <class T>
constexpr const T& max(const T& left, const T& right)
{
return left < right ? right : left;
}

}

#endif
4 changes: 2 additions & 2 deletions src/platform/console_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ static CHAR16 message[16384], timestampedMessage[16384];
// Output to console on no-UEFI platform
static inline void outputStringToConsole(CHAR16* str)
{
std::wprintf(L"%ls", str);
wprintf(L"%ls", str);
}

// Log message to console (with line break) on non-UEFI platform
static void logToConsole(const CHAR16* message)
{
if (disableConsoleLogging)
return;
std::wprintf(L"%ls\n", message);
wprintf(L"%ls\n", message);
}

#else
Expand Down
20 changes: 10 additions & 10 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
#define MAX_NUMBER_OF_PROCESSORS 32

#define VERSION_A 1
#define VERSION_B 184
#define VERSION_B 185
#define VERSION_C 0

#define EPOCH 87
#define TICK 11400000
#define EPOCH 88
#define TICK 11550000

#define RANDOM_SEED0 14
#define RANDOM_SEED0 46
#define RANDOM_SEED1 69
#define RANDOM_SEED2 123
#define RANDOM_SEED3 231
#define RANDOM_SEED4 222
#define RANDOM_SEED5 7
#define RANDOM_SEED6 34
#define RANDOM_SEED7 131
#define RANDOM_SEED2 22
#define RANDOM_SEED3 88
#define RANDOM_SEED4 14
#define RANDOM_SEED5 41
#define RANDOM_SEED6 202
#define RANDOM_SEED7 65

#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"

Expand Down
2 changes: 1 addition & 1 deletion src/qpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4963,7 +4963,7 @@ namespace QPI
{
private:
static_assert(N >= 2 && !(N & (N - 1)) && N <= 33554432,
"Size of index must be 2 to the power of n. At least 2, at most 33554432."
"Capacity of index (template param N) must be 2 to the power of a natural number. N must be at least 2, at most 33554432."
);

id _values[N];
Expand Down
Loading

0 comments on commit bd82eae

Please sign in to comment.