Skip to content

Commit b25e4fd

Browse files
committed
refactor: adapt ProTx logic to DeploymentActive{At,After}
1 parent 07ea998 commit b25e4fd

File tree

9 files changed

+122
-84
lines changed

9 files changed

+122
-84
lines changed

src/evo/deterministicmns.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,35 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <evo/deterministicmns.h>
6+
67
#include <evo/dmn_types.h>
78
#include <evo/dmnstate.h>
89
#include <evo/evodb.h>
910
#include <evo/providertx.h>
1011
#include <evo/simplifiedmns.h>
1112
#include <evo/specialtx.h>
13+
#include <masternode/meta.h>
14+
#include <messagesigner.h>
15+
#include <stats/client.h>
16+
#include <util/irange.h>
17+
#include <util/pointer.h>
1218

1319
#include <chainparams.h>
1420
#include <coins.h>
1521
#include <consensus/validation.h>
1622
#include <deploymentstatus.h>
1723
#include <index/txindex.h>
18-
#include <masternode/meta.h>
19-
#include <messagesigner.h>
2024
#include <node/blockstorage.h>
2125
#include <script/standard.h>
22-
#include <stats/client.h>
2326
#include <uint256.h>
24-
#include <univalue.h>
25-
#include <util/irange.h>
26-
#include <util/pointer.h>
27+
#include <validation.h>
2728

2829
#include <functional>
2930
#include <optional>
3031
#include <memory>
3132

33+
#include <univalue.h>
34+
3235
static const std::string DB_LIST_SNAPSHOT = "dmn_S3";
3336
static const std::string DB_LIST_DIFF = "dmn_D4"; // Bumped for nVersion-first format
3437
static const std::string DB_LIST_DIFF_LEGACY = "dmn_D3"; // Legacy format key
@@ -1035,8 +1038,9 @@ static bool CheckHashSig(const ProTx& proTx, const CBLSPublicKey& pubKey, TxVali
10351038
return true;
10361039
}
10371040

1038-
template<typename ProTx>
1039-
static std::optional<ProTx> GetValidatedPayload(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state)
1041+
template <typename ProTx>
1042+
static std::optional<ProTx> GetValidatedPayload(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
1043+
const ChainstateManager& chainman, TxValidationState& state)
10401044
{
10411045
if (tx.nType != ProTx::SPECIALTX_TYPE) {
10421046
state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-type");
@@ -1048,7 +1052,7 @@ static std::optional<ProTx> GetValidatedPayload(const CTransaction& tx, gsl::not
10481052
state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-payload");
10491053
return std::nullopt;
10501054
}
1051-
if (!opt_ptx->IsTriviallyValid(pindexPrev, state)) {
1055+
if (!opt_ptx->IsTriviallyValid(pindexPrev, chainman, state)) {
10521056
// pass the state returned by the function above
10531057
return std::nullopt;
10541058
}
@@ -1065,9 +1069,10 @@ static std::optional<ProTx> GetValidatedPayload(const CTransaction& tx, gsl::not
10651069
* @returns true if version change is valid or DEPLOYMENT_V24 is not active
10661070
*/
10671071
bool IsVersionChangeValid(gsl::not_null<const CBlockIndex*> pindexPrev, const uint16_t tx_type,
1068-
const uint16_t state_version, const uint16_t tx_version, TxValidationState& state)
1072+
const uint16_t state_version, const uint16_t tx_version, const ChainstateManager& chainman,
1073+
TxValidationState& state)
10691074
{
1070-
if (!DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V24)) {
1075+
if (!DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_V24)) {
10711076
// New restrictions only apply after v24 deployment
10721077
return true;
10731078
}
@@ -1090,15 +1095,17 @@ bool IsVersionChangeValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ui
10901095
return true;
10911096
}
10921097

1093-
bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs)
1098+
bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
1099+
CDeterministicMNManager& dmnman, const CCoinsViewCache& view, const ChainstateManager& chainman,
1100+
TxValidationState& state, bool check_sigs)
10941101
{
1095-
const auto opt_ptx = GetValidatedPayload<CProRegTx>(tx, pindexPrev, state);
1102+
const auto opt_ptx = GetValidatedPayload<CProRegTx>(tx, pindexPrev, chainman, state);
10961103
if (!opt_ptx) {
10971104
// pass the state returned by the function above
10981105
return false;
10991106
}
11001107

1101-
const bool is_v24_active{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_V24)};
1108+
const bool is_v24_active{DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_V24)};
11021109

