@@ -188,11 +188,10 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
188188 request.params [3 ].getValStr (), request.params [4 ].getValStr (),
189189 govobj.GetDataAsPlainString (), govobj.GetHash ().ToString ());
190190
191+ bool fDIP0024IsActive = WITH_LOCK (cs_main, return VersionBitsTipState (Params ().GetConsensus (), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
191192 if (govobj.GetObjectType () == GOVERNANCE_OBJECT_PROPOSAL) {
192- LOCK (cs_main);
193- bool fAllowScript = (VersionBitsTipState (Params ().GetConsensus (), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
194193 // Note: we do not allow legacy format in RPC already, no need to reuse DEPLOYMENT_DIP0024
195- CProposalValidator validator (strDataHex, false , fAllowScript );
194+ CProposalValidator validator (strDataHex, false , fDIP0024IsActive );
196195 if (!validator.Validate ()) {
197196 throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid proposal data, error messages:" + validator.GetErrorMessages ());
198197 }
@@ -208,11 +207,9 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
208207
209208 LOCK (pwallet->cs_wallet );
210209
211- {
212- LOCK (cs_main);
213- std::string strError = " " ;
214- if (!govobj.IsValidLocally (strError, false ))
215- throw JSONRPCError (RPC_INTERNAL_ERROR, " Governance object is not valid - " + govobj.GetHash ().ToString () + " - " + strError);
210+ std::string strError = " " ;
211+ if (!govobj.IsValidLocally (strError, false )) {
212+ throw JSONRPCError (RPC_INTERNAL_ERROR, " Governance object is not valid - " + govobj.GetHash ().ToString () + " - " + strError);
216213 }
217214
218215 // If specified, spend this outpoint as the proposal fee
@@ -229,9 +226,7 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
229226
230227 CTransactionRef tx;
231228
232- bool fork_active = VersionBitsTipState (Params ().GetConsensus (), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE;
233-
234- if (!pwallet->GetBudgetSystemCollateralTX (tx, govobj.GetHash (), govobj.GetMinCollateralFee (fork_active), outpoint)) {
229+ if (!pwallet->GetBudgetSystemCollateralTX (tx, govobj.GetHash (), govobj.GetMinCollateralFee (fDIP0024IsActive ), outpoint)) {
235230 std::string err = " Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked." ;
236231 if (!request.params [6 ].isNull () && !request.params [7 ].isNull ()) {
237232 err += " Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee." ;
@@ -363,8 +358,7 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
363358 govobj.GetDataAsPlainString (), govobj.GetHash ().ToString (), txidFee.ToString ());
364359
365360 if (govobj.GetObjectType () == GOVERNANCE_OBJECT_PROPOSAL) {
366- LOCK (cs_main);
367- bool fAllowScript = (VersionBitsTipState (Params ().GetConsensus (), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
361+ bool fAllowScript = WITH_LOCK (cs_main, return VersionBitsTipState (Params ().GetConsensus (), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
368362 // Note: we do not allow legacy format in RPC already, no need to reuse DEPLOYMENT_DIP0024
369363 CProposalValidator validator (strDataHex, false , fAllowScript );
370364 if (!validator.Validate ()) {
@@ -389,18 +383,15 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
389383
390384 std::string strHash = govobj.GetHash ().ToString ();
391385
386+ if (g_txindex) {
387+ g_txindex->BlockUntilSyncedToCurrentChain ();
388+ }
389+
392390 std::string strError = " " ;
393391 bool fMissingConfirmations ;
394- {
395- if (g_txindex) {
396- g_txindex->BlockUntilSyncedToCurrentChain ();
397- }
398-
399- LOCK (cs_main);
400- if (!govobj.IsValidLocally (strError, fMissingConfirmations , true ) && !fMissingConfirmations ) {
401- LogPrintf (" gobject(submit) -- Object submission rejected because object is not valid - hash = %s, strError = %s\n " , strHash, strError);
402- throw JSONRPCError (RPC_INTERNAL_ERROR, " Governance object is not valid - " + strHash + " - " + strError);
403- }
392+ if (!govobj.IsValidLocally (strError, fMissingConfirmations , true ) && !fMissingConfirmations ) {
393+ LogPrintf (" gobject(submit) -- Object submission rejected because object is not valid - hash = %s, strError = %s\n " , strHash, strError);
394+ throw JSONRPCError (RPC_INTERNAL_ERROR, " Governance object is not valid - " + strHash + " - " + strError);
404395 }
405396
406397 // RELAY THIS OBJECT
@@ -724,7 +715,7 @@ static UniValue ListObjects(const std::string& strCachedSignal, const std::strin
724715 g_txindex->BlockUntilSyncedToCurrentChain ();
725716 }
726717
727- LOCK2 (cs_main, governance.cs );
718+ LOCK ( governance.cs );
728719
729720 std::vector<CGovernanceObject> objs = governance.GetAllNewerThan (nStartTime);
730721 governance.UpdateLastDiffTime (GetTime ());
@@ -867,7 +858,7 @@ static UniValue gobject_get(const JSONRPCRequest& request)
867858 }
868859
869860 // FIND THE GOVERNANCE OBJECT THE USER IS LOOKING FOR
870- LOCK2 (cs_main, governance.cs );
861+ LOCK ( governance.cs );
871862 CGovernanceObject* pGovObj = governance.FindGovernanceObject (hash);
872863
873864 if (pGovObj == nullptr ) {
@@ -1182,14 +1173,13 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request)
11821173 }
11831174
11841175 int nLastSuperblock = 0 , nNextSuperblock = 0 ;
1185- const auto * pindex = WITH_LOCK (cs_main, return ::ChainActive ().Tip () );
1186- int nBlockHeight = pindex-> nHeight ;
1176+ const auto * pindex = ::ChainActive ().Tip ();
1177+ bool fork_active = WITH_LOCK (cs_main, return VersionBitsState ( pindex, Params (). GetConsensus (), Consensus::DEPLOYMENT_DIP0024, versionbitscache) == ThresholdState::ACTIVE) ;
11871178
1188- CSuperblock::GetNearestSuperblocksHeights (nBlockHeight , nLastSuperblock, nNextSuperblock);
1179+ CSuperblock::GetNearestSuperblocksHeights (pindex-> nHeight , nLastSuperblock, nNextSuperblock);
11891180
11901181 UniValue obj (UniValue::VOBJ);
11911182 obj.pushKV (" governanceminquorum" , Params ().GetConsensus ().nGovernanceMinQuorum );
1192- bool fork_active = VersionBitsState (pindex, Params ().GetConsensus (), Consensus::DEPLOYMENT_DIP0024, versionbitscache) == ThresholdState::ACTIVE;
11931183 obj.pushKV (" proposalfee" , ValueFromAmount (fork_active ? GOVERNANCE_PROPOSAL_FEE_TX : GOVERNANCE_PROPOSAL_FEE_TX_OLD));
11941184 obj.pushKV (" superblockcycle" , Params ().GetConsensus ().nSuperblockCycle );
11951185 obj.pushKV (" lastsuperblock" , nLastSuperblock);
0 commit comments