Skip to content

Commit

Permalink
Merge pull request #242 from qubic/develop (Release/v1.230.0)
Browse files Browse the repository at this point in the history
Release/v1.230.0
  • Loading branch information
Franziska-Mueller authored Dec 18, 2024
2 parents 5094f33 + 4dd061f commit df0f5a5
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 153 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ echo -e "o\nY\nd\nn\n\n\n+200G\n\nt\n\nef00\nw\nY" | gdisk /dev/sda
/contract0003.XXX
/contract0004.XXX
/contract0005.XXX
/contract0006.XXX
/contract0007.XXX
/contract0008.XXX
/contract0009.XXX
/contract0010.XXX
/spectrum.XXX
/system
/universe.XXX
Expand All @@ -57,6 +62,11 @@ echo -e "o\nY\nd\nn\n\n\n+200G\n\nt\n\nef00\nw\nY" | gdisk /dev/sda
- contract0003.XXX => must be the current contract #3 file. XXX must be replaced with the current epoch. (e.g. `contract0003.114`). Data from Random.
- contract0004.XXX => must be the current contract #4 file. XXX must be replaced with the current epoch. (e.g. `contract0004.114`). Data from QUtil.
- contract0005.XXX => must be the current contract #5 file. XXX must be replaced with the current epoch. (e.g. `contract0005.114`). Data from MyLastMatch.
- contract0006.XXX => must be the current contract #6 file. XXX must be replaced with the current epoch. (e.g. `contract0006.114`). Data from GQMPROPO.
- contract0007.XXX => must be the current contract #7 file. XXX must be replaced with the current epoch. (e.g. `contract0007.114`). Data from Swatch.
- contract0008.XXX => must be the current contract #8 file. XXX must be replaced with the current epoch. (e.g. `contract0008.114`). Data from CCF.
- contract0009.XXX => must be the current contract #9 file. XXX must be replaced with the current epoch. (e.g. `contract0009.114`). Data from QEarn.
- contract0010.XXX => must be the current contract #10 file. XXX must be replaced with the current epoch. (e.g. `contract0010.114`). Data from QVault.
- Other contract files with the same format as above. For now, we have 6 contracts.
- universe.XXX => must be the current universe file. XXX must be replaced with the current epoch. (e.g `universe.114`)
- spectrum.XXX => must be the current spectrum file. XXX must be replaced with the current epoch. (e.g `spectrum.114`)
Expand Down
36 changes: 36 additions & 0 deletions doc/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,42 @@ If an outgoing connection to a non-verified peer is accepted and an `ExchangePub
If a protocol violation is detected at any moment during communication (allowing to assume the remote end runs something else, not Qubic node), then the IP is removed even if it is verified.
An IP is only removed from the list of peers if the list still has at least 10 entries afterwards and if it is not in the initial `knownPublicPeers`.

## Broadcast Message

Defined in https://github.com/qubic/core/blob/main/src/network_messages/broadcast_message.h

```
struct BroadcastMessage
{
m256i sourcePublicKey;
m256i destinationPublicKey;
m256i gammingNonce;
enum {
type = 1,
};
};
```

- SourcePublicKey must not be NULL.
- The message signature must be verified with SourcePublicKey.
- The message is broadcasted if sourcePublicKey's balance is greater than or equal MESSAGE_DISSEMINATION_THRESHOLD or sourcePublicKey is a computor's public key.
- destinationPublicKey needs to be in the computorPublicKeys of the node:
- If sourcePublicKey is the same as computorPublicKey:
- computorPrivateKeys and sourcePublicKey are used to generate sharedKey.
- sharedKey is used for generating gammingKey.
- If sourcePublicKey is not the same as computorPublicKey, its balance must be greater than or equal MESSAGE_DISSEMINATION_THRESHOLD.
- gammingKey can be extracted from the message.
- gammingKey is used for decrypting the message's payload.
- The first byte of gammingKey (gammingKey[0]) is used to define the message type.

The message is processed as follows, depending on the message type:

### MESSAGE_TYPE_SOLUTION
- Payload size check.
- Solution mining seed is extracted from the first 32 bytes of the payload.
- Solution nonce is extracted from the next 32 bytes of the payload.
- The solution will be verified and recorded if it does not already exist in the current node.

## ...

66 changes: 66 additions & 0 deletions src/contracts/Qearn.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ struct QEARN : public ContractBase
sint32 returnCode;
};

struct getStatsPerEpoch_input {
uint32 epoch;
};

struct getStatsPerEpoch_output {

uint64 earlyUnlockedAmount;
uint64 earlyUnlockedPercent;
uint64 totalLockedAmount;
uint64 averageAPY;

};

protected:

struct RoundInfo {
Expand Down Expand Up @@ -243,6 +256,39 @@ struct QEARN : public ContractBase
}
_

struct getStatsPerEpoch_locals
{
uint32 cnt, _t;
};

PUBLIC_FUNCTION_WITH_LOCALS(getStatsPerEpoch)

output.earlyUnlockedAmount = state._initialRoundInfo.get(input.epoch)._totalLockedAmount - state._currentRoundInfo.get(input.epoch)._totalLockedAmount;
output.earlyUnlockedPercent = QPI::div(output.earlyUnlockedAmount * 10000ULL, state._initialRoundInfo.get(input.epoch)._totalLockedAmount);

output.totalLockedAmount = 0;
output.averageAPY = 0;
locals.cnt = 0;
for(locals._t = qpi.epoch(); locals._t >= qpi.epoch() - 52; locals._t--)
{
if(locals._t < QEARN_INITIAL_EPOCH)
{
break;
}
if(state._currentRoundInfo.get(locals._t)._totalLockedAmount == 0)
{
continue;
}

locals.cnt++;
output.totalLockedAmount += state._currentRoundInfo.get(locals._t)._totalLockedAmount;
output.averageAPY += QPI::div(state._currentRoundInfo.get(locals._t)._epochBonusAmount * 10000000ULL, state._currentRoundInfo.get(locals._t)._totalLockedAmount);
}

output.averageAPY = QPI::div(output.averageAPY, locals.cnt * 1ULL);

_

struct getUserLockedInfo_locals {
uint32 _t;
uint32 startIndex;
Expand Down Expand Up @@ -598,6 +644,14 @@ struct QEARN : public ContractBase

state._currentRoundInfo.set(input.lockedEpoch, locals.updatedRoundInfo);

if(qpi.epoch() == input.lockedEpoch)
{
locals.updatedRoundInfo._totalLockedAmount = state._initialRoundInfo.get(input.lockedEpoch)._totalLockedAmount - locals.amountOfUnlocking;
locals.updatedRoundInfo._epochBonusAmount = state._initialRoundInfo.get(input.lockedEpoch)._epochBonusAmount;

state._initialRoundInfo.set(input.lockedEpoch, locals.updatedRoundInfo);
}

if(state.locker.get(locals.indexOfinvocator)._lockedAmount == locals.amountOfUnlocking)
{
locals.updatedUserInfo.ID = NULL_ID;
Expand Down Expand Up @@ -666,6 +720,7 @@ struct QEARN : public ContractBase
REGISTER_USER_FUNCTION(getStateOfRound, 3);
REGISTER_USER_FUNCTION(getUserLockStatus, 4);
REGISTER_USER_FUNCTION(getEndedStatus, 5);
REGISTER_USER_FUNCTION(getStatsPerEpoch, 6);

REGISTER_USER_PROCEDURE(lock, 1);
REGISTER_USER_PROCEDURE(unlock, 2);
Expand Down Expand Up @@ -712,6 +767,17 @@ struct QEARN : public ContractBase
state._initialRoundInfo.set(qpi.epoch(), locals.INITIALIZE_ROUNDINFO);
state._currentRoundInfo.set(qpi.epoch(), locals.INITIALIZE_ROUNDINFO);

/*
the initial total locked amount should exclude the amount that locked on initial epoch but it didn't exclude that amount before.
so now it is updated.
I recorded the initial total locked amount of epoch 138 with 6924939374040.
once the epoch 139 is finished, I will also update the initial total locked amount of epoch 139.
this line will be deleted at epoch 140 or 141 at least.
*/
locals.INITIALIZE_ROUNDINFO._epochBonusAmount = state._initialRoundInfo.get(138)._epochBonusAmount;
locals.INITIALIZE_ROUNDINFO._totalLockedAmount = 6924939374040;

state._initialRoundInfo.set(138, locals.INITIALIZE_ROUNDINFO);
_

struct END_EPOCH_locals
Expand Down
42 changes: 0 additions & 42 deletions src/mining/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,4 @@ struct MiningSolutionTransaction : public Transaction
m256i miningSeed;
m256i nonce;
unsigned char signature[SIGNATURE_SIZE];
};

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

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

static constexpr unsigned short minInputSize()
{
return sizeof(codeFileTrailerDigest) + sizeof(dataFileTrailerDigest);
}

m256i codeFileTrailerDigest;
m256i dataFileTrailerDigest;
};

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

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

static constexpr unsigned short minInputSize()
{
return sizeof(codeFileTrailerDigest) + sizeof(dataFileTrailerDigest);
}

m256i codeFileTrailerDigest;
m256i dataFileTrailerDigest;
};
31 changes: 31 additions & 0 deletions src/network_messages/broadcast_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
// "A General Message type used to send/receive messages from/to peers." -> right?
// What the the gammingNonce about exactly?
// Which other message types are planned next to MESSAGE_TYPE_SOLUTION?
//
// MESSAGE_TYPE_SOLUTION
// sourcePublicKey Must not be NULL_ID. It can be a signing public key or a computor/candidate public key.
// destinationPublicKey Public key of a computor/candidate controlled by a node.
// gammingNonce There are two cases:
// - If sourcePublicKey is just a signing pubkey: the first 32 bytes are zeros, and the last 32 bytes are taken from the message.
// - If sourcePublicKey is a public key of a computor: the message is encrypted.
struct BroadcastMessage
{
m256i sourcePublicKey;
Expand All @@ -20,3 +27,27 @@ struct BroadcastMessage
};

static_assert(sizeof(BroadcastMessage) == 32 + 32 + 32, "Something is wrong with the struct size.");

struct CustomMiningTaskMessage
{
m256i sourcePublicKey;
m256i zero;
m256i gammingNonce;

m256i codeFileTrailerDigest;
m256i dataFileTrailerDigest;

// Task payload
};

struct CustomMiningSolutionMessage
{
m256i sourcePublicKey;
m256i zero;
m256i gammingNonce;

m256i codeFileTrailerDigest;
m256i dataFileTrailerDigest;

// Solution payload
};
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 8; // 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 9; // TODO: Set actual value
return 7; // TODO: Set actual value
}

unsigned long long queryIndex;
Expand Down
10 changes: 5 additions & 5 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// Number of ticks from prior epoch that are kept after seamless epoch transition. These can be requested after transition.
#define TICKS_TO_KEEP_FROM_PRIOR_EPOCH 100

#define TARGET_TICK_DURATION 1000
#define TARGET_TICK_DURATION 1500
#define TRANSACTION_SPARSENESS 1

// Below are 2 variables that are used for auto-F5 feature:
Expand All @@ -49,12 +49,12 @@
// Config options that should NOT be changed by operators

#define VERSION_A 1
#define VERSION_B 229
#define VERSION_B 230
#define VERSION_C 0

// Epoch and initial tick for node startup
#define EPOCH 139
#define TICK 17720000
#define EPOCH 140
#define TICK 17860000

#define ARBITRATOR "AFZPUAIYVPNUYGJRQVLUKOPPVLHAZQTGLYAAUUNBXFTVTAMSBKQBLEIEPCVJ"

Expand All @@ -71,7 +71,7 @@ static unsigned short CONTRACT_FILE_NAME[] = L"contract????.???";
#define MAX_DURATION 9000000
#define NUMBER_OF_OPTIMIZATION_STEPS 30
#define NEURON_VALUE_LIMIT 1LL
#define SOLUTION_THRESHOLD_DEFAULT 134
#define SOLUTION_THRESHOLD_DEFAULT 135

#define SOLUTION_SECURITY_DEPOSIT 1000000

Expand Down
Loading

0 comments on commit df0f5a5

Please sign in to comment.