11031110
// No longer allow legacy scheme masternode registration
11041111
if (is_v24_active && opt_ptx->nVersion < ProTxVersion::BasicBLS) {
@@ -1223,9 +1230,10 @@ bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl:
12231230
return true;
12241231
}
12251232

1226-
bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs)
1233+
bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, CDeterministicMNManager& dmnman,
1234+
const ChainstateManager& chainman, TxValidationState& state, bool check_sigs)
12271235
{
1228-
const auto opt_ptx = GetValidatedPayload<CProUpServTx>(tx, pindexPrev, state);
1236+
const auto opt_ptx = GetValidatedPayload<CProUpServTx>(tx, pindexPrev, chainman, state);
12291237
if (!opt_ptx) {
12301238
// pass the state returned by the function above
12311239
return false;
@@ -1248,7 +1256,7 @@ bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, g
12481256
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
12491257
}
12501258

1251-
if (!IsVersionChangeValid(pindexPrev, tx.nType, dmn->pdmnState->nVersion, opt_ptx->nVersion, state)) {
1259+
if (!IsVersionChangeValid(pindexPrev, tx.nType, dmn->pdmnState->nVersion, opt_ptx->nVersion, chainman, state)) {
12521260
// pass the state returned by the function above
12531261
return false;
12541262
}
@@ -1299,9 +1307,11 @@ bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, g
12991307
return true;
13001308
}
13011309

1302-
bool CheckProUpRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs)
1310+
bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
1311+
CDeterministicMNManager& dmnman, const CCoinsViewCache& view, const ChainstateManager& chainman,
1312+
TxValidationState& state, bool check_sigs)
13031313
{
1304-
const auto opt_ptx = GetValidatedPayload<CProUpRegTx>(tx, pindexPrev, state);
1314+
const auto opt_ptx = GetValidatedPayload<CProUpRegTx>(tx, pindexPrev, chainman, state);
13051315
if (!opt_ptx) {
13061316
// pass the state returned by the function above
13071317
return false;
@@ -1319,7 +1329,7 @@ bool CheckProUpRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gs
13191329
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
13201330
}
13211331

1322-
if (!IsVersionChangeValid(pindexPrev, tx.nType, dmn->pdmnState->nVersion, opt_ptx->nVersion, state)) {
1332+
if (!IsVersionChangeValid(pindexPrev, tx.nType, dmn->pdmnState->nVersion, opt_ptx->nVersion, chainman, state)) {
13231333
// pass the state returned by the function above
13241334
return false;
13251335
}
@@ -1369,9 +1379,10 @@ bool CheckProUpRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gs
13691379
return true;
13701380
}
13711381

1372-
bool CheckProUpRevTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs)
1382+
bool CheckProUpRevTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, CDeterministicMNManager& dmnman,
1383+
const ChainstateManager& chainman, TxValidationState& state, bool check_sigs)
13731384
{
1374-
const auto opt_ptx = GetValidatedPayload<CProUpRevTx>(tx, pindexPrev, state);
1385+
const auto opt_ptx = GetValidatedPayload<CProUpRevTx>(tx, pindexPrev, chainman, state);
13751386
if (!opt_ptx) {
13761387
// pass the state returned by the function above
13771388
return false;
@@ -1383,7 +1394,7 @@ bool CheckProUpRevTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gs
13831394
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-hash");
13841395
}
13851396

1386-
if (!IsVersionChangeValid(pindexPrev, tx.nType, dmn->pdmnState->nVersion, opt_ptx->nVersion, state)) {
1397+
if (!IsVersionChangeValid(pindexPrev, tx.nType, dmn->pdmnState->nVersion, opt_ptx->nVersion, chainman, state)) {
13871398
// pass the state returned by the function above
13881399
return false;
13891400
}

src/evo/deterministicmns.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
class CBlock;
3131
class CBlockIndex;
3232
class CCoinsViewCache;
33+
class ChainstateManager;
3334
class CEvoDB;
3435
class CSimplifiedMNList;
3536
class CSimplifiedMNListEntry;
@@ -768,9 +769,15 @@ class CDeterministicMNManager
768769
RecalcDiffsResult& result) EXCLUSIVE_LOCKS_REQUIRED(!cs);
769770
};
770771

