Skip to content

Commit f31d1cf

Browse files
committed
Throttling of expired transactions
1 parent 24a6c39 commit f31d1cf

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/catapult/chain/ChainResults.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ namespace catapult { namespace chain {
4343
/// Validation failed because the unconfirmed cache is too full.
4444
DEFINE_CHAIN_RESULT(Unconfirmed_Cache_Too_Full, 201);
4545

46+
/// Validation failed because the transaction is expired.
47+
DEFINE_CHAIN_RESULT(Transaction_Expired, 202);
48+
4649
#ifndef CUSTOM_RESULT_DEFINITION
4750
}}
4851
#endif

src/catapult/chain/UtUpdater.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ namespace catapult { namespace chain {
171171
const auto& entity = *utInfo.pEntity;
172172
const auto& entityHash = utInfo.EntityHash;
173173

174+
if (entity.Deadline <= currentTime) {
175+
CATAPULT_LOG(warning) << "dropping transaction " << entityHash << " " << entity.Type << " due to expiration";
176+
applyState.FailureTransactions.emplace_back(FailureInfo{ entity, entityHash, effectiveHeight, Failure_Chain_Transaction_Expired });
177+
continue;
178+
}
179+
174180
if (!filter(utInfo))
175181
continue;
176182

@@ -184,15 +190,15 @@ namespace catapult { namespace chain {
184190
// don't log reverted transactions that could have been included by harvester with lower min fee multiplier
185191
if (TransactionSource::New == transactionSource) {
186192
CATAPULT_LOG(debug)
187-
<< "dropping transaction " << entityHash << " with max fee " << entity.MaxFee
193+
<< "dropping transaction " << entityHash << " " << entity.Type << " with max fee " << entity.MaxFee
188194
<< " because min fee is " << minTransactionFee;
189195
}
190196

191197
continue;
192198
}
193199

194200
if (throttle(utInfo, transactionSource, applyState, readOnlyCache)) {
195-
CATAPULT_LOG(warning) << "dropping transaction " << entityHash << " due to throttle";
201+
CATAPULT_LOG(warning) << "dropping transaction " << entityHash << " " << entity.Type << " due to throttle";
196202
applyState.FailureTransactions.emplace_back(FailureInfo{ entity, entityHash, effectiveHeight, Failure_Chain_Unconfirmed_Cache_Too_Full });
197203
continue;
198204
}

tests/catapult/chain/UtUpdaterTests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,11 @@ namespace catapult { namespace chain {
365365
ASSERT_EQ(failedIndexes.size(), m_failedTransactionStatuses.size());
366366
for (auto i = 0u; i < failedIndexes.size(); ++i) {
367367
auto failedIndex = failedIndexes[i].first;
368+
auto timeOffset = Default_Time.unwrap() + 1;
368369
auto message = "failed index " + std::to_string(failedIndex);
369370
EXPECT_EQ(entityInfos[failedIndex].hash(), m_failedTransactionStatuses[i].Hash) << message;
370371
EXPECT_EQ(failedIndexes[i].second, validators::ValidationResult(m_failedTransactionStatuses[i].Status)) << message;
371-
EXPECT_EQ(Timestamp(failedIndex * failedIndex), m_failedTransactionStatuses[i].Deadline) << message;
372+
EXPECT_EQ(Timestamp((timeOffset + failedIndex) * (timeOffset + failedIndex)), m_failedTransactionStatuses[i].Deadline) << message;
372373
}
373374
}
374375

@@ -469,7 +470,8 @@ namespace catapult { namespace chain {
469470

470471
TransactionData CreateTransactionData(size_t count, size_t start = 0) {
471472
TransactionData data;
472-
data.UtInfos = test::CreateTransactionInfos(count, [start](auto i) { return Timestamp((i + start) * (i + start)); });
473+
auto timeOffset = Default_Time.unwrap() + 1;
474+
data.UtInfos = test::CreateTransactionInfos(count, [timeOffset, start](auto i) { return Timestamp((timeOffset + i + start) * (timeOffset + i + start)); });
473475
data.Entities = test::ExtractEntities(data.UtInfos);
474476
data.Hashes = test::ExtractHashes(data.UtInfos);
475477
for (auto i = 0u; i < count; ++i)

0 commit comments

Comments
 (0)