Skip to content

Commit

Permalink
Merge pull request #209 from qubic/develop (Release/v1.225.0)
Browse files Browse the repository at this point in the history
Release/v1.225.0 to main
  • Loading branch information
philippwerner authored Oct 30, 2024
2 parents 234f9a3 + 3b8e46f commit 7bf36fa
Show file tree
Hide file tree
Showing 22 changed files with 825 additions and 256 deletions.
1 change: 1 addition & 0 deletions src/Qubic.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<ClInclude Include="platform\read_write_lock.h" />
<ClInclude Include="platform\stack_size_tracker.h" />
<ClInclude Include="platform\time_stamp_counter.h" />
<ClInclude Include="platform\global_var.h" />
<ClInclude Include="score.h" />
<ClInclude Include="platform\m256.h" />
<ClInclude Include="platform\memory.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 @@ -202,6 +202,9 @@
<ClInclude Include="assets\assets.h">
<Filter>assets</Filter>
</ClInclude>
<ClInclude Include="platform\global_var.h">
<Filter>platform</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="platform">
Expand Down
13 changes: 7 additions & 6 deletions src/assets/assets.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "platform/global_var.h"
#include "platform/m256.h"
#include "platform/concurrency.h"
#include "platform/uefi.h"
Expand All @@ -16,12 +17,12 @@



static volatile char universeLock = 0;
static Asset* assets = NULL;
static m256i* assetDigests = NULL;
GLOBAL_VAR_DECL volatile char universeLock GLOBAL_VAR_INIT(0);
GLOBAL_VAR_DECL Asset* assets GLOBAL_VAR_INIT(nullptr);
GLOBAL_VAR_DECL m256i* assetDigests GLOBAL_VAR_INIT(nullptr);
static constexpr unsigned long long assetDigestsSizeInBytes = (ASSETS_CAPACITY * 2 - 1) * 32ULL;
static unsigned long long* assetChangeFlags = NULL;
static char CONTRACT_ASSET_UNIT_OF_MEASUREMENT[7] = { 0, 0, 0, 0, 0, 0, 0 };
GLOBAL_VAR_DECL unsigned long long* assetChangeFlags GLOBAL_VAR_INIT(nullptr);
static constexpr char CONTRACT_ASSET_UNIT_OF_MEASUREMENT[7] = { 0, 0, 0, 0, 0, 0, 0 };

static bool initAssets()
{
Expand Down Expand Up @@ -55,7 +56,7 @@ static void deinitAssets()
}
}

