Skip to content

Commit

Permalink
Merge pull request #79 from qubic/2024-02-29-keep-some-ticks-after-ep…
Browse files Browse the repository at this point in the history
…och-transition

Fixes of seamless epoch transition
  • Loading branch information
philippwerner authored Mar 25, 2024
2 parents 676189b + 8006235 commit 84041f0
Show file tree
Hide file tree
Showing 16 changed files with 1,684 additions and 296 deletions.
4 changes: 2 additions & 2 deletions Qubic.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.Debug|x64.ActiveCfg = Release|x64
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.Debug|x64.ActiveCfg = Debug|x64
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.Debug|x64.Build.0 = Debug|x64
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.LinuxRelease|x64.ActiveCfg = LinuxRelease|x64
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.LinuxRelease|x64.Build.0 = LinuxRelease|x64
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.Release|x64.ActiveCfg = Release|x64
{6A7C1322-658B-4FD8-8150-A2F88202B57F}.Release|x64.Build.0 = Release|x64
{30E8E249-6B00-4575-BCDF-BE2445D5E099}.Debug|x64.ActiveCfg = Debug|x64
{30E8E249-6B00-4575-BCDF-BE2445D5E099}.Debug|x64.Build.0 = Debug|x64
{30E8E249-6B00-4575-BCDF-BE2445D5E099}.LinuxRelease|x64.ActiveCfg = Release|x64
{30E8E249-6B00-4575-BCDF-BE2445D5E099}.LinuxRelease|x64.Build.0 = Release|x64
{30E8E249-6B00-4575-BCDF-BE2445D5E099}.Release|x64.ActiveCfg = Release|x64
{30E8E249-6B00-4575-BCDF-BE2445D5E099}.Release|x64.Build.0 = Release|x64
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Qubic Node Source Code - this repository contains the source code of a full qubi
## Prerequisites
To run a qubic node, you need the following spec:
- Bare Metal Server/Computer with at least 8 Cores (high CPU frequency with AVX2 support). AVX-512 support is recommended; check supported CPUs [here](https://www.epey.co.uk/cpu/e/YTozOntpOjUwOTc7YToxOntpOjA7czo2OiI0Mjg1NzUiO31pOjUwOTk7YToyOntpOjA7czoxOiI4IjtpOjE7czoyOiIzMiI7fWk6NTA4ODthOjY6e2k6MDtzOjY6IjQ1NjE1MCI7aToxO3M6NzoiMjM4Nzg2MSI7aToyO3M6NzoiMTkzOTE5OSI7aTozO3M6NzoiMTUwMjg4MyI7aTo0O3M6NzoiMjA2Nzk5MyI7aTo1O3M6NzoiMjE5OTc1OSI7fX1fYjowOw==/)
- At least 128GB of RAM
- At least 256GB of RAM
- 1Gb/s synchronous internet connection
- A USB Stick or SSD/HD attached to the Computer (via NVMe M.2 or USB)
- UEFI Bios
Expand Down
73 changes: 71 additions & 2 deletions src/Qubic.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="LinuxRelease|x64">
<Configuration>LinuxRelease</Configuration>
<Platform>x64</Platform>
Expand Down Expand Up @@ -35,6 +39,7 @@
<ClInclude Include="platform\concurrency.h" />
<ClInclude Include="four_q.h" />
<ClInclude Include="kangaroo_twelve.h" />
<ClInclude Include="platform\debugging.h" />
<ClInclude Include="platform\file_io.h" />
<ClInclude Include="platform\console_logging.h" />
<ClInclude Include="platform\common_types.h" />
Expand All @@ -57,6 +62,7 @@
<ClInclude Include="smart_contracts.h" />
<ClInclude Include="platform\time.h" />
<ClInclude Include="platform\uefi.h" />
<ClInclude Include="tick_storage.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
Expand All @@ -73,6 +79,13 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='LinuxRelease|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
Expand All @@ -88,6 +101,9 @@
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='LinuxRelease|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
Expand All @@ -97,6 +113,11 @@
<TargetExt>.efi</TargetExt>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.efi</TargetExt>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='LinuxRelease|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.efi</TargetExt>
Expand All @@ -117,7 +138,7 @@
<StringPooling>true</StringPooling>
<UseFullPaths>false</UseFullPaths>
<Optimization>MaxSpeed</Optimization>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalOptions>/Gs1638400 %(AdditionalOptions)</AdditionalOptions>
<StackReserveSize>126976</StackReserveSize>
Expand Down Expand Up @@ -149,6 +170,54 @@
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
<OmitDefaultLibName>true</OmitDefaultLibName>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<StringPooling>true</StringPooling>
<UseFullPaths>false</UseFullPaths>
<Optimization>MaxSpeed</Optimization>
<LanguageStandard>stdcpp20</LanguageStandard>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalOptions>/Gs1638400 %(AdditionalOptions)</AdditionalOptions>
<StackReserveSize>126976</StackReserveSize>
<StackCommitSize>126976</StackCommitSize>
<DebugInformationFormat>None</DebugInformationFormat>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<OmitFramePointers>true</OmitFramePointers>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<ControlFlowGuard>false</ControlFlowGuard>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<FloatingPointExceptions>false</FloatingPointExceptions>
<CreateHotpatchableImage>false</CreateHotpatchableImage>
<GuardEHContMetadata>false</GuardEHContMetadata>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>$(IntDir)Qubic.asm</AssemblerListingLocation>
</ClCompile>
<Link>
<SubSystem>EFI Application</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<AdditionalDependencies>
</AdditionalDependencies>
<EntryPointSymbol>efi_main</EntryPointSymbol>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>false</DataExecutionPrevention>
<StackReserveSize>131072</StackReserveSize>
<StackCommitSize>131072</StackCommitSize>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='LinuxRelease|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand All @@ -164,7 +233,7 @@
<StringPooling>true</StringPooling>
<UseFullPaths>false</UseFullPaths>
<Optimization>MaxSpeed</Optimization>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalOptions>/Gs1638400 %(AdditionalOptions)</AdditionalOptions>
<StackReserveSize>126976</StackReserveSize>
Expand Down
4 changes: 4 additions & 0 deletions src/Qubic.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
<ClInclude Include="smart_contracts\QUtil.h">
<Filter>smart_contracts</Filter>
</ClInclude>
<ClInclude Include="tick_storage.h" />
<ClInclude Include="platform\debugging.h">
<Filter>platform</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="smart_contracts">
Expand Down
4 changes: 2 additions & 2 deletions src/network_core/peers.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static void enqueueResponse(Peer* peer, RequestResponseHeader* responseHeader)
RELEASE(responseQueueHeadLock);
}

