Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/v1.196.0 to main #73

Merged
merged 9 commits into from
Mar 13, 2024
4 changes: 2 additions & 2 deletions src/network_messages/special_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct SpecialCommandSetProposalAndBallotResponse

#define SPECIAL_COMMAND_SET_SOLUTION_THRESHOLD_REQUEST 5ULL
#define SPECIAL_COMMAND_SET_SOLUTION_THRESHOLD_RESPONSE 6ULL
struct SpecialCommandSetSolutionThresholdResquestAndResponse
struct SpecialCommandSetSolutionThresholdRequestAndResponse
{
unsigned long long everIncreasingNonceAndCommandType;
unsigned int epoch;
Expand All @@ -75,7 +75,7 @@ struct SpecialCommandSetSolutionThresholdResquestAndResponse

#define SPECIAL_COMMAND_TOGGLE_MAIN_MODE_REQUEST 7ULL // F12
#define SPECIAL_COMMAND_TOGGLE_MAIN_MODE_RESPONSE 8ULL // F12
struct SpecialCommandToggleMainModeResquestAndResponse
struct SpecialCommandToggleMainModeRequestAndResponse
{
unsigned long long everIncreasingNonceAndCommandType;
unsigned char mainModeFlag; // 0 Aux - 1 Main
Expand Down
12 changes: 6 additions & 6 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// no need to define AVX512 here anymore, just change the project settings to use the AVX512 version

#define MAX_NUMBER_OF_PROCESSORS 32
#define NUMBER_OF_SOLUTION_PROCESSORS 4 // do not increase this for this epoch, because there may be issues due too fast ticking
#define NUMBER_OF_SOLUTION_PROCESSORS 6 // do not increase this for this epoch, because there may be issues due too fast ticking

#define VERSION_A 1
#define VERSION_B 195
#define VERSION_C 1
#define VERSION_B 196
#define VERSION_C 0

#define EPOCH 99
#define TICK 12820000
#define EPOCH 100
#define TICK 12950000

// random seed is now obtained from spectrumDigests

Expand All @@ -31,7 +31,7 @@ static unsigned short CONTRACT_FILE_NAME[] = L"contract????.???";
#define MAX_INPUT_DURATION 256
#define MAX_OUTPUT_DURATION 256
#define NEURON_VALUE_LIMIT 1099511627776LL
#define SOLUTION_THRESHOLD_DEFAULT 45
#define SOLUTION_THRESHOLD_DEFAULT 44
#define USE_SCORE_CACHE 1
#define SCORE_CACHE_SIZE 1000000 // the larger the better
#define SCORE_CACHE_COLLISION_RETRIES 20 // number of retries to find entry in cache in case of hash collision
32 changes: 17 additions & 15 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,10 @@ static void processBroadcastMessage(const unsigned long long processorNumber, Re
}
if (k == system.numberOfSolutions)
{
unsigned int solutionScore = (*score)(processorNumber, request->destinationPublicKey, solution_nonce);
unsigned long long solutionScore = (*score)(processorNumber, request->destinationPublicKey, solution_nonce);
const int threshold = (system.epoch < MAX_NUMBER_EPOCH) ? solutionThreshold[system.epoch] : SOLUTION_THRESHOLD_DEFAULT;
if (system.numberOfSolutions < MAX_NUMBER_OF_SOLUTIONS
&& ((solutionScore >= (DATA_LENGTH / 2) + solutionThreshold[system.epoch]) || (solutionScore <= (DATA_LENGTH / 2) - solutionThreshold[system.epoch])))
&& ((solutionScore >= (DATA_LENGTH / 2) + threshold) || (solutionScore <= (DATA_LENGTH / 2) - threshold)))
{
ACQUIRE(solutionsLock);

Expand Down Expand Up @@ -1124,24 +1125,24 @@ static void processSpecialCommand(Peer* peer, RequestResponseHeader* header)

case SPECIAL_COMMAND_SET_SOLUTION_THRESHOLD_REQUEST:
{
SpecialCommandSetSolutionThresholdResquestAndResponse* _request = header->getPayload<SpecialCommandSetSolutionThresholdResquestAndResponse>();
SpecialCommandSetSolutionThresholdRequestAndResponse* _request = header->getPayload<SpecialCommandSetSolutionThresholdRequestAndResponse>();
// can only set future epoch
if (_request->epoch > system.epoch)
if (_request->epoch > system.epoch && _request->epoch < MAX_NUMBER_EPOCH)
{
solutionThreshold[_request->epoch] = _request->threshold;
}
SpecialCommandSetSolutionThresholdResquestAndResponse response;
SpecialCommandSetSolutionThresholdRequestAndResponse response;
response.everIncreasingNonceAndCommandType = _request->everIncreasingNonceAndCommandType;
response.epoch = _request->epoch;
response.threshold = solutionThreshold[_request->epoch];
enqueueResponse(peer, sizeof(SpecialCommandSetSolutionThresholdResquestAndResponse), SpecialCommand::type, header->dejavu(), &response);
response.threshold = (_request->epoch < MAX_NUMBER_EPOCH) ? solutionThreshold[_request->epoch] : SOLUTION_THRESHOLD_DEFAULT;
enqueueResponse(peer, sizeof(SpecialCommandSetSolutionThresholdRequestAndResponse), SpecialCommand::type, header->dejavu(), &response);
}
break;
case SPECIAL_COMMAND_TOGGLE_MAIN_MODE_REQUEST:
{
SpecialCommandToggleMainModeResquestAndResponse* _request = header->getPayload<SpecialCommandToggleMainModeResquestAndResponse>();
SpecialCommandToggleMainModeRequestAndResponse* _request = header->getPayload<SpecialCommandToggleMainModeRequestAndResponse>();
mainAuxStatus = _request->mainModeFlag;
enqueueResponse(peer, sizeof(SpecialCommandToggleMainModeResquestAndResponse), SpecialCommand::type, header->dejavu(), _request);
enqueueResponse(peer, sizeof(SpecialCommandToggleMainModeRequestAndResponse), SpecialCommand::type, header->dejavu(), _request);
}
break;
case SPECIAL_COMMAND_REFRESH_PEER_LIST:
Expand Down Expand Up @@ -1640,7 +1641,7 @@ static long long __transfer(const m256i& destination, long long amount)
return remainingAmount;
}

static long long __transferShareOwnershipAndPossession(unsigned long long assetName, const m256i& issuer, const m256i& owner, const m256i& possessor, long long numberOfShares, const m256i& newOwner)
static long long __transferShareOwnershipAndPossession(unsigned long long assetName, const m256i& issuer, const m256i& owner, const m256i& possessor, long long numberOfShares, const m256i& newOwnerAndPossessor)
{
if (numberOfShares <= 0 || numberOfShares > MAX_AMOUNT)
{
Expand Down Expand Up @@ -1697,7 +1698,7 @@ static long long __transferShareOwnershipAndPossession(unsigned long long assetN
if (assets[possessionIndex].varStruct.possession.numberOfShares >= numberOfShares)
{
int destinationOwnershipIndex, destinationPossessionIndex;
transferShareOwnershipAndPossession(ownershipIndex, possessionIndex, newOwner, numberOfShares, &destinationOwnershipIndex, &destinationPossessionIndex, false);
transferShareOwnershipAndPossession(ownershipIndex, possessionIndex, newOwnerAndPossessor, numberOfShares, &destinationOwnershipIndex, &destinationPossessionIndex, false);

RELEASE(universeLock);

Expand Down Expand Up @@ -2117,7 +2118,8 @@ static void processTick(unsigned long long processorNumber)
resourceTestingDigest ^= solutionScore;
KangarooTwelve(&resourceTestingDigest, sizeof(resourceTestingDigest), &resourceTestingDigest, sizeof(resourceTestingDigest));

if (((solutionScore >= (DATA_LENGTH / 2) + solutionThreshold[system.epoch]) || (solutionScore <= (DATA_LENGTH / 2) - solutionThreshold[system.epoch])))
const int threshold = (system.epoch < MAX_NUMBER_EPOCH) ? solutionThreshold[system.epoch] : SOLUTION_THRESHOLD_DEFAULT;
if (((solutionScore >= (DATA_LENGTH / 2) + threshold) || (solutionScore <= (DATA_LENGTH / 2) - threshold)))
{
for (unsigned int i = 0; i < sizeof(computorSeeds) / sizeof(computorSeeds[0]); i++)
{
Expand Down Expand Up @@ -2532,7 +2534,7 @@ static void beginEpoch1of2()
minimumComputorScore = 0;
minimumCandidateScore = 0;

if (solutionThreshold[system.epoch] <= 0 || solutionThreshold[system.epoch] > DATA_LENGTH) { // invalid threshold
if (system.epoch < MAX_NUMBER_EPOCH && (solutionThreshold[system.epoch] <= 0 || solutionThreshold[system.epoch] > DATA_LENGTH)) { // invalid threshold
solutionThreshold[system.epoch] = SOLUTION_THRESHOLD_DEFAULT;
}

Expand All @@ -2543,7 +2545,7 @@ static void beginEpoch1of2()
bs->SetMem(system.solutions, sizeof(system.solutions), 0);
bs->SetMem(system.futureComputors, sizeof(system.futureComputors), 0);

// Reset resource testing digest at begining of the epoch
// Reset resource testing digest at beginning of the epoch
// there are many global variables that were init at declaration, may need to re-check all of them again
resourceTestingDigest = 0;

Expand Down Expand Up @@ -4445,7 +4447,7 @@ EFI_STATUS efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE* systemTable)
mpServicesProtocol->WhoAmI(mpServicesProtocol, &mainThreadProcessorID); // get the proc Id of main thread (for later use)

// Initialize resource management
// ASSUMPTION: - each processor (CPU core) is binded to different functional thread.
// ASSUMPTION: - each processor (CPU core) is bound to different functional thread.
// - there are potentially 2+ tick processors in the future
// procId is guaranteed lower than MAX_NUMBER_OF_PROCESSORS (https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Protocol/MpService.h#L615)
// First part: tick processors always process solutions
Expand Down
155 changes: 146 additions & 9 deletions src/smart_contracts/Qx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,112 @@ struct QX
uint32 tradeFee; // Number of billionths
};

struct AssetAskOrders_input
{
id issuer;
uint64 assetName;
uint64 offset;
};
struct AssetAskOrders_output
{
struct Order
{
id entity;
sint64 price;
sint64 numberOfShares;
};

array<Order, 256> orders;
};

struct AssetBidOrders_input
{
id issuer;
uint64 assetName;
uint64 offset;
};
struct AssetBidOrders_output
{
struct Order
{
id entity;
sint64 price;
sint64 numberOfShares;
};

array<Order, 256> orders;
};

struct IssueAsset_input
{
uint64 name;
uint64 assetName;
sint64 numberOfShares;
uint64 unitOfMeasurement;
sint8 numberOfDecimalPlaces;
};
struct IssueAsset_output
{
long long issuedNumberOfShares;
sint64 issuedNumberOfShares;
};

struct TransferShareOwnershipAndPossession_input
{
id issuer;
id possessor;
id newOwner;
unsigned long long assetName;
long long numberOfShares;
id newOwnerAndPossessor;
uint64 assetName;
sint64 numberOfShares;
};
struct TransferShareOwnershipAndPossession_output
{
long long transferredNumberOfShares;
sint64 transferredNumberOfShares;
};

struct AddToAskOrder_input
{
id issuer;
uint64 assetName;
sint64 price;
sint64 numberOfShares;
};
struct AddToAskOrder_output
{
sint64 addedNumberOfShares;
};

struct AddToBidOrder_input
{
id issuer;
uint64 assetName;
sint64 price;
sint64 numberOfShares;
};
struct AddToBidOrder_output
{
sint64 addedNumberOfShares;
};

struct RemoveFromAskOrder_input
{
id issuer;
uint64 assetName;
sint64 price;
sint64 numberOfShares;
};
struct RemoveFromAskOrder_output
{
sint64 removedNumberOfShares;
};

struct RemoveFromBidOrder_input
{
id issuer;
uint64 assetName;
sint64 price;
sint64 numberOfShares;
};
struct RemoveFromBidOrder_output
{
sint64 removedNumberOfShares;
};

private:
Expand All @@ -58,6 +141,12 @@ struct QX
output.tradeFee = state._tradeFee;
_

PUBLIC(AssetAskOrders)
_

PUBLIC(AssetBidOrders)
_

PUBLIC(IssueAsset)

if (invocationReward() < state._assetIssuanceFee)
Expand All @@ -77,7 +166,7 @@ struct QX
}
state._earnedAmount += state._assetIssuanceFee;

output.issuedNumberOfShares = issueAsset(input.name, invocator(), input.numberOfDecimalPlaces, input.numberOfShares, input.unitOfMeasurement);
output.issuedNumberOfShares = issueAsset(input.assetName, invocator(), input.numberOfDecimalPlaces, input.numberOfShares, input.unitOfMeasurement);
}
_

Expand All @@ -100,19 +189,67 @@ struct QX
}
state._earnedAmount += state._transferFee;

output.transferredNumberOfShares = transferShareOwnershipAndPossession(input.assetName, input.issuer, invocator(), input.possessor, input.numberOfShares, input.newOwner) < 0 ? 0 : input.numberOfShares;
output.transferredNumberOfShares = transferShareOwnershipAndPossession(input.assetName, input.issuer, invocator(), invocator(), input.numberOfShares, input.newOwnerAndPossessor) < 0 ? 0 : input.numberOfShares;
}
_

PUBLIC(AddToAskOrder)

if (invocationReward() > 0)
{
transfer(invocator(), invocationReward());
}

output.addedNumberOfShares = 0;
_

PUBLIC(AddToBidOrder)

if (invocationReward() > 0)
{
transfer(invocator(), invocationReward());
}

output.addedNumberOfShares = 0;
_

PUBLIC(RemoveFromAskOrder)

if (invocationReward() > 0)
{
transfer(invocator(), invocationReward());
}

output.removedNumberOfShares = 0;
_

PUBLIC(RemoveFromBidOrder)

if (invocationReward() > 0)
{
transfer(invocator(), invocationReward());
}

output.removedNumberOfShares = 0;
_

REGISTER_USER_FUNCTIONS

REGISTER_USER_FUNCTION(Fees, 1);
REGISTER_USER_FUNCTION(AssetAskOrders, 2);
REGISTER_USER_FUNCTION(AssetBidOrders, 3);
_

REGISTER_USER_PROCEDURES

REGISTER_USER_PROCEDURE(IssueAsset, 1);
REGISTER_USER_PROCEDURE(TransferShareOwnershipAndPossession, 2);
//
//
REGISTER_USER_PROCEDURE(AddToAskOrder, 5);
REGISTER_USER_PROCEDURE(AddToBidOrder, 6);
REGISTER_USER_PROCEDURE(RemoveFromAskOrder, 7);
REGISTER_USER_PROCEDURE(RemoveFromBidOrder, 8);
_

INITIALIZE
Expand Down
Loading
Loading