Skip to content
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ Commands:
Set console logging mode: 0 disabled, 1 low computational cost, 2 full logging. Valid seed and node ip/port are required.
-savesnapshot
Remotely trigger saving snapshot, valid seed and node ip/port are required.
-setexecutionfeemultiplier <NUMERATOR> <DENOMINATOR>
Set the multiplier for the conversion of raw execution time to contract execution fees to ( NUMERATOR / DENOMINATOR ), valid seed and node ip/port are required.
-getexecutionfeemultiplier
Get the current multiplier for the conversion of raw execution time to contract execution fees, valid seed and node ip/port are required.

[SMART CONTRACT COMMANDS]
-callcontractfunction <CONTRACT_INDEX> <CONTRACT_FUNCTION> <INPUT_FORMAT_STRING> <OUTPUT_FORMAT_STRING>
Expand Down
22 changes: 22 additions & 0 deletions argparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ void print_help()
printf("\t\tBroadcast a message on Qubic network, the message will be relayed to discord via bot. Node ip/port are required. Seed for a valid comp is required\t\n");
printf("\t-savesnapshot \n");
printf("\t\tRemotely trigger saving snapshot, valid seed and node ip/port are required.\t\n");
printf("\t-setexecutionfeemultiplier <NUMERATOR> <DENOMINATOR>\n");
printf("\t\tSet the multiplier for the conversion of raw execution time to contract execution fees to ( NUMERATOR / DENOMINATOR ), valid seed and node ip/port are required.\t\n");
printf("\t-getexecutionfeemultiplier\n");
printf("\t\tGet the current multiplier for the conversion of raw execution time to contract execution fees, valid seed and node ip/port are required.\t\n");


printf("\n[SMART CONTRACT COMMANDS]\n");
printf("\t-callcontractfunction <CONTRACT_INDEX> <CONTRACT_FUNCTION> <INPUT_FORMAT_STRING> <OUTPUT_FORMAT_STRING>\n");
Expand Down Expand Up @@ -1129,6 +1134,23 @@ void parseArgument(int argc, char** argv)
CHECK_OVER_PARAMETERS
break;
}
if (strcmp(argv[i], "-setexecutionfeemultiplier") == 0)
{
CHECK_NUMBER_OF_PARAMETERS(2)
g_cmd = SET_EXECUTION_FEE_MULTIPLIER;
g_executionFeeMultiplierNumerator = charToNumber(argv[i + 1]);
g_executionFeeMultiplierDenominator = charToNumber(argv[i + 2]);
i += 3;
CHECK_OVER_PARAMETERS
break;
}
if (strcmp(argv[i], "-getexecutionfeemultiplier") == 0)
{
g_cmd = GET_EXECUTION_FEE_MULTIPLIER;
i++;
CHECK_OVER_PARAMETERS
break;
}