771-
bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs);
772-
bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs);
773-
bool CheckProUpRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, const CCoinsViewCache& view, bool check_sigs);
774-
bool CheckProUpRevTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state, bool check_sigs);
772+
bool CheckProRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
773+
CDeterministicMNManager& dmnman, const CCoinsViewCache& view, const ChainstateManager& chainman,
774+
TxValidationState& state, bool check_sigs);
775+
bool CheckProUpServTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, CDeterministicMNManager& dmnman,
776+
const ChainstateManager& chainman, TxValidationState& state, bool check_sigs);
777+
bool CheckProUpRegTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev,
778+
CDeterministicMNManager& dmnman, const CCoinsViewCache& view, const ChainstateManager& chainman,
779+
TxValidationState& state, bool check_sigs);
780+
bool CheckProUpRevTx(const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, CDeterministicMNManager& dmnman,
781+
const ChainstateManager& chainman, TxValidationState& state, bool check_sigs);
775782

776783
#endif // BITCOIN_EVO_DETERMINISTICMNS_H

src/evo/providertx.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,42 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <evo/dmn_types.h>
65
#include <evo/providertx.h>
76

7+
#include <evo/dmn_types.h>
8+
89
#include <chainparams.h>
910
#include <consensus/validation.h>
1011
#include <deploymentstatus.h>
1112
#include <hash.h>
1213
#include <script/standard.h>
1314
#include <tinyformat.h>
1415
#include <util/underlying.h>
16+
#include <validation.h>
1517

1618
namespace ProTxVersion {
1719
template <typename T>
1820
[[nodiscard]] uint16_t GetMaxFromDeployment(gsl::not_null<const CBlockIndex*> pindexPrev,
19-
std::optional<bool> is_basic_override)
21+
const ChainstateManager& chainman, std::optional<bool> is_basic_override)
2022
{
2123
constexpr bool is_extaddr_eligible{std::is_same_v<std::decay_t<T>, CProRegTx> || std::is_same_v<std::decay_t<T>, CProUpServTx>};
22-
return ProTxVersion::GetMax(is_basic_override ? *is_basic_override
23-
: DeploymentActiveAfter(pindexPrev, Params().GetConsensus(),
24-
Consensus::DEPLOYMENT_V19),
25-
is_extaddr_eligible ? DeploymentActiveAfter(pindexPrev, Params().GetConsensus(),
26-
Consensus::DEPLOYMENT_V24)
27-
: false);
24+
return ProTxVersion::GetMax(
25+
is_basic_override ? *is_basic_override
26+
: DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), Consensus::DEPLOYMENT_V19),
27+
is_extaddr_eligible ? DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_V24) : false);
2828
}
29-
template uint16_t GetMaxFromDeployment<CProRegTx>(gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> is_basic_override);
30-
template uint16_t GetMaxFromDeployment<CProUpServTx>(gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> is_basic_override);
31-
template uint16_t GetMaxFromDeployment<CProUpRegTx>(gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> is_basic_override);
32-
template uint16_t GetMaxFromDeployment<CProUpRevTx>(gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> is_basic_override);
29+
template uint16_t GetMaxFromDeployment<CProRegTx>(gsl::not_null<const CBlockIndex*> pindexPrev,
30+
const ChainstateManager& chainman,
31+
std::optional<bool> is_basic_override);
32+
template uint16_t GetMaxFromDeployment<CProUpServTx>(gsl::not_null<const CBlockIndex*> pindexPrev,
33+
const ChainstateManager& chainman,
34+
std::optional<bool> is_basic_override);
35+
template uint16_t GetMaxFromDeployment<CProUpRegTx>(gsl::not_null<const CBlockIndex*> pindexPrev,
36+
const ChainstateManager& chainman,
37+
std::optional<bool> is_basic_override);
38+
template uint16_t GetMaxFromDeployment<CProUpRevTx>(gsl::not_null<const CBlockIndex*> pindexPrev,
39+
const ChainstateManager& chainman,
40+
std::optional<bool> is_basic_override);
3341
} // namespace ProTxVersion
3442

