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/ep96 to develop #54

Merged
merged 7 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If an outgoing connection to a verified peer is rejected, the peer loses the ver
If an outgoing connection to a non-verified peer is rejected, the peer is removed from the list of peers.
If an outgoing connection to a non-verified peer is accepted and an `ExchangePublicPeers` message is received, the peer gets the verified status.
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.
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`.


## ...
Expand Down
1 change: 1 addition & 0 deletions src/Qubic.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<ClInclude Include="network_messages\header.h" />
<ClInclude Include="network_messages\public_peers.h" />
<ClInclude Include="network_messages\special_command.h" />
<ClInclude Include="network_messages\system_info.h" />
<ClInclude Include="network_messages\tick.h" />
<ClInclude Include="network_messages\transactions.h" />
<ClInclude Include="platform\concurrency.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 @@ -105,6 +105,9 @@
<ClInclude Include="network_core\tcp4.h">
<Filter>network_core</Filter>
</ClInclude>
<ClInclude Include="network_messages\system_info.h">
<Filter>network_messages</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="smart_contracts">
Expand Down
52 changes: 46 additions & 6 deletions src/network_core/peers.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,54 @@ static void enqueueResponse(Peer* peer, unsigned int dataSize, unsigned char typ
RELEASE(responseQueueHeadLock);
}

/**
* checks if a given address is a bogon address
* a bogon address is an ip address which should not be used pubicly (e.g. private networks)
*
* @param address the ip address to be checked
* @return true if address is bogon or false if not
*/
static bool isBogonAddress(const IPv4Address& address)
{
return (!address.u8[0])
|| (address.u8[0] == 127)
|| (address.u8[0] == 10)
|| (address.u8[0] == 172 && address.u8[1] >= 16 && address.u8[1] <= 31)
|| (address.u8[0] == 192 && address.u8[1] == 168)
|| (address.u8[0] == 255);
}

/**
* checks if a given address was manually set in the initial list of known public peers
*
* @param address the ip address to be checked
* @return true if the ip address is in the Known Public Peers or false if not
*/
static bool isAddressInKnownPublicPeers(const IPv4Address& address)
{
// keep this exception to avoid bogon addresses kept for outgoing connections
if (isBogonAddress(address))
return false;

for (unsigned int i = 0; i < sizeof(knownPublicPeers) / sizeof(knownPublicPeers[0]); i++)
{
const IPv4Address& peer_ip = *reinterpret_cast<const IPv4Address*>(knownPublicPeers[i]);
if (peer_ip == address)
return true;
}
return false;
}


// Forget public peer (no matter if verified or not) if we have more than the minium number of peers
static void forgetPublicPeer(const IPv4Address& address)
{
// if address is one of our initial peers we don't forget it
if (isAddressInKnownPublicPeers(address))
{
return;
}

if (listOfPeersIsStatic)
{
return;
Expand Down Expand Up @@ -300,14 +344,10 @@ static void penalizePublicPeerRejectedConnection(const IPv4Address& address)
}
}


static void addPublicPeer(const IPv4Address& address)
{
if ((!address.u8[0])
|| (address.u8[0] == 127)
|| (address.u8[0] == 10)
|| (address.u8[0] == 172 && address.u8[1] >= 16 && address.u8[1] <= 31)
|| (address.u8[0] == 192 && address.u8[1] == 168)
|| (address.u8[0] == 255))
if (isBogonAddress(address))
{
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/network_messages/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
#include "special_command.h"
#include "tick.h"
#include "transactions.h"
#include "system_info.h"
32 changes: 32 additions & 0 deletions src/network_messages/system_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "common_def.h"

#define REQUEST_SYSTEM_INFO 46


#define RESPOND_SYSTEM_INFO 47

struct RespondSystemInfo
{
short version;
unsigned short epoch;
unsigned int tick;
unsigned int initialTick;
unsigned int latestCreatedTick;

unsigned short initialMillisecond;
unsigned char initialSecond;
unsigned char initialMinute;
unsigned char initialHour;
unsigned char initialDay;
unsigned char initialMonth;
unsigned char initialYear;

unsigned int numberOfEntities;
unsigned int numberOfTransactions;

m256i randomMiningSeed;
};

static_assert(sizeof(RespondSystemInfo) == 2 + 2 + 4 + 4 + 4 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 4 + 32 + 4, "Something is wrong with the struct size of RespondSystemInfo.");
8 changes: 4 additions & 4 deletions src/public_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#define NUMBER_OF_SOLUTION_PROCESSORS 2 // do not increase this for this epoch, because there may be issues due too fast ticking

#define VERSION_A 1
#define VERSION_B 191
#define VERSION_B 192
#define VERSION_C 0

#define EPOCH 94
#define TICK 12270000
#define EPOCH 95
#define TICK 12380000

// random seed is now obtained from spectrumDigests

Expand All @@ -30,7 +30,7 @@ static unsigned short CONTRACT_FILE_NAME[] = L"contract????.???";
#define NUMBER_OF_OUTPUT_NEURONS 2400
#define MAX_INPUT_DURATION 200
#define MAX_OUTPUT_DURATION 200
#define SOLUTION_THRESHOLD_DEFAULT 693
#define SOLUTION_THRESHOLD_DEFAULT 694
#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: 32 additions & 0 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,32 @@ static void processRequestContractFunction(Peer* peer, const unsigned long long
}
}

static void processRequestSystemInfo(Peer* peer, RequestResponseHeader* header)
{
RespondSystemInfo respondedSystemInfo;

respondedSystemInfo.version = system.version;
respondedSystemInfo.epoch = system.epoch;
respondedSystemInfo.tick = system.tick;
respondedSystemInfo.initialTick = system.initialTick;
respondedSystemInfo.latestCreatedTick = system.latestLedTick;

respondedSystemInfo.initialMillisecond = system.initialMillisecond;
respondedSystemInfo.initialSecond = system.initialSecond;
respondedSystemInfo.initialMinute = system.initialMinute;
respondedSystemInfo.initialHour = system.initialHour;
respondedSystemInfo.initialDay = system.initialDay;
respondedSystemInfo.initialMonth = system.initialMonth;
respondedSystemInfo.initialYear = system.initialYear;

respondedSystemInfo.numberOfEntities = numberOfEntities;
respondedSystemInfo.numberOfTransactions = numberOfTransactions;

respondedSystemInfo.randomMiningSeed = score->initialRandomSeed;

enqueueResponse(peer, sizeof(respondedSystemInfo), RESPOND_SYSTEM_INFO, header->dejavu(), &respondedSystemInfo);
}

static void processSpecialCommand(Peer* peer, RequestResponseHeader* header)
{
SpecialCommand* request = header->getPayload<SpecialCommand>();
Expand Down Expand Up @@ -1281,6 +1307,12 @@ static void requestProcessor(void* ProcedureArgument)
}
break;

case REQUEST_SYSTEM_INFO:
{
processRequestSystemInfo(peer, header);
}
break;

case SpecialCommand::type:
{
processSpecialCommand(peer, header);
Expand Down
2 changes: 2 additions & 0 deletions src/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ template<
struct ScoreFunction
{
int miningData[dataLength];
m256i initialRandomSeed;

#pragma warning(push)
#pragma warning(disable:4293)
Expand Down Expand Up @@ -71,6 +72,7 @@ struct ScoreFunction

void initMiningData(m256i randomSeed)
{
initialRandomSeed = randomSeed; // persist the initial random seed to be able to sned it back on system info response
random((unsigned char*)&randomSeed, (unsigned char*)&randomSeed, (unsigned char*)miningData, sizeof(miningData));
}

Expand Down
22 changes: 19 additions & 3 deletions src/smart_contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# smart_contracts
# Qubic Contract Development Guidelines

This directory contains the smart contract implementations in header files starting with a capital letter.

Further, it contain `qpi.h`, the Qubic Programming Interface for implementing the smart contracts.
Further, it contains `qpi.h`, the Qubic Programming Interface for implementing the smart contracts.
It is available automatically in the smart contract implementation header files.

Other header files with starting with a lower case letter, such as `math_lib.h`, provide additional library functions that may be used in the smart contract implementation header files (for example, use `#include "math_lib.h"`).
Other header files starting with a lowercase letter, such as `math_lib.h`, provide examples of useful functions that can be used in contract code.

This document outlines the guidelines for developing secure and efficient Qubic contracts. Adherence to these guidelines is crucial for ensuring the proper functionality and security of your contracts within the Qubic environment.

### Syntax and Formatting:
- Qubic contracts generally inherit the syntax and format of C/C++.
- However, due to security reasons, certain things are prohibited:
- Declaring and accessing arrays using the C/C++ notation (`[` `]`). Utilize pre-defined array structures within qpi.h such as `collection`, `uint32_64`, `uint32_128`,...
- Any pointer-related techniques such as casting, accessing,...
- Native data types like `int`, `long`, `char`,... Use their corresponding predefined datatypes in `qpi.h` (`int8`, `int16`, `int32`, `int64`,...)
- Inclusion of other files via `#include`. All functions must reside within a single file.
- Math operators `%` and `/`. Use `mod` and `div` from `qpi.h` instead. `+`, `-`, `*`(multiplication), and bit-wise operators are accepted.
- Local variable declaration, even for for-loop. You need to define all necessary variables in the contract state and utilize them.
- The `typedef`, `union` keyword.
- Floating points datatypes (half, float, double)

Currently, the maximum contract state size is capped at 1 GiB (03/02/2024). This value is subject to change based on hardware upgrades of computors.
Loading