static long long issueAsset(const m256i& issuerPublicKey, char name[7], char numberOfDecimalPlaces, char unitOfMeasurement[7], long long numberOfShares, unsigned short managingContractIndex,
static long long issueAsset(const m256i& issuerPublicKey, const char name[7], char numberOfDecimalPlaces, const char unitOfMeasurement[7], long long numberOfShares, unsigned short managingContractIndex,
int* issuanceIndex, int* ownershipIndex, int* possessionIndex)
{
*issuanceIndex = issuerPublicKey.m256i_u32[0] & (ASSETS_CAPACITY - 1);
Expand Down
5 changes: 4 additions & 1 deletion src/common_buffers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "platform/global_var.h"
#include "platform/memory.h"

#include "network_messages/entity.h"
Expand All @@ -10,7 +11,8 @@ constexpr unsigned long long spectrumSizeInBytes = SPECTRUM_CAPACITY * sizeof(::
constexpr unsigned long long universeSizeInBytes = ASSETS_CAPACITY * sizeof(Asset);

// Buffer used for reorganizing spectrum and universe hash maps, currently also used as scratchpad buffer for contracts
static void* reorgBuffer = nullptr; // Must be large enough to fit any contract, full spectrum, and full universe!
// Must be large enough to fit any contract, full spectrum, and full universe!
GLOBAL_VAR_DECL void* reorgBuffer GLOBAL_VAR_INIT(nullptr);

static bool initCommonBuffers()
{
Expand All @@ -30,6 +32,7 @@ static void deinitCommonBuffers()
if (reorgBuffer)
{
freePool(reorgBuffer);
reorgBuffer = nullptr;
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/contract_core/contract_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ struct __FunctionOrProcedureBeginEndGuard
#include "qpi_collection_impl.h"
#include "qpi_trivial_impl.h"

#include "platform/global_var.h"

#include "network_messages/common_def.h"

struct Contract0State
Expand Down Expand Up @@ -195,25 +197,25 @@ constexpr struct ContractDescription

constexpr unsigned int contractCount = sizeof(contractDescriptions) / sizeof(contractDescriptions[0]);

static EXPAND_PROCEDURE contractExpandProcedures[contractCount];
GLOBAL_VAR_DECL EXPAND_PROCEDURE contractExpandProcedures[contractCount];

// TODO: all below are filled very sparsely, so a better data structure could save almost all the memory
static USER_FUNCTION contractUserFunctions[contractCount][65536];
static unsigned short contractUserFunctionInputSizes[contractCount][65536];
static unsigned short contractUserFunctionOutputSizes[contractCount][65536];
GLOBAL_VAR_DECL USER_FUNCTION contractUserFunctions[contractCount][65536];
GLOBAL_VAR_DECL unsigned short contractUserFunctionInputSizes[contractCount][65536];
GLOBAL_VAR_DECL unsigned short contractUserFunctionOutputSizes[contractCount][65536];
// This has been changed to unsigned short to avoid the misalignment issue happening in epochs 109 and 110,
// probably due to too high numbers in contractUserProcedureLocalsSizes causing stack buffer alloc to fail
// probably due to buffer overflow that is difficult to reproduce in test net
// TODO: change back to unsigned int
static unsigned short contractUserFunctionLocalsSizes[contractCount][65536];
static USER_PROCEDURE contractUserProcedures[contractCount][65536];
static unsigned short contractUserProcedureInputSizes[contractCount][65536];
static unsigned short contractUserProcedureOutputSizes[contractCount][65536];
GLOBAL_VAR_DECL unsigned short contractUserFunctionLocalsSizes[contractCount][65536];
GLOBAL_VAR_DECL USER_PROCEDURE contractUserProcedures[contractCount][65536];
GLOBAL_VAR_DECL unsigned short contractUserProcedureInputSizes[contractCount][65536];
GLOBAL_VAR_DECL unsigned short contractUserProcedureOutputSizes[contractCount][65536];
// This has been changed to unsigned short to avoid the misalignment issue happening in epochs 109 and 110,
// probably due to too high numbers in contractUserProcedureLocalsSizes causing stack buffer alloc to fail
// probably due to buffer overflow that is difficult to reproduce in test net
// TODO: change back to unsigned int
static unsigned short contractUserProcedureLocalsSizes[contractCount][65536];
GLOBAL_VAR_DECL unsigned short contractUserProcedureLocalsSizes[contractCount][65536];

enum SystemProcedureID
{
Expand All @@ -235,8 +237,8 @@ enum MoreProcedureIDs
USER_PROCEDURE_CALL = contractSystemProcedureCount + 1,
};

static SYSTEM_PROCEDURE contractSystemProcedures[contractCount][contractSystemProcedureCount];
static unsigned short contractSystemProcedureLocalsSizes[contractCount][contractSystemProcedureCount];
GLOBAL_VAR_DECL SYSTEM_PROCEDURE contractSystemProcedures[contractCount][contractSystemProcedureCount];
GLOBAL_VAR_DECL unsigned short contractSystemProcedureLocalsSizes[contractCount][contractSystemProcedureCount];


#define REGISTER_CONTRACT_FUNCTIONS_AND_PROCEDURES(contractName) { \
Expand Down
31 changes: 17 additions & 14 deletions src/contract_core/contract_exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "contracts/qpi.h"

#include "platform/global_var.h"
#include "platform/read_write_lock.h"
#include "platform/debugging.h"
#include "platform/memory.h"
Expand Down Expand Up @@ -32,22 +33,22 @@ enum ContractError

// Used to store: locals and for first invocation level also input and output
typedef StackBuffer<unsigned int, 32 * 1024 * 1024> ContractLocalsStack;
static ContractLocalsStack contractLocalsStack[NUMBER_OF_CONTRACT_EXECUTION_BUFFERS];
static volatile char contractLocalsStackLock[NUMBER_OF_CONTRACT_EXECUTION_BUFFERS];
static volatile long contractLocalsStackLockWaitingCount = 0;
static long contractLocalsStackLockWaitingCountMax = 0;
GLOBAL_VAR_DECL ContractLocalsStack contractLocalsStack[NUMBER_OF_CONTRACT_EXECUTION_BUFFERS];
GLOBAL_VAR_DECL volatile char contractLocalsStackLock[NUMBER_OF_CONTRACT_EXECUTION_BUFFERS];
GLOBAL_VAR_DECL volatile long contractLocalsStackLockWaitingCount;
GLOBAL_VAR_DECL long contractLocalsStackLockWaitingCountMax;


static ReadWriteLock contractStateLock[contractCount];
static unsigned char* contractStates[contractCount];
static volatile long long contractTotalExecutionTicks[contractCount];
static unsigned int contractError[contractCount];
GLOBAL_VAR_DECL ReadWriteLock contractStateLock[contractCount];
GLOBAL_VAR_DECL unsigned char* contractStates[contractCount];
GLOBAL_VAR_DECL volatile long long contractTotalExecutionTicks[contractCount];
GLOBAL_VAR_DECL unsigned int contractError[contractCount];

// TODO: If we ever have parallel procedure calls (of different contracts), we need to make
// access to contractStateChangeFlags thread-safe
static unsigned long long* contractStateChangeFlags = NULL;
GLOBAL_VAR_DECL unsigned long long* contractStateChangeFlags GLOBAL_VAR_INIT(nullptr);

static ContractActionTracker<1024> contractActionTracker;
GLOBAL_VAR_DECL ContractActionTracker<1024*1024> contractActionTracker;


static bool initContractExec()
Expand All @@ -70,6 +71,8 @@ static bool initContractExec()
for (ContractLocalsStack::SizeType i = 0; i < NUMBER_OF_CONTRACT_EXECUTION_BUFFERS; ++i)
contractLocalsStack[i].init();
setMem((void*)contractLocalsStackLock, sizeof(contractLocalsStackLock), 0);
contractLocalsStackLockWaitingCount = 0;
contractLocalsStackLockWaitingCountMax = 0;

setMem((void*)contractTotalExecutionTicks, sizeof(contractTotalExecutionTicks), 0);
setMem((void*)contractError, sizeof(contractError), 0);
Expand Down Expand Up @@ -325,7 +328,7 @@ void QPI::QpiContextFunctionCall::__qpiAbort(unsigned int errorCode) const
ASSERT(_currentContractIndex < contractCount);
contractError[_currentContractIndex] = errorCode;

#ifndef NDEBUG
#if !defined(NDEBUG)
CHAR16 dbgMsgBuf[200];
setText(dbgMsgBuf, L"__qpiAbort() called in tick ");
appendNumber(dbgMsgBuf, system.tick, FALSE);
Expand Down Expand Up @@ -452,7 +455,7 @@ struct QpiContextSystemProcedureCall : public QPI::QpiContextProcedureCall
}
};

// QPI context used to call contract user procedure from qubic core (contract processor)
// QPI context used to call contract user procedure from qubic core (contract processor), after transfer of invocation reward
struct QpiContextUserProcedureCall : public QPI::QpiContextProcedureCall
{
char* outputBuffer;
Expand All @@ -474,7 +477,7 @@ struct QpiContextUserProcedureCall : public QPI::QpiContextProcedureCall

void call(unsigned short inputType, const void* inputPtr, unsigned short inputSize)
{
#ifndef NDEBUG
#if !defined(NDEBUG) && !defined(NO_UEFI)
CHAR16 dbgMsgBuf[400];
setText(dbgMsgBuf, L"QpiContextUserProcedureCall in tick ");
appendNumber(dbgMsgBuf, system.tick, FALSE);
Expand Down Expand Up @@ -585,7 +588,7 @@ struct QpiContextUserFunctionCall : public QPI::QpiContextFunctionCall
// call function
void call(unsigned short inputType, const void* inputPtr, unsigned short inputSize)
{
#ifndef NDEBUG
#if !defined(NDEBUG) && !defined(NO_UEFI)
CHAR16 dbgMsgBuf[300];
setText(dbgMsgBuf, L"QpiContextUserFunctionCall in tick ");
appendNumber(dbgMsgBuf, system.tick, FALSE);
Expand Down
14 changes: 7 additions & 7 deletions src/contracts/qpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ namespace QPI
inline uint16 epoch(
) const; // [0..9'999]

bit getEntity(
inline bit getEntity(
const id& id,
Entity& entity
) const; // Returns "true" if the entity has been found, returns "false" otherwise
Expand Down Expand Up @@ -1145,7 +1145,7 @@ namespace QPI
const id& currentId
) const;

sint64 numberOfPossessedShares(
inline sint64 numberOfPossessedShares(
uint64 assetName,
const id& issuer,
const id& owner,
Expand Down Expand Up @@ -1208,15 +1208,15 @@ namespace QPI
uint16 sourcePossessionManagingContractIndex
) const;

sint64 burn(
inline sint64 burn(
sint64 amount
) const;

bool distributeDividends( // Attempts to pay dividends
inline bool distributeDividends( // Attempts to pay dividends
sint64 amountPerShare // Total amount will be 676x of this
) const; // "true" if the contract has had enough qus, "false" otherwise

sint64 issueAsset(
inline sint64 issueAsset(
uint64 name,
const id& issuer,
sint8 numberOfDecimalPlaces,
Expand All @@ -1234,12 +1234,12 @@ namespace QPI
uint16 destinationPossessionManagingContractIndex
) const;

sint64 transfer( // Attempts to transfer energy from this qubic
inline sint64 transfer( // Attempts to transfer energy from this qubic
const id& destination, // Destination to transfer to, use NULL_ID to destroy the transferred energy
sint64 amount // Energy amount to transfer, must be in [0..1'000'000'000'000'000] range
) const; // Returns remaining energy amount; if the value is less than 0 then the attempt has failed, in this case the absolute value equals to the insufficient amount

sint64 transferShareOwnershipAndPossession(
inline sint64 transferShareOwnershipAndPossession(
uint64 assetName,
const id& issuer,
const id& owner,
Expand Down
27 changes: 27 additions & 0 deletions src/files/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,31 @@ struct FileFragmentTransactionPrefix : public Transaction
struct FileFragmentTransactionPostfix
{
unsigned char signature[SIGNATURE_SIZE];
};

struct FileTrailerTransaction : public Transaction
{
static constexpr unsigned char transactionType()
{
return 5; // TODO: Set actual value
}

static constexpr long long minAmount()
{
return 0;
}

static constexpr unsigned short minInputSize()
{
return sizeof(fileSize)
+ sizeof(numberOfFragments)
+ sizeof(fileFormat)
+ sizeof(lastFileFragmentTransactionDigest);
}

unsigned long long fileSize;
unsigned long long numberOfFragments;
unsigned char fileFormat[8];
m256i lastFileFragmentTransactionDigest;
unsigned char signature[SIGNATURE_SIZE];
};
4 changes: 2 additions & 2 deletions src/oracles/oracle_machines.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct OracleReplyCommitTransaction : public Transaction
{
static constexpr unsigned char transactionType()
{
return 5; // TODO: Set actual value
return 6; // TODO: Set actual value
}

unsigned long long queryIndex;
Expand All @@ -15,7 +15,7 @@ struct OracleReplyRevealTransactionPrefix : public Transaction
{
static constexpr unsigned char transactionType()
{
return 6; // TODO: Set actual value
return 7; // TODO: Set actual value
}

unsigned long long queryIndex;
Expand Down
24 changes: 24 additions & 0 deletions src/platform/global_var.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

// If multiple compile units are used, having all globals declared as static causes
// trouble if code is shared between compile units. Thus, globals need to be declared
// extern and defined in only one compile unit.

#if defined(SINGLE_COMPILE_UNIT)

// single compile unit -> make static
#define GLOBAL_VAR_DECL static
#define GLOBAL_VAR_INIT(val) =val

#else

// multiple compile units -> only define in one file (declare as extern in the others)
#if defined(DEFINE_VARIABLES_SHARED_BETWEEN_COMPILE_UNITS)
#define GLOBAL_VAR_DECL
#define GLOBAL_VAR_INIT(val) =val
#else
#define GLOBAL_VAR_DECL extern
#define GLOBAL_VAR_INIT(val)
#endif

#endif
10 changes: 5 additions & 5 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
// Config options that should NOT be changed by operators

#define VERSION_A 1
#define VERSION_B 224
#define VERSION_C 4
#define VERSION_B 225
#define VERSION_C 0

// Epoch and initial tick for node startup
#define EPOCH 132
#define TICK 16790000
#define EPOCH 133
#define TICK 16910000

#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"

Expand All @@ -72,7 +72,7 @@ static unsigned short REVENUE_FILE_NAME[] = L"revenueScore"; // TODO: for testin
#define NUMBER_OF_NEIGHBOR_NEURONS 10000
#define MAX_DURATION 100000000
#define NEURON_VALUE_LIMIT 1LL
#define SOLUTION_THRESHOLD_DEFAULT 43
#define SOLUTION_THRESHOLD_DEFAULT 44

#define SOLUTION_SECURITY_DEPOSIT 1000000

Expand Down
Loading

0 comments on commit 7bf36fa

Please sign in to comment.