aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-08-09 14:58:11 +0200
committerRiccardo Spagni <ric@spagni.net>2017-08-09 14:58:11 +0200
commitf43d59d8b368f79231f536a26a668a55e1bf7ead (patch)
treecd7615acb005a5a299ef2a8d628695f15bdb49ce
parentMerge pull request #2267 (diff)
parentprotocol: add checks for top block hard fork version (diff)
downloadmonero-f43d59d8b368f79231f536a26a668a55e1bf7ead.tar.xz
Merge pull request #2269
635929ea protocol: add checks for top block hard fork version (moneromooo-monero) 7482253a epee: fixup KV_SERIALIZE_OPT to work in more cases (moneromooo-monero)
-rw-r--r--contrib/epee/include/serialization/keyvalue_serialization.h5
-rw-r--r--src/cryptonote_core/blockchain.h9
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_defs.h2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl11
4 files changed, 26 insertions, 1 deletions
diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h
index f4442e46c..d4413a71b 100644
--- a/contrib/epee/include/serialization/keyvalue_serialization.h
+++ b/contrib/epee/include/serialization/keyvalue_serialization.h
@@ -70,10 +70,13 @@ public: \
#define KV_SERIALIZE_N(varialble, val_name) \
epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name);
+ template<typename T> inline void serialize_default(const T &t, T v) { }
+ template<typename T> inline void serialize_default(T &t, T v) { t = v; }
+
#define KV_SERIALIZE_OPT_N(variable, val_name, default_value) \
do { \
if (!epee::serialization::selector<is_store>::serialize(this_ref.variable, stg, hparent_section, val_name)) \
- this_ref.variable = default_value; \
+ epee::serialize_default(this_ref.variable, default_value); \
} while (0);
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index bd8a8313c..aa61dc034 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -746,6 +746,15 @@ namespace cryptonote
uint8_t get_ideal_hard_fork_version(uint64_t height) const { return m_hardfork->get_ideal_version(height); }
/**
+ * @brief returns the actual hardfork version for a given block height
+ *
+ * @param height the height for which to check version info
+ *
+ * @return the version
+ */
+ uint8_t get_hard_fork_version(uint64_t height) const { return m_hardfork->get(height); }
+
+ /**
* @brief get information about hardfork voting for a version
*
* @param version the version in question
diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h
index 042ae49f6..37b503436 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_defs.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h
@@ -195,10 +195,12 @@ namespace cryptonote
{
uint64_t current_height;
crypto::hash top_id;
+ uint8_t top_version;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(current_height)
KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
+ KV_SERIALIZE_OPT(top_version, (uint8_t)0)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 4652bf23e..3e3bb83d0 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -256,6 +256,14 @@ namespace cryptonote
if(context.m_state == cryptonote_connection_context::state_synchronizing)
return true;
+ // from v6, if the peer advertises a top block version, reject if it's not what it should be (will only work if no voting)
+ const uint8_t version = m_core.get_blockchain_storage().get_ideal_hard_fork_version(hshd.current_height - 1);
+ if (version >= 6 && version != hshd.top_version)
+ {
+ LOG_DEBUG_CC(context, "Ignoring due to wrong top version (" << hshd.top_version << ", expected " << version);
+ return false;
+ }
+
uint64_t target = m_core.get_target_blockchain_height();
if (target == 0)
target = m_core.get_current_blockchain_height();
@@ -297,6 +305,7 @@ namespace cryptonote
bool t_cryptonote_protocol_handler<t_core>::get_payload_sync_data(CORE_SYNC_DATA& hshd)
{
m_core.get_blockchain_top(hshd.current_height, hshd.top_id);
+ hshd.top_version = m_core.get_blockchain_storage().get_hard_fork_version(hshd.current_height);
hshd.current_height +=1;
return true;
}
@@ -348,6 +357,7 @@ namespace cryptonote
{
LOG_PRINT_CCONTEXT_L0("Block verification failed, dropping connection");
m_p2p->drop_connection(context);
+ m_p2p->add_host_fail(context.m_remote_address);
m_block_queue.flush_spans(context.m_connection_id);
return 1;
}
@@ -616,6 +626,7 @@ namespace cryptonote
{
LOG_PRINT_CCONTEXT_L0("Block verification failed, dropping connection");
m_p2p->drop_connection(context);
+ m_p2p->add_host_fail(context.m_remote_address);
m_block_queue.flush_spans(context.m_connection_id);
return 1;
}