Skip to content

Commit

Permalink
Merge pull request #40 from qubic/release/ep93_revert
Browse files Browse the repository at this point in the history
Release/ep93_reverted to main
  • Loading branch information
philippwerner authored Jan 24, 2024
2 parents 8280415 + 37efebc commit 2eb1edb
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 84 deletions.
3 changes: 0 additions & 3 deletions src/assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,6 @@ static void saveUniverse()

static bool loadUniverse()
{
UNIVERSE_FILE_NAME[sizeof(UNIVERSE_FILE_NAME) / sizeof(UNIVERSE_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0';
UNIVERSE_FILE_NAME[sizeof(UNIVERSE_FILE_NAME) / sizeof(UNIVERSE_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0';
UNIVERSE_FILE_NAME[sizeof(UNIVERSE_FILE_NAME) / sizeof(UNIVERSE_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0';
long long loadedSize = load(UNIVERSE_FILE_NAME, ASSETS_CAPACITY * sizeof(Asset), (unsigned char*)assets);
if (loadedSize != ASSETS_CAPACITY * sizeof(Asset))
{
Expand Down
17 changes: 5 additions & 12 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@
#define MAX_NUMBER_OF_PROCESSORS 32

#define VERSION_A 1
#define VERSION_B 189
#define VERSION_B 190
#define VERSION_C 0

#define EPOCH 92
#define TICK 12050000

#define RANDOM_SEED0 69
#define RANDOM_SEED1 177
#define RANDOM_SEED2 23
#define RANDOM_SEED3 197
#define RANDOM_SEED4 178
#define RANDOM_SEED5 119
#define RANDOM_SEED6 252
#define RANDOM_SEED7 66
#define EPOCH 93
#define TICK 12160000

// random seed is now obtained from spectrumDigests

#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"

Expand Down
110 changes: 67 additions & 43 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static unsigned long long nextTickTransactionOffset = FIRST_TICK_TRANSACTION_OFF
static m256i uniqueNextTickTransactionDigests[NUMBER_OF_COMPUTORS];
static unsigned int uniqueNextTickTransactionDigestCounters[NUMBER_OF_COMPUTORS];

static void* reorgBuffer = NULL;
static void* reorgBuffer = NULL; // Must be large enough to fit any contract!

static unsigned long long resourceTestingDigest = 0;

Expand Down Expand Up @@ -1460,6 +1460,11 @@ static unsigned char __second()
return etalonTick.second;
}

static void* __scratchpad()
{
return reorgBuffer;
}

static unsigned int __tick()
{
return system.tick;
Expand Down Expand Up @@ -3244,6 +3249,50 @@ static void saveSystem()
}
}

static void beginEpoch1of2()
{
// This version doesn't support migration from contract IPO to contract operation!

broadcastedComputors.header.setSize<sizeof(broadcastedComputors.header) + sizeof(broadcastedComputors.broadcastComputors)>();
broadcastedComputors.header.setType(BroadcastComputors::type);
broadcastedComputors.broadcastComputors.computors.epoch = 0;
for (unsigned int i = 0; i < NUMBER_OF_COMPUTORS; i++)
{
broadcastedComputors.broadcastComputors.computors.publicKeys[i].setRandomValue();
}
bs->SetMem(&broadcastedComputors.broadcastComputors.computors.signature, sizeof(broadcastedComputors.broadcastComputors.computors.signature), 0);

bs->SetMem(ticks, ((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * NUMBER_OF_COMPUTORS * sizeof(Tick), 0);
bs->SetMem(tickData, ((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * sizeof(TickData), 0);
bs->SetMem(tickTransactions, FIRST_TICK_TRANSACTION_OFFSET + (((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * NUMBER_OF_TRANSACTIONS_PER_TICK * MAX_TRANSACTION_SIZE / TRANSACTION_SPARSENESS), 0);
bs->SetMem(tickTransactionOffsets, sizeof(tickTransactionOffsets), 0);

bs->SetMem(solutionPublicationTicks, sizeof(solutionPublicationTicks), 0);
bs->SetMem(faultyComputorFlags, sizeof(faultyComputorFlags), 0);

SPECTRUM_FILE_NAME[sizeof(SPECTRUM_FILE_NAME) / sizeof(SPECTRUM_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0';
SPECTRUM_FILE_NAME[sizeof(SPECTRUM_FILE_NAME) / sizeof(SPECTRUM_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0';
SPECTRUM_FILE_NAME[sizeof(SPECTRUM_FILE_NAME) / sizeof(SPECTRUM_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0';

UNIVERSE_FILE_NAME[sizeof(UNIVERSE_FILE_NAME) / sizeof(UNIVERSE_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0';
UNIVERSE_FILE_NAME[sizeof(UNIVERSE_FILE_NAME) / sizeof(UNIVERSE_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0';
UNIVERSE_FILE_NAME[sizeof(UNIVERSE_FILE_NAME) / sizeof(UNIVERSE_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0';

CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0';
CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0';
CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0';

bs->SetMem(score, sizeof(*score), 0);
score->loadScoreCache(system.epoch);
bs->SetMem(minerSolutionFlags, NUMBER_OF_MINER_SOLUTION_FLAGS / 8, 0);
bs->SetMem((void*)minerScores, sizeof(minerScores[0]) * NUMBER_OF_COMPUTORS, 0);
}

static void beginEpoch2of2()
{
score->initMiningData(spectrumDigests[(SPECTRUM_CAPACITY * 2 - 1) - 1]);
}

static bool initialize()
{
enableAVX();
Expand Down Expand Up @@ -3292,15 +3341,6 @@ static bool initialize()
bs->SetMem(peers, sizeof(peers), 0);
bs->SetMem(publicPeers, sizeof(publicPeers), 0);

broadcastedComputors.header.setSize<sizeof(broadcastedComputors.header) + sizeof(broadcastedComputors.broadcastComputors)>();
broadcastedComputors.header.setType(BroadcastComputors::type);
broadcastedComputors.broadcastComputors.computors.epoch = 0;
for (unsigned int i = 0; i < NUMBER_OF_COMPUTORS; i++)
{
broadcastedComputors.broadcastComputors.computors.publicKeys[i].setRandomValue();
}
bs->SetMem(&broadcastedComputors.broadcastComputors.computors.signature, sizeof(broadcastedComputors.broadcastComputors.computors.signature), 0);

requestedComputors.header.setSize<sizeof(requestedComputors)>();
requestedComputors.header.setType(RequestComputors::type);
requestedQuorumTick.header.setSize<sizeof(requestedQuorumTick)>();
Expand All @@ -3322,7 +3362,6 @@ static bool initialize()

return false;
}
bs->SetMem(ticks, ((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * NUMBER_OF_COMPUTORS * sizeof(Tick), 0);
if ((status = bs->AllocatePool(EfiRuntimeServicesData, ((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * sizeof(TickData), (void**)&tickData))
|| (status = bs->AllocatePool(EfiRuntimeServicesData, FIRST_TICK_TRANSACTION_OFFSET + (((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * NUMBER_OF_TRANSACTIONS_PER_TICK * MAX_TRANSACTION_SIZE / TRANSACTION_SPARSENESS), (void**)&tickTransactions))
|| (status = bs->AllocatePool(EfiRuntimeServicesData, SPECTRUM_CAPACITY * MAX_TRANSACTION_SIZE, (void**)&entityPendingTransactions))
Expand All @@ -3332,9 +3371,6 @@ static bool initialize()

return false;
}
bs->SetMem(tickData, ((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * sizeof(TickData), 0);
bs->SetMem(tickTransactions, FIRST_TICK_TRANSACTION_OFFSET + (((unsigned long long)MAX_NUMBER_OF_TICKS_PER_EPOCH) * NUMBER_OF_TRANSACTIONS_PER_TICK * MAX_TRANSACTION_SIZE / TRANSACTION_SPARSENESS), 0);
bs->SetMem(tickTransactionOffsets, sizeof(tickTransactionOffsets), 0);
for (unsigned int i = 0; i < SPECTRUM_CAPACITY; i++)
{
((Transaction*)&entityPendingTransactions[i * MAX_TRANSACTION_SIZE])->tick = 0;
Expand Down Expand Up @@ -3387,6 +3423,19 @@ static bool initialize()
}
}

if (status = bs->AllocatePool(EfiRuntimeServicesData, sizeof(*score), (void**)&score))
{
logStatusToConsole(L"EFI_BOOT_SERVICES.AllocatePool() fails", status, __LINE__);
return false;
}

if (status = bs->AllocatePool(EfiRuntimeServicesData, NUMBER_OF_MINER_SOLUTION_FLAGS / 8, (void**)&minerSolutionFlags))
{
logStatusToConsole(L"EFI_BOOT_SERVICES.AllocatePool() fails", status, __LINE__);

return false;
}

if (!initLogging())
return false;

Expand All @@ -3405,6 +3454,8 @@ static bool initialize()
}
system.tick = system.initialTick;

beginEpoch1of2();

etalonTick.epoch = system.epoch;
etalonTick.tick = system.initialTick;
etalonTick.millisecond = system.initialMillisecond;
Expand All @@ -3415,14 +3466,7 @@ static bool initialize()
etalonTick.month = system.initialMonth;
etalonTick.year = system.initialYear;

bs->SetMem(solutionPublicationTicks, sizeof(solutionPublicationTicks), 0);

bs->SetMem(faultyComputorFlags, sizeof(faultyComputorFlags), 0);

logToConsole(L"Loading spectrum file ...");
SPECTRUM_FILE_NAME[sizeof(SPECTRUM_FILE_NAME) / sizeof(SPECTRUM_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0';
SPECTRUM_FILE_NAME[sizeof(SPECTRUM_FILE_NAME) / sizeof(SPECTRUM_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0';
SPECTRUM_FILE_NAME[sizeof(SPECTRUM_FILE_NAME) / sizeof(SPECTRUM_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0';
long long loadedSize = load(SPECTRUM_FILE_NAME, SPECTRUM_CAPACITY * sizeof(::Entity), (unsigned char*)spectrum);
if (loadedSize != SPECTRUM_CAPACITY * sizeof(::Entity))
{
Expand Down Expand Up @@ -3485,9 +3529,6 @@ static bool initialize()
return false;

logToConsole(L"Loading contract files ...");
CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 4] = system.epoch / 100 + L'0';
CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 3] = (system.epoch % 100) / 10 + L'0';
CONTRACT_FILE_NAME[sizeof(CONTRACT_FILE_NAME) / sizeof(CONTRACT_FILE_NAME[0]) - 2] = system.epoch % 10 + L'0';
for (unsigned int contractIndex = 0; contractIndex < sizeof(contractDescriptions) / sizeof(contractDescriptions[0]); contractIndex++)
{
if (contractDescriptions[contractIndex].constructionEpoch == system.epoch)
Expand Down Expand Up @@ -3521,25 +3562,6 @@ static bool initialize()
appendText(message, L".");
logToConsole(message);
}

if (status = bs->AllocatePool(EfiRuntimeServicesData, sizeof(*score), (void**)&score))
{
logStatusToConsole(L"EFI_BOOT_SERVICES.AllocatePool() fails", status, __LINE__);
return false;
}
bs->SetMem(score, sizeof(*score), 0);
score->loadScoreCache(system.epoch);
score->initMiningData();

if (status = bs->AllocatePool(EfiRuntimeServicesData, NUMBER_OF_MINER_SOLUTION_FLAGS / 8, (void**)&minerSolutionFlags))
{
logStatusToConsole(L"EFI_BOOT_SERVICES.AllocatePool() fails", status, __LINE__);

return false;
}
bs->SetMem(minerSolutionFlags, NUMBER_OF_MINER_SOLUTION_FLAGS / 8, 0);

bs->SetMem((void*)minerScores, sizeof(minerScores[0]) * NUMBER_OF_COMPUTORS, 0);
}

logToConsole(L"Allocating buffers ...");
Expand Down Expand Up @@ -3602,6 +3624,8 @@ static bool initialize()
if (!initTcp4(PORT))
return false;

beginEpoch2of2();

return true;
}

Expand Down
20 changes: 5 additions & 15 deletions src/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ScoreFunction
{
char input[(numberOfInputNeurons + infoLength) * (dataLength + numberOfInputNeurons + infoLength)];
char output[(numberOfOutputNeurons + dataLength) * (infoLength + numberOfOutputNeurons + dataLength)];
unsigned short lengths[maxInputDuration * (numberOfInputNeurons + infoLength) + MAX_OUTPUT_DURATION * (numberOfOutputNeurons + dataLength)];
unsigned short lengths[maxInputDuration * (numberOfInputNeurons + infoLength) + maxOutputDuration * (numberOfOutputNeurons + dataLength)];
} synapses[solutionBufferCount];

struct
Expand All @@ -70,19 +70,9 @@ struct ScoreFunction
ScoreCache<SCORE_CACHE_SIZE, SCORE_CACHE_COLLISION_RETRIES> scoreCache;
#endif

void initMiningData()
void initMiningData(m256i randomSeed)
{
unsigned char randomSeed[32];
setMem(randomSeed, 32, 0);
randomSeed[0] = RANDOM_SEED0;
randomSeed[1] = RANDOM_SEED1;
randomSeed[2] = RANDOM_SEED2;
randomSeed[3] = RANDOM_SEED3;
randomSeed[4] = RANDOM_SEED4;
randomSeed[5] = RANDOM_SEED5;
randomSeed[6] = RANDOM_SEED6;
randomSeed[7] = RANDOM_SEED7;
random(randomSeed, randomSeed, (unsigned char*)miningData, sizeof(miningData));
random((unsigned char*)&randomSeed, (unsigned char*)&randomSeed, (unsigned char*)miningData, sizeof(miningData));
}

// Save score cache to SCORE_CACHE_FILE_NAME
Expand Down Expand Up @@ -198,7 +188,7 @@ struct ScoreFunction
}
}

for (unsigned int tick = 0; tick < MAX_INPUT_DURATION; tick++)
for (unsigned int tick = 0; tick < maxInputDuration; tick++)
{
unsigned short neuronIndices[numberOfInputNeurons + infoLength];
unsigned short numberOfRemainingNeurons = 0;
Expand Down Expand Up @@ -254,7 +244,7 @@ struct ScoreFunction
clearBitNeuron(nrVal1Bit, i);
}
}
for (unsigned int tick = 0; tick < MAX_OUTPUT_DURATION; tick++)
for (unsigned int tick = 0; tick < maxOutputDuration; tick++)
{
unsigned short neuronIndices[numberOfOutputNeurons + dataLength];
unsigned short numberOfRemainingNeurons = 0;
Expand Down
1 change: 1 addition & 0 deletions src/smart_contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static m256i __nextId(const m256i&);
static m256i __originator();
static void __registerUserFunction(USER_FUNCTION, unsigned short, unsigned short, unsigned short);
static void __registerUserProcedure(USER_PROCEDURE, unsigned short, unsigned short, unsigned short);
static void* __scratchpad();
static unsigned char __second();
static unsigned int __tick();
static long long __transfer(const m256i&, long long);
Expand Down
21 changes: 19 additions & 2 deletions src/smart_contracts/qpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ namespace QPI
[
]
__
union
float
double
float
typedef
union
*/

Expand Down Expand Up @@ -5129,6 +5130,22 @@ namespace QPI
return L;
}

// Remove all povs marked for removal, this is a very expensive operation
void cleanup()
{
collection<T, L> *copy;
copy = ::__scratchpad();
copy->reset();

for (sint64 povIndex = 0; povIndex < L; povIndex++)
{
if (_povOccupationFlags[povIndex >> 5] & (1ULL << ((povIndex & 31) << 1)))
{
// TODO
}
}
}

// Return element value at elementIndex.
inline T element(sint64 elementIndex) const
{
Expand Down
15 changes: 14 additions & 1 deletion test/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct ScoreTester
{
score = new ScoreFuncOpt;
score_ref_impl = new ScoreFuncRef;
score->initMiningData();
score->initMiningData(_mm256_setzero_si256());
score_ref_impl->initMiningData();
}

Expand Down Expand Up @@ -109,6 +109,19 @@ TEST(TestQubicScoreFunction, CurrentLengthNeuronsDurationSettings) {
runCommonTests(test_score);
}

TEST(TestQubicScoreFunction, Length1024Neurons4096Duration2256) {
ScoreTester<
1024, // DATA_LENGTH
1024, // INFO_LENGTH
4096, // NUMBER_OF_INPUT_NEURONS
4096, // NUMBER_OF_OUTPUT_NEURONS
256, // MAX_INPUT_DURATION
256, // MAX_OUTPUT_DURATION
1 // SET BUFFER TO 1 TO DETECT MEMORY OVERFLOW
> test_score;
runCommonTests(test_score);
}

TEST(TestQubicScoreFunction, LengthNeurons1000Duration200) {
ScoreTester<
1000, // DATA_LENGTH
Expand Down
16 changes: 8 additions & 8 deletions test/score_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ struct ScoreReferenceImplementation
{
unsigned char randomSeed[32];
setMem(randomSeed, 32, 0);
randomSeed[0] = RANDOM_SEED0;
randomSeed[1] = RANDOM_SEED1;
randomSeed[2] = RANDOM_SEED2;
randomSeed[3] = RANDOM_SEED3;
randomSeed[4] = RANDOM_SEED4;
randomSeed[5] = RANDOM_SEED5;
randomSeed[6] = RANDOM_SEED6;
randomSeed[7] = RANDOM_SEED7;
//randomSeed[0] = RANDOM_SEED0;
//randomSeed[1] = RANDOM_SEED1;
//randomSeed[2] = RANDOM_SEED2;
//randomSeed[3] = RANDOM_SEED3;
//randomSeed[4] = RANDOM_SEED4;
//randomSeed[5] = RANDOM_SEED5;
//randomSeed[6] = RANDOM_SEED6;
//randomSeed[7] = RANDOM_SEED7;
random(randomSeed, randomSeed, (unsigned char*)miningData, sizeof(miningData));
}

Expand Down

0 comments on commit 2eb1edb

Please sign in to comment.