3543
template <typename ProTx>
@@ -56,9 +64,10 @@ bool IsNetInfoTriviallyValid(const ProTx& proTx, TxValidationState& state)
5664
return true;
5765
}
5866

59-
bool CProRegTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const
67+
bool CProRegTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
68+
TxValidationState& state) const
6069
{
61-
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev)) {
70+
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev, chainman)) {
6271
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-version");
6372
}
6473
if (nVersion < ProTxVersion::BasicBLS && nType == MnType::Evo) {
@@ -153,9 +162,10 @@ std::string CProRegTx::ToString() const
153162
: strprintf(", platformP2PPort=%d, platformHTTPPort=%d", platformP2PPort, platformHTTPPort)));
154163
}
155164

156-
bool CProUpServTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const
165+
bool CProUpServTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
166+
TxValidationState& state) const
157167
{
158-
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev)) {
168+
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev, chainman)) {
159169
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-version");
160170
}
161171
if (nVersion < ProTxVersion::BasicBLS && nType == MnType::Evo) {
@@ -197,9 +207,10 @@ std::string CProUpServTx::ToString() const
197207
: strprintf(", platformP2PPort=%d, platformHTTPPort=%d", platformP2PPort, platformHTTPPort)));
198208
}
199209

200-
bool CProUpRegTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const
210+
bool CProUpRegTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
211+
TxValidationState& state) const
201212
{
202-
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev)) {
213+
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev, chainman)) {
203214
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-version");
204215
}
205216
if (nMode != 0) {
@@ -230,9 +241,10 @@ std::string CProUpRegTx::ToString() const
230241
nVersion, proTxHash.ToString(), pubKeyOperator.ToString(), EncodeDestination(PKHash(keyIDVoting)), payee);
231242
}
232243

233-
bool CProUpRevTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const
244+
bool CProUpRevTx::IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
245+
TxValidationState& state) const
234246
{
235-
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev)) {
247+
if (nVersion == 0 || nVersion > ProTxVersion::GetMaxFromDeployment<decltype(*this)>(pindexPrev, chainman)) {
236248
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-protx-version");
237249
}
238250

src/evo/providertx.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <gsl/pointers.h>
2222

2323
class CBlockIndex;
24+
class ChainstateManager;
2425
class TxValidationState;
2526
struct RPCResult;
2627

@@ -52,7 +53,7 @@ enum : uint16_t {
5253
* TODO: Resolve this oddity. Consider deprecating legacy BLS-only RPCs so we can remove them eventually.
5354
*/
5455
template <typename T>
55-
[[nodiscard]] uint16_t GetMaxFromDeployment(gsl::not_null<const CBlockIndex*> pindexPrev,
56+
[[nodiscard]] uint16_t GetMaxFromDeployment(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
5657
std::optional<bool> is_basic_override = std::nullopt);
5758
} // namespace ProTxVersion
5859

@@ -124,7 +125,8 @@ class CProRegTx
124125
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
125126
[[nodiscard]] UniValue ToJson() const;
126127

127-
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const;
128+
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
129+
TxValidationState& state) const;
128130
};
129131

130132
class CProUpServTx
@@ -185,7 +187,8 @@ class CProUpServTx
185187
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
186188
[[nodiscard]] UniValue ToJson() const;
187189

188-
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const;
190+
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
191+
TxValidationState& state) const;
189192
};
190193

191194
class CProUpRegTx
@@ -232,7 +235,8 @@ class CProUpRegTx
232235
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
233236
[[nodiscard]] UniValue ToJson() const;
234237

235-
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const;
238+
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
239+
TxValidationState& state) const;
236240
};
237241

238242
class CProUpRevTx
@@ -282,7 +286,8 @@ class CProUpRevTx
282286
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
283287
[[nodiscard]] UniValue ToJson() const;
284288

285-
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, TxValidationState& state) const;
289+
bool IsTriviallyValid(gsl::not_null<const CBlockIndex*> pindexPrev, const ChainstateManager& chainman,
290+
TxValidationState& state) const;
286291
};
287292

288293
template <typename ProTx>

0 commit comments

Comments
 (0)