diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 68794f5b5..6508d8781 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -66,6 +66,8 @@ using namespace dev::eth; #define CONSENSUS 1 #endif +const int SkaleHost::REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC = 600; + std::unique_ptr< ConsensusInterface > DefaultConsensusFactory::create( ConsensusExtFace& _extFace ) const { #if CONSENSUS @@ -325,6 +327,13 @@ void SkaleHost::logState() { } h256 SkaleHost::receiveTransaction( std::string _rlp ) { + // drop incoming transactions if skaled has an outdated state + if ( m_client.bc().info().timestamp() + REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC < + std::time( NULL ) ) { + LOG( m_debugLogger ) << "Dropped the transaction received through broadcast"; + return h256(); + } + Transaction transaction( jsToBytes( _rlp, OnFailed::Throw ), CheckTransaction::None ); h256 sha = transaction.sha3(); diff --git a/libethereum/SkaleHost.h b/libethereum/SkaleHost.h index 9a910ad98..8ffce7aca 100644 --- a/libethereum/SkaleHost.h +++ b/libethereum/SkaleHost.h @@ -229,4 +229,8 @@ class SkaleHost { std::atomic_int total_sent, total_arrived; boost::chrono::high_resolution_clock::time_point latestBlockTime; + + // reject old transactions that come through broadcast + // if current ts is much bigger than currentBlock.ts + static const int REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC; };