/***********************
***** QX COMMANDS *****
Expand Down
1 change: 1 addition & 0 deletions connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ template RespondTxStatus QubicConnection::receivePacketWithHeaderAs<RespondTxSta
template BroadcastComputors QubicConnection::receivePacketWithHeaderAs<BroadcastComputors>();
template RespondContractIPO QubicConnection::receivePacketWithHeaderAs<RespondContractIPO>();
template std::vector<RespondActiveIPO> QubicConnection::getLatestVectorPacketAs<RespondActiveIPO>();
template SpecialCommandExecutionFeeMultiplierRequestAndResponse QubicConnection::receivePacketWithHeaderAs<SpecialCommandExecutionFeeMultiplierRequestAndResponse>();
// QUOTTERY
template qtryBasicInfo_output QubicConnection::receivePacketWithHeaderAs<qtryBasicInfo_output>();
template getBetInfo_output QubicConnection::receivePacketWithHeaderAs<getBetInfo_output>();
Expand Down
2 changes: 2 additions & 0 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#define SPECIAL_COMMAND_GET_MINING_SCORE_RANKING 14ULL // get the ranking of miners connect to node
#define SPECIAL_COMMAND_SET_CONSOLE_LOGGING_MODE 17ULL // PAUSE key
#define SPECIAL_COMMAND_SAVE_SNAPSHOT 18ULL // F8
#define SPECIAL_COMMAND_SET_EXECUTION_FEE_MULTIPLIER 19ULL
#define SPECIAL_COMMAND_GET_EXECUTION_FEE_MULTIPLIER 20ULL

#define QX_CONTRACT_INDEX 1
#define QX_FEE_FUNCTION_INDEX 1
Expand Down
2 changes: 2 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ char* g_compressTool = nullptr;
uint32_t g_contractIndex = 0;
char g_loggingMode = 0;
char* g_compChatString = nullptr;
uint64_t g_executionFeeMultiplierNumerator = 1;
uint64_t g_executionFeeMultiplierDenominator = 1;

char* g_dumpBinaryFileInput = nullptr;
char* g_dumpBinaryFileOutput = nullptr;
Expand Down
10 changes: 10 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ int run(int argc, char* argv[])
sanityCheckSeed(g_seed);
broadcastCompChat(g_nodeIp, g_nodePort, g_seed, g_compChatString);
break;
case SET_EXECUTION_FEE_MULTIPLIER:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
setExecutionFeeMultiplier(g_nodeIp, g_nodePort, g_seed, g_executionFeeMultiplierNumerator, g_executionFeeMultiplierDenominator);
break;
case GET_EXECUTION_FEE_MULTIPLIER:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
getExecutionFeeMultiplier(g_nodeIp, g_nodePort, g_seed);
break;
case QUTIL_SEND_TO_MANY_V1:
sanityCheckNode(g_nodeIp, g_nodePort);
sanityCheckSeed(g_seed);
Expand Down
108 changes: 108 additions & 0 deletions node_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2210,3 +2210,111 @@ void saveSnapshot(const char* nodeIp, const int nodePort, const char* seed)
LOG("Failed to trigger saving snapshot\n");
}
}

void setExecutionFeeMultiplier(const char* nodeIp, const int nodePort, const char* seed, unsigned long long multiplierNumerator, unsigned long long multiplierDenominator)
{
uint8_t privateKey[32] = { 0 };
uint8_t sourcePublicKey[32] = { 0 };
uint8_t subseed[32] = { 0 };
uint8_t digest[32] = { 0 };
uint8_t signature[64] = { 0 };

struct {
RequestResponseHeader header;
SpecialCommandExecutionFeeMultiplierRequestAndResponse cmd;
uint8_t signature[64];
} packet;
packet.header.setSize(sizeof(packet));
packet.header.randomizeDejavu();
packet.header.setType(PROCESS_SPECIAL_COMMAND);
uint64_t curTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
uint64_t commandByte = (uint64_t)(SPECIAL_COMMAND_SET_EXECUTION_FEE_MULTIPLIER) << 56;
packet.cmd.everIncreasingNonceAndCommandType = commandByte | curTime;
packet.cmd.multiplierNumerator = multiplierNumerator;
packet.cmd.multiplierDenominator = multiplierDenominator;

getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
KangarooTwelve((unsigned char*)&packet.cmd,
sizeof(packet.cmd),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
auto qc = make_qc(nodeIp, nodePort);
qc->sendData((uint8_t*)&packet, packet.header.size());

SpecialCommandExecutionFeeMultiplierRequestAndResponse response;
try
{
response = qc->receivePacketWithHeaderAs<SpecialCommandExecutionFeeMultiplierRequestAndResponse>();
}
catch (std::logic_error)
{
memset(&response, 0, sizeof(SpecialCommandExecutionFeeMultiplierRequestAndResponse));
}

if (response.everIncreasingNonceAndCommandType == packet.cmd.everIncreasingNonceAndCommandType)
{
LOG("Successfully set execution fee multiplier\n");
}
else
{
LOG("Failed to set execution fee multiplier\n");
}
}

void getExecutionFeeMultiplier(const char* nodeIp, const int nodePort, const char* seed)
{
uint8_t privateKey[32] = { 0 };
uint8_t sourcePublicKey[32] = { 0 };
uint8_t subseed[32] = { 0 };
uint8_t digest[32] = { 0 };
uint8_t signature[64] = { 0 };

struct {
RequestResponseHeader header;
SpecialCommand cmd;
uint8_t signature[64];
} packet;
packet.header.setSize(sizeof(packet));
packet.header.randomizeDejavu();
packet.header.setType(PROCESS_SPECIAL_COMMAND);
uint64_t curTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
uint64_t commandByte = (uint64_t)(SPECIAL_COMMAND_GET_EXECUTION_FEE_MULTIPLIER) << 56;
packet.cmd.everIncreasingNonceAndCommandType = commandByte | curTime;

getSubseedFromSeed((uint8_t*)seed, subseed);
getPrivateKeyFromSubSeed(subseed, privateKey);
getPublicKeyFromPrivateKey(privateKey, sourcePublicKey);
KangarooTwelve((unsigned char*)&packet.cmd,
sizeof(packet.cmd),
digest,
32);
sign(subseed, sourcePublicKey, digest, signature);
memcpy(packet.signature, signature, 64);
auto qc = make_qc(nodeIp, nodePort);
qc->sendData((uint8_t*)&packet, packet.header.size());

SpecialCommandExecutionFeeMultiplierRequestAndResponse response;
try
{
response = qc->receivePacketWithHeaderAs<SpecialCommandExecutionFeeMultiplierRequestAndResponse>();
}
catch (std::logic_error)
{
memset(&response, 0, sizeof(SpecialCommandExecutionFeeMultiplierRequestAndResponse));
}

if (response.everIncreasingNonceAndCommandType == packet.cmd.everIncreasingNonceAndCommandType)
{
LOG("Execution fee multiplier is currently set to:\n");
LOG("- Numerator: %" PRIu64 "\n", response.multiplierNumerator);
LOG("- Denominator: %" PRIu64 "\n", response.multiplierDenominator);
}
else
{
LOG("Failed to get execution fee multiplier\n");
}
}
2 changes: 2 additions & 0 deletions node_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ void syncTime(const char* nodeIp, const int nodePort, const char* seed);
void setLoggingMode(const char* nodeIp, const int nodePort, const char* seed, char mode);
void broadcastCompChat(const char* nodeIp, const int nodePort, const char* seed, char* compChatMsg);
void saveSnapshot(const char* nodeIp, const int nodePort, const char* seed);
void setExecutionFeeMultiplier(const char* nodeIp, const int nodePort, const char* seed, unsigned long long multiplierNumerator, unsigned long long multiplierDenominator);
void getExecutionFeeMultiplier(const char* nodeIp, const int nodePort, const char* seed);
15 changes: 15 additions & 0 deletions structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ enum COMMAND
SHAREHOLDER_VOTE,
SHAREHOLDER_GET_VOTE,
SHAREHOLDER_GET_VOTING_RESULTS,
SET_EXECUTION_FEE_MULTIPLIER,
GET_EXECUTION_FEE_MULTIPLIER,
TOTAL_COMMAND // DO NOT CHANGE THIS
};

Expand Down Expand Up @@ -870,6 +872,19 @@ struct SpecialCommandSaveSnapshotRequestAndResponse
}
};

// This struct is used as response for the get command and as request and response for the set command.
struct SpecialCommandExecutionFeeMultiplierRequestAndResponse
{
unsigned long long everIncreasingNonceAndCommandType;
unsigned long long multiplierNumerator;
unsigned long long multiplierDenominator;

static constexpr unsigned char type()
{
return 255;
}
};

#define REQUEST_TX_STATUS 201

struct RequestTxStatus
Expand Down