mirror of
				https://git.wownero.com/wownero/wownero.git
				synced 2024-08-15 01:03:23 +00:00 
			
		
		
		
	proper tx_pool handling from CryptoZoidberg / BBR
This commit is contained in:
		
							parent
							
								
									0ddbd20129
								
							
						
					
					
						commit
						3bc16dc0e6
					
				
					 4 changed files with 36 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -51,6 +51,8 @@
 | 
			
		|||
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT              200    //by default, blocks count in blocks downloading
 | 
			
		||||
#define CRYPTONOTE_PROTOCOL_HOP_RELAX_COUNT             3      //value of hop, after which we use only announce of new block
 | 
			
		||||
 | 
			
		||||
#define CRYPTONOTE_MEMPOOL_TX_LIVETIME                    86400 //seconds, one day
 | 
			
		||||
#define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME     604800 //seconds, one week
 | 
			
		||||
 | 
			
		||||
#define P2P_DEFAULT_PORT                                18080
 | 
			
		||||
#define RPC_DEFAULT_PORT                                18081
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -526,6 +526,7 @@ namespace cryptonote
 | 
			
		|||
 | 
			
		||||
    m_store_blockchain_interval.do_call(boost::bind(&blockchain_storage::store_blockchain, &m_blockchain_storage));
 | 
			
		||||
    m_miner.on_idle();
 | 
			
		||||
    m_mempool.on_idle();
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  //-----------------------------------------------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,6 +83,7 @@ namespace cryptonote
 | 
			
		|||
        txd_p.first->second.max_used_block_id = null_hash;
 | 
			
		||||
        txd_p.first->second.max_used_block_height = 0;
 | 
			
		||||
        txd_p.first->second.kept_by_block = kept_by_block;
 | 
			
		||||
        txd_p.first->second.receive_time = time(nullptr);
 | 
			
		||||
        tvc.m_verifivation_impossible = true;
 | 
			
		||||
        tvc.m_added_to_pool = true;
 | 
			
		||||
      }else
 | 
			
		||||
| 
						 | 
				
			
			@ -104,6 +105,7 @@ namespace cryptonote
 | 
			
		|||
      txd_p.first->second.max_used_block_height = max_used_block_height;
 | 
			
		||||
      txd_p.first->second.last_failed_height = 0;
 | 
			
		||||
      txd_p.first->second.last_failed_id = null_hash;
 | 
			
		||||
      txd_p.first->second.receive_time = time(nullptr);
 | 
			
		||||
      tvc.m_added_to_pool = true;
 | 
			
		||||
 | 
			
		||||
      if(txd_p.first->second.fee > 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -178,6 +180,30 @@ namespace cryptonote
 | 
			
		|||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  //---------------------------------------------------------------------------------
 | 
			
		||||
  void tx_memory_pool::on_idle()
 | 
			
		||||
  {
 | 
			
		||||
    m_remove_stuck_tx_interval.do_call([this](){return remove_stuck_transactions();});
 | 
			
		||||
  }
 | 
			
		||||
  //---------------------------------------------------------------------------------
 | 
			
		||||
  //proper tx_pool handling courtesy of CryptoZoidberg and Boolberry
 | 
			
		||||
  bool tx_memory_pool::remove_stuck_transactions()
 | 
			
		||||
  {
 | 
			
		||||
    CRITICAL_REGION_LOCAL(m_transactions_lock);
 | 
			
		||||
    for(auto it = m_transactions.begin(); it!= m_transactions.end();)
 | 
			
		||||
    {
 | 
			
		||||
      uint64_t tx_age = time(nullptr) - it->second.receive_time;
 | 
			
		||||
 | 
			
		||||
      if((tx_age > CRYPTONOTE_MEMPOOL_TX_LIVETIME && !it->second.kept_by_block) || 
 | 
			
		||||
         (tx_age > CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME && it->second.kept_by_block) )
 | 
			
		||||
      {
 | 
			
		||||
        LOG_PRINT_L0("Tx " << it->first << " removed from tx pool due to outdated, age: " << tx_age );
 | 
			
		||||
        m_transactions.erase(it++);
 | 
			
		||||
      }else
 | 
			
		||||
        ++it;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  //---------------------------------------------------------------------------------
 | 
			
		||||
  size_t tx_memory_pool::get_transactions_count()
 | 
			
		||||
  {
 | 
			
		||||
    CRITICAL_REGION_LOCAL(m_transactions_lock);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
 | 
			
		||||
#include "string_tools.h"
 | 
			
		||||
#include "syncobj.h"
 | 
			
		||||
#include "math_helper.h"
 | 
			
		||||
#include "cryptonote_basic_impl.h"
 | 
			
		||||
#include "verification_context.h"
 | 
			
		||||
#include "crypto/hash.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +41,7 @@ namespace cryptonote
 | 
			
		|||
 | 
			
		||||
    bool on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id);
 | 
			
		||||
    bool on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id);
 | 
			
		||||
    void on_idle();
 | 
			
		||||
 | 
			
		||||
    void lock();
 | 
			
		||||
    void unlock();
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +61,7 @@ namespace cryptonote
 | 
			
		|||
    /*bool flush_pool(const std::strig& folder);
 | 
			
		||||
    bool inflate_pool(const std::strig& folder);*/
 | 
			
		||||
 | 
			
		||||
#define CURRENT_MEMPOOL_ARCHIVE_VER    7
 | 
			
		||||
#define CURRENT_MEMPOOL_ARCHIVE_VER    8
 | 
			
		||||
 | 
			
		||||
    template<class archive_t>
 | 
			
		||||
    void serialize(archive_t & a, const unsigned int version)
 | 
			
		||||
| 
						 | 
				
			
			@ -82,9 +84,11 @@ namespace cryptonote
 | 
			
		|||
      //
 | 
			
		||||
      uint64_t last_failed_height;
 | 
			
		||||
      crypto::hash last_failed_id;
 | 
			
		||||
      time_t receive_time;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
  	bool remove_stuck_transactions();
 | 
			
		||||
    bool is_transaction_ready_to_go(tx_details& txd);
 | 
			
		||||
    typedef std::unordered_map<crypto::hash, tx_details > transactions_container;
 | 
			
		||||
    typedef std::unordered_map<crypto::key_image, std::unordered_set<crypto::hash> > key_images_container;
 | 
			
		||||
| 
						 | 
				
			
			@ -92,6 +96,7 @@ namespace cryptonote
 | 
			
		|||
    epee::critical_section m_transactions_lock;
 | 
			
		||||
    transactions_container m_transactions;
 | 
			
		||||
    key_images_container m_spent_key_images;
 | 
			
		||||
    epee::math_helper::once_a_time_seconds<30> m_remove_stuck_tx_interval;
 | 
			
		||||
 | 
			
		||||
    //transactions_container m_alternative_transactions;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -159,6 +164,7 @@ namespace boost
 | 
			
		|||
      ar & td.max_used_block_id;
 | 
			
		||||
      ar & td.last_failed_height;
 | 
			
		||||
      ar & td.last_failed_id;
 | 
			
		||||
      ar & td.receive_time;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue