Skip to content

Commit 228c740

Browse files
authored
Merge pull request #435 from proximax-storage/develop
Merge v1.9.4 into master
2 parents 77330e9 + f616dc0 commit 228c740

28 files changed

+251
-70
lines changed

plugins/txes/storage/src/model/ReplicatorsCleanupTransaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace catapult { namespace model {
2020
using TransactionType = ReplicatorsCleanupTransactionBody<THeader>;
2121

2222
public:
23-
DEFINE_TRANSACTION_CONSTANTS(Entity_Type_ReplicatorsCleanup, 1)
23+
DEFINE_TRANSACTION_CONSTANTS(Entity_Type_ReplicatorsCleanup, 2)
2424

2525
public:
2626
/// The number of replicators to remove.

plugins/txes/storage/src/observers/Observers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace catapult { namespace observers {
157157
DECLARE_OBSERVER(ReplicatorNodeBootKey, model::ReplicatorNodeBootKeyNotification<1>)();
158158

159159
/// Observes changes triggered by replicators cleanup notifications
160-
DECLARE_OBSERVER(ReplicatorsCleanup, model::ReplicatorsCleanupNotification<1>)(const std::unique_ptr<LiquidityProviderExchangeObserver>& pLiquidityProvider);
160+
DECLARE_OBSERVER(ReplicatorsCleanupV1, model::ReplicatorsCleanupNotification<1>)(const std::unique_ptr<LiquidityProviderExchangeObserver>& pLiquidityProvider);
161+
DECLARE_OBSERVER(ReplicatorsCleanupV2, model::ReplicatorsCleanupNotification<2>)();
161162

162163
}}

plugins/txes/storage/src/observers/ReplicatorsCleanupObserver.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99

1010
namespace catapult { namespace observers {
1111

12-
using Notification = model::ReplicatorsCleanupNotification<1>;
13-
14-
DECLARE_OBSERVER(ReplicatorsCleanup, Notification)(const std::unique_ptr<LiquidityProviderExchangeObserver>& pLiquidityProvider) {
15-
return MAKE_OBSERVER(ReplicatorsCleanup, Notification, ([&pLiquidityProvider](const Notification& notification, ObserverContext& context) {
12+
DECLARE_OBSERVER(ReplicatorsCleanupV1, model::ReplicatorsCleanupNotification<1>)(const std::unique_ptr<LiquidityProviderExchangeObserver>& pLiquidityProvider) {
13+
return MAKE_OBSERVER(ReplicatorsCleanupV1, model::ReplicatorsCleanupNotification<1>, ([&pLiquidityProvider](const model::ReplicatorsCleanupNotification<1>& notification, ObserverContext& context) {
1614
if (NotifyMode::Rollback == context.Mode)
17-
CATAPULT_THROW_RUNTIME_ERROR("Invalid observer mode ROLLBACK (ReplicatorsCleanup)");
15+
CATAPULT_THROW_RUNTIME_ERROR("Invalid observer mode ROLLBACK (ReplicatorsCleanupV1)");
1816

1917
auto& replicatorCache = context.Cache.template sub<cache::ReplicatorCache>();
2018
auto pReplicatorKey = notification.ReplicatorKeysPtr;
@@ -35,4 +33,19 @@ namespace catapult { namespace observers {
3533
}
3634
}))
3735
};
36+
37+
DECLARE_OBSERVER(ReplicatorsCleanupV2, model::ReplicatorsCleanupNotification<2>)() {
38+
return MAKE_OBSERVER(ReplicatorsCleanupV2, model::ReplicatorsCleanupNotification<2>, ([](const model::ReplicatorsCleanupNotification<2>& notification, ObserverContext& context) {
39+
if (NotifyMode::Rollback == context.Mode)
40+
CATAPULT_THROW_RUNTIME_ERROR("Invalid observer mode ROLLBACK (ReplicatorsCleanupV2)");
41+
42+
auto& replicatorCache = context.Cache.template sub<cache::ReplicatorCache>();
43+
auto pReplicatorKey = notification.ReplicatorKeysPtr;
44+
for (auto i = 0u; i < notification.ReplicatorCount; ++i, ++pReplicatorKey) {
45+
auto replicatorIter = replicatorCache.find(*pReplicatorKey);
46+
auto& replicatorEntry = replicatorIter.get();
47+
replicatorEntry.drives().clear();
48+
}
49+
}))
50+
};
3851
}}

plugins/txes/storage/src/plugins/ReplicatorsCleanupTransactionPlugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ namespace catapult { namespace plugins {
2323
break;
2424
}
2525

26+
case 2: {
27+
sub.notify(ReplicatorsCleanupNotification<2>(transaction.ReplicatorCount, transaction.ReplicatorKeysPtr()));
28+
break;
29+
}
30+
2631
default:
2732
CATAPULT_LOG(debug) << "invalid version of ReplicatorsCleanupTransaction: " << transaction.EntityVersion();
2833
}

plugins/txes/storage/src/plugins/StoragePlugin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ namespace catapult { namespace plugins {
227227
.add(validators::CreateServiceUnitTransferValidator())
228228
.add(validators::CreateOwnerManagementProhibitionValidator())
229229
.add(validators::CreateReplicatorNodeBootKeyValidator())
230-
.add(validators::CreateReplicatorsCleanupValidator());
230+
.add(validators::CreateReplicatorsCleanupV1Validator())
231+
.add(validators::CreateReplicatorsCleanupV2Validator());
231232
});
232233

233234
const auto& storageUpdatesListeners = manager.storageUpdatesListeners();
@@ -261,7 +262,8 @@ namespace catapult { namespace plugins {
261262
.add(observers::CreatePeriodicDownloadChannelPaymentObserver(pStorageState))
262263
.add(observers::CreateOwnerManagementProhibitionObserver())
263264
.add(observers::CreateReplicatorNodeBootKeyObserver())
264-
.add(observers::CreateReplicatorsCleanupObserver(liquidityProviderObserver));
265+
.add(observers::CreateReplicatorsCleanupV1Observer(liquidityProviderObserver))
266+
.add(observers::CreateReplicatorsCleanupV2Observer());
265267
});
266268
}
267269
}}

plugins/txes/storage/src/validators/ReplicatorsCleanupValidator.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace catapult { namespace validators {
1111

12-
using Notification = model::ReplicatorsCleanupNotification<1>;
13-
14-
DEFINE_STATEFUL_VALIDATOR(ReplicatorsCleanup, ([](const Notification& notification, const ValidatorContext& context) {
12+
DEFINE_STATEFUL_VALIDATOR_WITH_TYPE(ReplicatorsCleanupV1, model::ReplicatorsCleanupNotification<1>, ([](const model::ReplicatorsCleanupNotification<1>& notification, const ValidatorContext& context) {
1513
if (!notification.ReplicatorCount)
1614
return Failure_Storage_No_Replicators_To_Remove;
1715

@@ -29,4 +27,20 @@ namespace catapult { namespace validators {
2927

3028
return ValidationResult::Success;
3129
}));
30+
31+
DEFINE_STATEFUL_VALIDATOR_WITH_TYPE(ReplicatorsCleanupV2, model::ReplicatorsCleanupNotification<2>, ([](const model::ReplicatorsCleanupNotification<2>& notification, const ValidatorContext& context) {
32+
if (!notification.ReplicatorCount)
33+
return Failure_Storage_No_Replicators_To_Remove;
34+
35+
const auto& cache = context.Cache.sub<cache::ReplicatorCache>();
36+
auto pReplicatorKey = notification.ReplicatorKeysPtr;
37+
for (auto i = 0u; i < notification.ReplicatorCount; ++i, ++pReplicatorKey) {
38+
auto iter = cache.find(*pReplicatorKey);
39+
auto pEntry = iter.tryGet();
40+
if (!pEntry)
41+
return Failure_Storage_Replicator_Not_Found;
42+
}
43+
44+
return ValidationResult::Success;
45+
}));
3246
}}

plugins/txes/storage/src/validators/Validators.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,9 @@ namespace catapult { namespace validators {
177177
/// A validator implementation that applies to replicators cleanup notifications and validates that:
178178
/// - replicators are registered
179179
/// - replicators are not bound with boot keys
180-
DECLARE_STATEFUL_VALIDATOR(ReplicatorsCleanup, model::ReplicatorsCleanupNotification<1>)();
180+
DECLARE_STATEFUL_VALIDATOR(ReplicatorsCleanupV1, model::ReplicatorsCleanupNotification<1>)();
181+
182+
/// A validator implementation that applies to replicators cleanup notifications and validates that:
183+
/// - replicators are registered
184+
DECLARE_STATEFUL_VALIDATOR(ReplicatorsCleanupV2, model::ReplicatorsCleanupNotification<2>)();
181185
}}

plugins/txes/storage/tests/model/ReplicatorsCleanupTransactionTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace catapult { namespace model {
3333
void AssertTransactionHasExpectedProperties() {
3434
// Assert:
3535
EXPECT_EQ(Entity_Type_ReplicatorsCleanup, T::Entity_Type);
36-
EXPECT_EQ(1u, T::Current_Version);
36+
EXPECT_EQ(2u, T::Current_Version);
3737
}
3838
}
3939

plugins/txes/storage/tests/observers/ReplicatorsCleanupObserverTests.cpp

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ namespace catapult { namespace observers {
1515

1616
const std::unique_ptr<observers::LiquidityProviderExchangeObserver> Liquidity_Provider_Ptr = std::make_unique<test::LiquidityProviderExchangeObserverImpl>();
1717

18-
DEFINE_COMMON_OBSERVER_TESTS(ReplicatorsCleanup, Liquidity_Provider_Ptr)
18+
DEFINE_COMMON_OBSERVER_TESTS(ReplicatorsCleanupV1, Liquidity_Provider_Ptr)
1919

2020
namespace {
2121
using ObserverTestContext = test::ObserverTestContextT<test::StorageCacheFactory>;
22-
using Notification = model::ReplicatorsCleanupNotification<1>;
2322

24-
void RunTest(NotifyMode mode) {
23+
void RunV1Test(NotifyMode mode) {
2524
// Arrange:
2625
ObserverTestContext context(mode, Height(1));
2726
std::vector<Key> replicatorKeys{
@@ -31,11 +30,11 @@ namespace catapult { namespace observers {
3130
Key({ 7 }),
3231
Key({ 9 }),
3332
};
34-
Notification notification(replicatorKeys.size(), replicatorKeys.data());
33+
model::ReplicatorsCleanupNotification<1> notification(replicatorKeys.size(), replicatorKeys.data());
3534
auto& cache = context.cache().sub<cache::ReplicatorCache>();
3635
for (uint8_t i = 1; i <= 10; ++i)
3736
cache.insert(state::ReplicatorEntry(Key({ i })));
38-
auto pObserver = CreateReplicatorsCleanupObserver(Liquidity_Provider_Ptr);
37+
auto pObserver = CreateReplicatorsCleanupV1Observer(Liquidity_Provider_Ptr);
3938

4039
// Sanity
4140
for (uint8_t i = 1; i <= 10; ++i)
@@ -53,13 +52,62 @@ namespace catapult { namespace observers {
5352
}
5453
}
5554

56-
TEST(TEST_CLASS, ReplicatorsCleanup_Commit) {
55+
TEST(TEST_CLASS, ReplicatorsCleanupV1_Commit) {
5756
// Assert:
58-
RunTest(NotifyMode::Commit);
57+
RunV1Test(NotifyMode::Commit);
5958
}
6059

61-
TEST(TEST_CLASS, ReplicatorsCleanup_Rollback) {
60+
TEST(TEST_CLASS, ReplicatorsCleanupV1_Rollback) {
6261
// Assert
63-
EXPECT_THROW(RunTest(NotifyMode::Rollback), catapult_runtime_error);
62+
EXPECT_THROW(RunV1Test(NotifyMode::Rollback), catapult_runtime_error);
63+
}
64+
65+
DEFINE_COMMON_OBSERVER_TESTS(ReplicatorsCleanupV2)
66+
67+
namespace {
68+
using ObserverTestContext = test::ObserverTestContextT<test::StorageCacheFactory>;
69+
70+
void RunV2Test(NotifyMode mode) {
71+
// Arrange:
72+
ObserverTestContext context(mode, Height(1));
73+
std::vector<Key> replicatorKeys{
74+
Key({ 1 }),
75+
Key({ 3 }),
76+
Key({ 5 }),
77+
Key({ 7 }),
78+
Key({ 9 }),
79+
};
80+
model::ReplicatorsCleanupNotification<2> notification(replicatorKeys.size(), replicatorKeys.data());
81+
auto& cache = context.cache().sub<cache::ReplicatorCache>();
82+
for (uint8_t i = 1; i <= 10; ++i) {
83+
auto entry = state::ReplicatorEntry(Key({ i }));
84+
for (uint8_t j = 1; j <= 5; ++j)
85+
entry.drives().emplace(Key({ static_cast<uint8_t>(10 + j) }), state::DriveInfo{});
86+
cache.insert(entry);
87+
}
88+
auto pObserver = CreateReplicatorsCleanupV2Observer();
89+
90+
// Act:
91+
test::ObserveNotification(*pObserver, notification, context);
92+
93+
// Assert: check the cache
94+
for (uint8_t i = 1; i <= 10; ++i) {
95+
auto replicatorKey = Key({ i });
96+
auto iter = cache.find(replicatorKey);
97+
const auto& entry = iter.get();
98+
auto driveCount = (1 == i % 2) ? 0u : 5u;
99+
ASSERT_EQ(driveCount, entry.drives().size());
100+
}
101+
}
102+
}
103+
104+
TEST(TEST_CLASS, ReplicatorsCleanupV2_Commit) {
105+
// Assert:
106+
RunV2Test(NotifyMode::Commit);
107+
}
108+
109+
TEST(TEST_CLASS, ReplicatorsCleanupV2_Rollback) {
110+
// Assert
111+
EXPECT_THROW(RunV2Test(NotifyMode::Rollback), catapult_runtime_error);
64112
}
65113
}}

plugins/txes/storage/tests/plugins/DataModificationApprovalTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/DataModificationCancelTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/DataModificationTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/DownloadTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/DriveClosureTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/PrepareBcDriveTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/ReplicatorOffboardingTransactionsPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/ReplicatorOnboardingTransactionPluginTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/plugins/ReplicatorsCleanupTransactionPluginTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2024 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/
@@ -18,7 +18,7 @@ namespace catapult { namespace plugins {
1818
#define TEST_CLASS ReplicatorsCleanupTransactionPluginTests
1919

2020
namespace {
21-
DEFINE_TRANSACTION_PLUGIN_TEST_TRAITS(ReplicatorsCleanup, 1, 1,)
21+
DEFINE_TRANSACTION_PLUGIN_TEST_TRAITS(ReplicatorsCleanup, 2, 2,)
2222

2323
template<typename TTraits>
2424
auto CreateTransaction(uint16_t replicatorCount) {
@@ -71,7 +71,7 @@ namespace catapult { namespace plugins {
7171

7272
// Assert:
7373
ASSERT_EQ(1u, sub.numNotifications());
74-
EXPECT_EQ(Storage_ReplicatorsCleanup_v1_Notification, sub.notificationTypes()[0]);
74+
EXPECT_EQ(Storage_ReplicatorsCleanup_v2_Notification, sub.notificationTypes()[0]);
7575
}
7676

7777
// endregion
@@ -80,7 +80,7 @@ namespace catapult { namespace plugins {
8080

8181
PLUGIN_TEST(CanPublishReplicatorsCleanupNotification) {
8282
// Arrange:
83-
mocks::MockTypedNotificationSubscriber<ReplicatorsCleanupNotification<1>> sub;
83+
mocks::MockTypedNotificationSubscriber<ReplicatorsCleanupNotification<2>> sub;
8484
auto pPlugin = TTraits::CreatePlugin();
8585

8686
auto pTransaction = CreateTransaction<TTraits>(10);

plugins/txes/storage/tests/plugins/StoragePluginTests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ namespace catapult { namespace plugins {
109109
"EndDriveVerificationValidator",
110110
"OwnerManagementProhibitionValidator",
111111
"ReplicatorNodeBootKeyValidator",
112-
"ReplicatorsCleanupValidator",
112+
"ReplicatorsCleanupV1Validator",
113113
"ReplicatorOnboardingV2Validator",
114+
"ReplicatorsCleanupV2Validator",
114115
};
115116
}
116117

@@ -142,8 +143,9 @@ namespace catapult { namespace plugins {
142143
"EndDriveVerificationObserver",
143144
"OwnerManagementProhibitionObserver",
144145
"ReplicatorNodeBootKeyObserver",
145-
"ReplicatorsCleanupObserver",
146+
"ReplicatorsCleanupV1Observer",
146147
"ReplicatorOnboardingV2Observer",
148+
"ReplicatorsCleanupV2Observer",
147149
};
148150
}
149151

plugins/txes/storage/tests/test/StorageTestUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

plugins/txes/storage/tests/test/StorageTestUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
*** Copyright 2019 ProximaX Limited. All rights reserved.
2+
*** Copyright 2021 ProximaX Limited. All rights reserved.
33
*** Use of this source code is governed by the Apache 2.0
44
*** license that can be found in the LICENSE file.
55
**/

0 commit comments

Comments
 (0)