Skip to content

Commit

Permalink
Correctly update computer digest when state of contract 0 is changed (#…
Browse files Browse the repository at this point in the history
…84)

* When contract 0 state is changed, set flag for updating digest

* Wrap fee reserve change into function
  • Loading branch information
philippwerner authored Apr 4, 2024
1 parent 7d3cb7e commit 082e237
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,13 @@ static void requestProcessor(void* ProcedureArgument)
}
}

// Return reference to fee reserve of contract for changing its value (data stored in state of contract 0)
static long long & contractFeeReserve(unsigned int contractIndex)
{
contractStateChangeFlags[0] |= 1ULL;
return ((Contract0State*)contractStates[0])->contractFeeReserves[contractIndex];
}

static void __beginFunctionOrProcedure(const unsigned int functionOrProcedureId)
{
// TODO
Expand Down Expand Up @@ -1473,8 +1480,7 @@ static long long __burn(long long amount)

if (decreaseEnergy(index, amount))
{
Contract0State* contract0State = (Contract0State*)contractStates[0];
contract0State->contractFeeReserves[executedContractIndex] += amount;
contractFeeReserve(executedContractIndex) += amount;

const Burning burning = { currentContract , amount };
logBurning(burning);
Expand Down Expand Up @@ -2743,7 +2749,6 @@ static void endEpoch()
getUniverseDigest(etalonTick.prevUniverseDigest);
getComputerDigest(etalonTick.prevComputerDigest);

Contract0State* contract0State = (Contract0State*)contractStates[0];
for (unsigned int contractIndex = 1; contractIndex < sizeof(contractDescriptions) / sizeof(contractDescriptions[0]); contractIndex++)
{
if (system.epoch < contractDescriptions[contractIndex].constructionEpoch)
Expand Down Expand Up @@ -2794,7 +2799,7 @@ static void endEpoch()
logQuTransfer(quTransfer);
}

contract0State->contractFeeReserves[contractIndex] = finalPrice * NUMBER_OF_COMPUTORS;
contractFeeReserve(contractIndex) = finalPrice * NUMBER_OF_COMPUTORS;
}
}

Expand Down

0 comments on commit 082e237

Please sign in to comment.