Skip to content

Commit

Permalink
Version 20231218
Browse files Browse the repository at this point in the history
+ removed old networkID
+ removed switch checks
+ p2p connectivity, blocking of old nodes immediately
+ optimised performance
  • Loading branch information
dynexcoin committed Dec 18, 2023
1 parent fde16f7 commit 94fc2d7
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 153 deletions.
30 changes: 3 additions & 27 deletions src/DynexCNCore/Blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,8 @@ bool Blockchain::have_tx_keyimg_as_spent(const Crypto::KeyImage &key_im) {
}

bool Blockchain::check_tx_inputs_keyimages_domain(const Crypto::KeyImage& keyImage) {
// scalar multiplication over I & R:
Crypto::KeyImage Ry = scalarmultKey(I, R);
// first validation:
if (!(scalarmultKey(I,R) == I)) {
logger(ERROR, BRIGHT_RED) << "Transaction uses key image not in the valid domain";
return true;
}
// validate ((key image * curve order) == (identity element)
Crypto::KeyImage Rx = scalarmultKey(R, keyImage);
bool r = keyImage!=R;
return r;
if (getCurrentBlockchainHeight()>334581) return true;
return keyImage!=R;
}

bool Blockchain::checkIfSpent(const Crypto::KeyImage& keyImage, uint32_t blockIndex) {
Expand Down Expand Up @@ -2094,23 +2085,8 @@ bool Blockchain::pushBlock(const Block& blockData, block_verification_context& b
return true;
}

bool Blockchain::newversiondate() {
const int day = 15;
const int month = 12;
const int year = 2023;

if (daysFromNowToInputDate(day, month, year) < 0)
return true;

return false;
}

bool Blockchain::check_non_privacy(const Transaction& tx) {

if (!newversiondate()) {
return true;
}

logger(DEBUGGING) << "DEBUG (Blockchain.cpp): check_non_privacy invoked for transaction " << getObjectHash(tx);
DynexCN::TransactionPrefix transaction = *static_cast<const TransactionPrefix*>(&tx);

Expand All @@ -2136,7 +2112,7 @@ bool Blockchain::check_non_privacy(const Transaction& tx) {
}

// enforce only non-privacy tx:
if (newversiondate() && (amount.empty() || to_address.empty())) {
if (amount.empty() || to_address.empty()) {
{
logger(ERROR) << "Transaction " << getObjectHash(tx) << " rejected: privacy transaction";
return false;
Expand Down
17 changes: 0 additions & 17 deletions src/DynexCNCore/Blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,6 @@ namespace DynexCN {
const TransactionEntry& transactionByIndex(TransactionIndex index);
// non-privacy functions:
bool check_non_privacy(const Transaction& tx);
int daysFromNowToInputDate(int day, int month, int year) {
auto now = std::chrono::system_clock::now();
time_t now_c = std::chrono::system_clock::to_time_t(now);
struct tm * timeGMT;
timeGMT = gmtime (&now_c);
struct tm inputDate = {0};
inputDate.tm_year = year - 1900;
inputDate.tm_mon = month - 1;
inputDate.tm_mday = day;
time_t inputDate_c = mktime(&inputDate);
time_t timeGMT_c = mktime(timeGMT);
double diff_seconds = difftime(inputDate_c, timeGMT_c);
int diff_days = diff_seconds / (60 * 60 * 24);
return diff_days;
}
bool newversiondate();

bool pushBlock(const Block& blockData, block_verification_context& bvc);
bool pushBlock(const Block& blockData, const std::vector<Transaction>& transactions, block_verification_context& bvc);
bool pushBlock(BlockEntry& block);
Expand Down
17 changes: 1 addition & 16 deletions src/DynexCNCore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,23 +1213,8 @@ bool core::getPaymentId(const Transaction& transaction, Crypto::Hash& paymentId)
return getPaymentIdFromTransactionExtraNonce(extraNonce.nonce, paymentId);
}

bool core::newversiondate() {
const int day = 15;
const int month = 12;
const int year = 2023;

if (daysFromNowToInputDate(day, month, year) < 0)
return true;

return false;
}

bool core::check_non_privacy(const Transaction& tx) {

if (!newversiondate()) {
return true;
}

logger(DEBUGGING) << "DEBUG (Core.cpp): check_non_privacy invoked for transaction " << getObjectHash(tx);

DynexCN::TransactionPrefix transaction = *static_cast<const TransactionPrefix*>(&tx);
Expand All @@ -1256,7 +1241,7 @@ bool core::check_non_privacy(const Transaction& tx) {
}

// enforce only non-privacy tx:
if (newversiondate() && (amount.empty() || to_address.empty())) {
if (amount.empty() || to_address.empty()) {
{
logger(ERROR) << "Transaction " << getObjectHash(tx) << " rejected: privacy transaction";
return false;
Expand Down
18 changes: 0 additions & 18 deletions src/DynexCNCore/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,7 @@ namespace DynexCN {

// non-privacy functions:
bool check_non_privacy(const Transaction& tx);
int daysFromNowToInputDate(int day, int month, int year) {
auto now = std::chrono::system_clock::now();
time_t now_c = std::chrono::system_clock::to_time_t(now);
struct tm * timeGMT;
timeGMT = gmtime (&now_c);
struct tm inputDate = {0};
inputDate.tm_year = year - 1900;
inputDate.tm_mon = month - 1;
inputDate.tm_mday = day;
time_t inputDate_c = mktime(&inputDate);
time_t timeGMT_c = mktime(timeGMT);
double diff_seconds = difftime(inputDate_c, timeGMT_c);
int diff_days = diff_seconds / (60 * 60 * 24);
return diff_days;
}
bool newversiondate();



bool have_block(const Crypto::Hash& id) override;
std::vector<Crypto::Hash> buildSparseChain() override;
std::vector<Crypto::Hash> buildSparseChain(const Crypto::Hash& startBlockId) override;
Expand Down
74 changes: 4 additions & 70 deletions src/P2p/NetNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,6 @@ size_t get_random_index_with_fixed_probability(size_t max_index) {
return (x*x*x) / (max_index*max_index); //parabola \/
}

int daysFromNowToInputDate(int day, int month, int year) {
auto now = std::chrono::system_clock::now();
time_t now_c = std::chrono::system_clock::to_time_t(now);
struct tm * timeGMT;
timeGMT = gmtime (&now_c);
struct tm inputDate = {0};
inputDate.tm_year = year - 1900;
inputDate.tm_mon = month - 1;
inputDate.tm_mday = day;
time_t inputDate_c = mktime(&inputDate);
time_t timeGMT_c = mktime(timeGMT);
double diff_seconds = difftime(inputDate_c, timeGMT_c);
int diff_days = diff_seconds / (60 * 60 * 24);
return diff_days;
}

void addPortMapping(Logging::LoggerRef& logger, uint32_t port) {
// Add UPnP port mapping
logger(INFO) << "Attempting to add IGD port mapping.";
Expand Down Expand Up @@ -255,16 +239,13 @@ namespace DynexCN
m_payload_handler(payload_handler),
m_allow_local_ip(false),
m_hide_my_port(false),
m_network_id(BYTECOIN_NETWORK),
m_network_id_np(DYNEX_NETWORK),
m_network_id(DYNEX_NETWORK),
logger(log, "node_server"),
m_stopEvent(m_dispatcher),
m_idleTimer(m_dispatcher),
m_timedSyncTimer(m_dispatcher),
m_timeoutTimer(m_dispatcher),
m_stop(false),
// intervals
// m_peer_handshake_idle_maker_interval(DynexCN::P2P_DEFAULT_HANDSHAKE_INTERVAL),
m_connections_maker_interval(1),
m_peerlist_store_interval(60*30, false) {
}
Expand All @@ -287,20 +268,6 @@ namespace DynexCN
int ret = 0;
handled = true;

// enforce new version?:
if (m_network_id!=m_network_id_np && newversiondate()) {
m_network_id = m_network_id_np;
logger(INFO, BRIGHT_GREEN) << "Switched network to non-privacy " << m_network_id;
// drop this connection:
ctx.m_state = DynexCNConnectionContext::state_shutdown;
// drop all other connections:
forEachConnection([&](P2pConnectionContext& context) {
context.m_state = DynexCNConnectionContext::state_shutdown;
logger(INFO) << "Node connection to " << Common::ipAddressToString(context.m_remote_ip) << " dropped";
});
return 0;
}

if (cmd.isResponse && cmd.command == COMMAND_TIMED_SYNC::ID) {
if (!handleTimedSyncResponse(cmd.buf, ctx)) {
// invalid response, close connection
Expand Down Expand Up @@ -579,25 +546,13 @@ namespace DynexCN


//-----------------------------------------------------------------------------------
bool NodeServer::newversiondate() {
const int day = 15;
const int month = 12;
const int year = 2023;

if (daysFromNowToInputDate(day, month, year) < 0)
return true;

return false;
}

bool NodeServer::init(const NetNodeConfig& config) {
if (!config.getTestnet()) {
for (auto seed : DynexCN::SEED_NODES) {
append_net_address(m_seed_nodes, seed);
}
} else {
m_network_id.data[0] += 1;
m_network_id_np.data[0] += 1;
}

if (!handleConfig(config)) {
Expand Down Expand Up @@ -627,14 +582,8 @@ namespace DynexCN
m_last_stat_request_time = 0;
#endif

// enforce new version?:
if (newversiondate() || config.getTestnet()) {
m_network_id = m_network_id_np;
}
logger(INFO) << "Network (non-privacy): " << m_network_id;

logger(INFO) << "Network: " << m_network_id;
logger(INFO) << "Network (non-privacy): " << m_network_id_np;

//try to bind
logger(INFO) << "Binding on " << m_bind_ip << ":" << m_port;
m_listeningPort = Common::fromString<uint16_t>(m_port);
Expand Down Expand Up @@ -755,11 +704,6 @@ namespace DynexCN
//-----------------------------------------------------------------------------------
bool NodeServer::handshake(DynexCN::LevinProtocol& proto, P2pConnectionContext& context, bool just_take_peerlist) {

// enforce new version?
if (m_network_id!=m_network_id_np && newversiondate()) {
m_network_id = m_network_id_np;
}

COMMAND_HANDSHAKE::request arg;
COMMAND_HANDSHAKE::response rsp;
get_local_node_data(arg.node_data);
Expand All @@ -772,7 +716,7 @@ namespace DynexCN

context.version = rsp.node_data.version;

if ((rsp.node_data.network_id != m_network_id) && (rsp.node_data.network_id != m_network_id_np)) {
if (rsp.node_data.network_id != m_network_id) {
logger(Logging::DEBUGGING) << context << "COMMAND_HANDSHAKE Failed, wrong network! (" << rsp.node_data.network_id << "), closing connection.";
return false;
}
Expand Down Expand Up @@ -1179,11 +1123,6 @@ namespace DynexCN
bool NodeServer::get_local_node_data(basic_node_data& node_data)
{

// enforce new version?
if (m_network_id!=m_network_id_np && newversiondate()) {
m_network_id = m_network_id_np;
}

node_data.version = P2PProtocolVersion::CURRENT;
node_data.node_version = CN_PROJECT_VERSION;

Expand Down Expand Up @@ -1373,11 +1312,6 @@ namespace DynexCN

int NodeServer::handle_handshake(int command, COMMAND_HANDSHAKE::request& arg, COMMAND_HANDSHAKE::response& rsp, P2pConnectionContext& context)
{
// enforce new version?
if (m_network_id!=m_network_id_np && newversiondate()) {
m_network_id = m_network_id_np;
}

context.version = arg.node_data.version;

if (!is_remote_host_allowed(context.m_remote_ip)) {
Expand All @@ -1386,7 +1320,7 @@ namespace DynexCN
return 1;
}

if ((arg.node_data.network_id != m_network_id) && (arg.node_data.network_id != m_network_id_np)) {
if (arg.node_data.network_id != m_network_id) {
add_host_fail(context.m_remote_ip);
logger(Logging::INFO) << context << "WRONG NETWORK AGENT CONNECTED! id=" << arg.node_data.network_id;
context.m_state = DynexCNConnectionContext::state_shutdown;
Expand Down
1 change: 0 additions & 1 deletion src/P2p/NetNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ namespace DynexCN
std::list<PeerlistEntry> m_command_line_peers;
uint64_t m_peer_livetime;
boost::uuids::uuid m_network_id;
boost::uuids::uuid m_network_id_np;
std::map<uint32_t, time_t> m_blocked_hosts;
std::map<uint32_t, uint64_t> m_host_fails_score;

Expand Down
1 change: 0 additions & 1 deletion src/P2p/P2pNetworks.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@

namespace DynexCN
{
const static boost::uuids::uuid BYTECOIN_NETWORK = { { 0xae, 0x3c, 0xff, 0xc2, 0x53, 0xea, 0xeb, 0x3f, 0x81, 0xf1, 0xde, 0x41, 0x9a, 0x55, 0xb0, 0xfd } };
const static boost::uuids::uuid DYNEX_NETWORK = { { 0x3c, 0xae, 0xb5, 0xc3, 0xf3, 0xee, 0xe0, 0x2f, 0xd2, 0xc3, 0xee, 0x1a, 0x3c, 0x4e, 0x0b, 0xfa } };
}
3 changes: 1 addition & 2 deletions src/P2p/P2pNodeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ P2pNodeConfig::P2pNodeConfig() :
handshakeTimeout(std::chrono::milliseconds(P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT)),
connectInterval(P2P_DEFAULT_CONNECT_INTERVAL),
connectTimeout(std::chrono::milliseconds(P2P_DEFAULT_CONNECTION_TIMEOUT)),
networkId(BYTECOIN_NETWORK),
networkId_np(DYNEX_NETWORK),
networkId(DYNEX_NETWORK),
expectedOutgoingConnectionsCount(P2P_DEFAULT_CONNECTIONS_COUNT),
whiteListConnectionsPercent(P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT),
peerListConnectRange(P2P_DEFAULT_CONNECT_RANGE),
Expand Down
2 changes: 1 addition & 1 deletion src/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define CN_VER_MAJOR 2
#define CN_VER_MINOR 2
#define CN_VER_REV 2
#define CN_VER_BUILD 20231217
#define CN_VER_BUILD 20231218
#define CN_VER_REMARK "#non-privacy"
#define CN_PROJECT_VERSION STR(CN_VER_MAJOR) "." STR(CN_VER_MINOR) "." STR(CN_VER_REV)
#define CN_PROJECT_VERSION_BUILD_NO STR(CN_VER_BUILD)
Expand Down

0 comments on commit 94fc2d7

Please sign in to comment.