From e201e59b3d5591f61aa591fd435c8be83b570a80 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 10 Jul 2015 15:48:00 -0400 Subject: [PATCH] Define GRAPHENE_MIN_BLOCK_INTERVAL and use it to fix minimum_time_of_last_offered_block logic #154 --- libraries/chain/include/graphene/chain/config.hpp | 1 + .../chain/include/graphene/chain/protocol/chain_parameters.hpp | 1 + libraries/chain/include/graphene/chain/protocol/types.hpp | 2 -- libraries/net/node.cpp | 2 +- libraries/net/peer_connection.cpp | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index d7bad7b7..0c865e15 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -38,6 +38,7 @@ * make the network unable to operate. */ #define GRAPHENE_MIN_TRANSACTION_SIZE_LIMIT 1024 +#define GRAPHENE_MIN_BLOCK_INTERVAL 1 /* seconds */ #define GRAPHENE_MAX_BLOCK_INTERVAL 30 /* seconds */ #define GRAPHENE_DEFAULT_BLOCK_INTERVAL 5 /* seconds */ diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index 0311e95f..d8f8b48b 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -75,6 +75,7 @@ namespace graphene { namespace chain { FC_ASSERT( bulk_discount_threshold_min <= bulk_discount_threshold_max ); FC_ASSERT( bulk_discount_threshold_min > 0 ); + FC_ASSERT( block_interval >= GRAPHENE_MIN_BLOCK_INTERVAL ); FC_ASSERT( block_interval <= GRAPHENE_MAX_BLOCK_INTERVAL ); FC_ASSERT( block_interval > 0 ); FC_ASSERT( maintenance_interval > block_interval, diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 62bfea5d..1354d4cf 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -341,8 +341,6 @@ namespace graphene { namespace chain { bool is_valid_v1( const std::string& base58str ); }; - - } } // graphene::chain namespace fc diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 6a07ec6c..0a5ecf8d 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2415,7 +2415,7 @@ namespace graphene { namespace net { namespace detail { // they must be an attacker or have a buggy client. fc::time_point_sec minimum_time_of_last_offered_block = originating_peer->last_block_time_delegate_has_seen + // timestamp of the block immediately before the first unfetched block - originating_peer->number_of_unfetched_item_ids * GRAPHENE_MAX_BLOCK_INTERVAL; + originating_peer->number_of_unfetched_item_ids * GRAPHENE_MIN_BLOCK_INTERVAL; if (minimum_time_of_last_offered_block > _delegate->get_blockchain_now() + GRAPHENE_NET_FUTURE_SYNC_BLOCKS_GRACE_PERIOD_SEC) { wlog("Disconnecting from peer ${peer} who offered us an implausible number of blocks, their last block would be in the future (${timestamp})", diff --git a/libraries/net/peer_connection.cpp b/libraries/net/peer_connection.cpp index a7766e8a..b912eeb2 100644 --- a/libraries/net/peer_connection.cpp +++ b/libraries/net/peer_connection.cpp @@ -494,7 +494,7 @@ namespace graphene { namespace net // to give us some wiggle room) return inventory_peer_advertised_to_us.size() > GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES * GRAPHENE_NET_MAX_TRX_PER_SECOND * 60 + - (GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES + 1) * 60 / GRAPHENE_MAX_BLOCK_INTERVAL; + (GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES + 1) * 60 / GRAPHENE_MIN_BLOCK_INTERVAL; } bool peer_connection::performing_firewall_check() const