static void enqueueResponse(Peer* peer, unsigned int dataSize, unsigned char type, unsigned int dejavu, void* data)
static void enqueueResponse(Peer* peer, unsigned int dataSize, unsigned char type, unsigned int dejavu, const void* data)
{
ACQUIRE(responseQueueHeadLock);

Expand All @@ -228,7 +228,7 @@ static void enqueueResponse(Peer* peer, unsigned int dataSize, unsigned char typ
responseHeader->setDejavu(dejavu);
if (data)
{
bs->CopyMem(&responseQueueBuffer[responseQueueBufferHead + sizeof(RequestResponseHeader)], data, dataSize);
copyMem(&responseQueueBuffer[responseQueueBufferHead + sizeof(RequestResponseHeader)], data, dataSize);
}
responseQueueBufferHead += responseHeader->size();
responseQueueElements[responseQueueElementHead].peer = peer;
Expand Down
4 changes: 4 additions & 0 deletions src/network_messages/common_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#define NUMBER_OF_EXCHANGED_PEERS 4
#define SPECTRUM_DEPTH 24 // Defines SPECTRUM_CAPACITY (1 << SPECTRUM_DEPTH)

#define MAX_INPUT_SIZE 1024ULL
#define ISSUANCE_RATE 1000000000000LL
#define MAX_AMOUNT (ISSUANCE_RATE * 1000ULL)


// If you want to use the network_meassges directory in your project without dependencies to other code,
// you may define NETWORK_MESSAGES_WITHOUT_CORE_DEPENDENCIES before including any header or change the
Expand Down
26 changes: 26 additions & 0 deletions src/network_messages/transactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct ContractIPOBid

#define BROADCAST_TRANSACTION 24


// A transaction is made of this struct, followed by inputSize Bytes payload data and SIGNATURE_SIZE Bytes signature
struct Transaction
{
m256i sourcePublicKey;
Expand All @@ -19,6 +21,30 @@ struct Transaction
unsigned int tick;
unsigned short inputType;
unsigned short inputSize;

// Return total transaction datat size with payload data and signature
unsigned int totalSize() const
{
return sizeof(Transaction) + inputSize + SIGNATURE_SIZE;
}

// Check if transaction is valid
bool checkValidity() const
{
return amount >= 0 && amount <= MAX_AMOUNT && inputSize <= MAX_INPUT_SIZE;
}

// Return pointer to transaction's payload (CAUTION: This is behind the memory reserved for this struct!)
unsigned char* inputPtr()
{
return (((unsigned char*)this) + sizeof(Transaction));
}

// Return pointer to signature (CAUTION: This is behind the memory reserved for this struct!)
unsigned char* signaturePtr()
{
return ((unsigned char*)this) + sizeof(Transaction) + inputSize;
}
};

static_assert(sizeof(Transaction) == 32 + 32 + 8 + 4 + 2 + 2, "Something is wrong with the struct size.");
Expand Down
11 changes: 11 additions & 0 deletions src/platform/console_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ static void logToConsole(const CHAR16* message)
#else

// Output to console on UEFI platform
// CAUTION: Can only be called from main processor thread. Otherwise there is a high risk of crashing.
static inline void outputStringToConsole(CHAR16* str)
{
st->ConOut->OutputString(st->ConOut, str);
}

// Log message to console (with line break) on UEFI platform (defined in qubic.cpp due to dependencies on time and qubic status)
// CAUTION: Can only be called from main processor thread. Otherwise there is a high risk of crashing.
static void logToConsole(const CHAR16* message);

#endif
Expand Down Expand Up @@ -159,3 +161,12 @@ static void logStatusToConsole(const CHAR16* message, const EFI_STATUS status, c
appendText(::message, L"!");
logToConsole(::message);
}

// Count characters before terminating NULL
static unsigned int stringLength(const CHAR16* str)
{
unsigned int l = 0;
while (str[l] != 0)
l++;
return l;
}
128 changes: 128 additions & 0 deletions src/platform/debugging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#pragma once

#include "concurrency.h"
#include "file_io.h"


#if defined(EXPECT_TRUE)

// in gtest context, use EXPECT_TRUE as ASSERT
#define ASSERT EXPECT_TRUE

#elif defined(NDEBUG)

// with NDEBUG, make ASSERT disappear
#define ASSERT(expression) ((void)0)

#else

static CHAR16 debugMessage[128][16384];
static int debugMessageCount = 0;
static char volatile debugLogLock = 0;

#define WRITE_DEBUG_MESSAGES_TO_FILE 1

// Print debug messages added with addDebugMessage().
// CAUTION: Can only be called from main processor thread. Otherwise there is a high risk of crashing.
static void printDebugMessages()
{
#if WRITE_DEBUG_MESSAGES_TO_FILE
// Open debug log file and seek to the end of file for appending
EFI_STATUS status;
EFI_FILE_PROTOCOL* file = nullptr;
if (status = root->Open(root, (void**)&file, (CHAR16*)L"debug.log", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0))
{
logStatusToConsole(L"EFI_FILE_PROTOCOL.Open() fails", status, __LINE__);
file = nullptr;
}
else
{
if (status = root->SetPosition(file, 0xFFFFFFFFFFFFFFFF))
{
logStatusToConsole(L"EFI_FILE_PROTOCOL.SetPosition() fails", status, __LINE__);
file = nullptr;
}
}
#endif
ACQUIRE(debugLogLock);
for (int i = 0; i < debugMessageCount; i++)
{
// Make sure there is a newline at the end
unsigned int strLen = stringLength(debugMessage[i]);
if (debugMessage[i][strLen-1] != L'\n')
{
appendText(debugMessage[i], L"\r\n");
strLen += 2;
}

// Write to console
outputStringToConsole(debugMessage[i]);

#if WRITE_DEBUG_MESSAGES_TO_FILE
// Write to log file
if (file)
{
char* buffer = (char*)debugMessage[i];
unsigned long long totalSize = strLen * sizeof(CHAR16);
unsigned long long writtenSize = 0;
while (writtenSize < totalSize)
{
unsigned long long size = (WRITING_CHUNK_SIZE <= (totalSize - writtenSize) ? WRITING_CHUNK_SIZE : (totalSize - writtenSize));
status = file->Write(file, &size, &buffer[writtenSize]);
if (status
|| size != (WRITING_CHUNK_SIZE <= (totalSize - writtenSize) ? WRITING_CHUNK_SIZE : (totalSize - writtenSize)))
{
logStatusToConsole(L"EFI_FILE_PROTOCOL.Write() fails", status, __LINE__);

file->Close(file);
file = 0;
break;
}
writtenSize += size;
}
}
#endif
}
debugMessageCount = 0;
RELEASE(debugLogLock);
#if WRITE_DEBUG_MESSAGES_TO_FILE
if (file)
file->Close(file);
#endif
}

// Add a message for logging from arbitrary thread
static void addDebugMessage(const CHAR16* msg)
{
ACQUIRE(debugLogLock);
if (debugMessageCount < 128)
{
setText(debugMessage[debugMessageCount], msg);
++debugMessageCount;
}
RELEASE(debugLogLock);
}

// Add a assert message for logging from arbitrary thread
static void addDebugMessageAssert(const CHAR16* message, const CHAR16* file, const unsigned int lineNumber)
{
ACQUIRE(debugLogLock);
if (debugMessageCount < 128)
{
setText(debugMessage[debugMessageCount], L"Assertion failed: ");
appendText(debugMessage[debugMessageCount], message);
appendText(debugMessage[debugMessageCount], L" at line ");
appendNumber(debugMessage[debugMessageCount], lineNumber, FALSE);
appendText(debugMessage[debugMessageCount], L" in ");
appendText(debugMessage[debugMessageCount], file);
++debugMessageCount;
}
RELEASE(debugLogLock);
}

#define ASSERT(expression) (void)( \
(!!(expression)) || \
(addDebugMessageAssert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned int)(__LINE__)), 0) \
)

#endif
Loading

0 comments on commit 84041f0

Please sign in to comment.