Skip to content

Commit dd859f8

Browse files
authored
Add transfer script size RIP
2 parents 9232f01 + e3e9acd commit dd859f8

File tree

11 files changed

+93
-23
lines changed

11 files changed

+93
-23
lines changed

src/assets/assets.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,23 @@ bool TransferAssetFromScript(const CScript& scriptPubKey, CAssetTransfer& assetT
674674
strAddress = EncodeDestination(destination);
675675

676676
std::vector<unsigned char> vchTransferAsset;
677-
vchTransferAsset.insert(vchTransferAsset.end(), scriptPubKey.begin() + 31, scriptPubKey.end());
677+
678+
if (AreTransferScriptsSizeDeployed()) {
679+
// Before kawpow activation we used the hardcoded 31 to find the data
680+
// This created a bug where large transfers scripts would fail to serialize.
681+
// This fixes that issue (https://github.com/RavenProject/Ravencoin/issues/752)
682+
// TODO, after the kawpow fork goes active, we should be able to remove this if/else statement and just use this line.
683+
vchTransferAsset.insert(vchTransferAsset.end(), scriptPubKey.begin() + nStartingIndex, scriptPubKey.end());
684+
} else {
685+
vchTransferAsset.insert(vchTransferAsset.end(), scriptPubKey.begin() + 31, scriptPubKey.end());
686+
}
687+
678688
CDataStream ssAsset(vchTransferAsset, SER_NETWORK, PROTOCOL_VERSION);
679689

680690
try {
681691
ssAsset >> assetTransfer;
682692
} catch(std::exception& e) {
683-
std::cout << "Failed to get the transfer asset from the stream: " << e.what() << std::endl;
693+
error("Failed to get the transfer asset from the stream: %s", e.what());
684694
return false;
685695
}
686696

@@ -705,7 +715,7 @@ bool AssetFromScript(const CScript& scriptPubKey, CNewAsset& assetNew, std::stri
705715
try {
706716
ssAsset >> assetNew;
707717
} catch(std::exception& e) {
708-
std::cout << "Failed to get the asset from the stream: " << e.what() << std::endl;
718+
error("Failed to get the asset from the stream: %s", e.what());
709719
return false;
710720
}
711721

@@ -730,7 +740,7 @@ bool MsgChannelAssetFromScript(const CScript& scriptPubKey, CNewAsset& assetNew,
730740
try {
731741
ssAsset >> assetNew;
732742
} catch(std::exception& e) {
733-
std::cout << "Failed to get the msg channel asset from the stream: " << e.what() << std::endl;
743+
error("Failed to get the msg channel asset from the stream: %s", e.what());
734744
return false;
735745
}
736746

@@ -755,7 +765,7 @@ bool QualifierAssetFromScript(const CScript& scriptPubKey, CNewAsset& assetNew,
755765
try {
756766
ssAsset >> assetNew;
757767
} catch(std::exception& e) {
758-
std::cout << "Failed to get the qualifier asset from the stream: " << e.what() << std::endl;
768+
error("Failed to get the qualifier asset from the stream: %s", e.what());
759769
return false;
760770
}
761771

@@ -780,7 +790,7 @@ bool RestrictedAssetFromScript(const CScript& scriptPubKey, CNewAsset& assetNew,
780790
try {
781791
ssAsset >> assetNew;
782792
} catch(std::exception& e) {
783-
std::cout << "Failed to get the restricted asset from the stream: " << e.what() << std::endl;
793+
error("Failed to get the restricted asset from the stream: %s", e.what());
784794
return false;
785795
}
786796

@@ -805,7 +815,7 @@ bool OwnerAssetFromScript(const CScript& scriptPubKey, std::string& assetName, s
805815
try {
806816
ssOwner >> assetName;
807817
} catch(std::exception& e) {
808-
std::cout << "Failed to get the owner asset from the stream: " << e.what() << std::endl;
818+
error("Failed to get the owner asset from the stream: %s", e.what());
809819
return false;
810820
}
811821

@@ -830,7 +840,7 @@ bool ReissueAssetFromScript(const CScript& scriptPubKey, CReissueAsset& reissue,
830840
try {
831841
ssReissue >> reissue;
832842
} catch(std::exception& e) {
833-
std::cout << "Failed to get the reissue asset from the stream: " << e.what() << std::endl;
843+
error("Failed to get the reissue asset from the stream: %s", e.what());
834844
return false;
835845
}
836846

@@ -855,7 +865,7 @@ bool AssetNullDataFromScript(const CScript& scriptPubKey, CNullAssetTxData& asse
855865
try {
856866
ssData >> assetData;
857867
} catch(std::exception& e) {
858-
std::cout << "Failed to get the asset tx data from the stream: " << e.what() << std::endl;
868+
error("Failed to get the null asset tx data from the stream: %s", e.what());
859869
return false;
860870
}
861871

@@ -875,7 +885,7 @@ bool GlobalAssetNullDataFromScript(const CScript& scriptPubKey, CNullAssetTxData
875885
try {
876886
ssData >> assetData;
877887
} catch(std::exception& e) {
878-
std::cout << "Failed to get the global restriction asset tx data from the stream: " << e.what() << std::endl;
888+
error("Failed to get the global restriction asset tx data from the stream: %s", e.what());
879889
return false;
880890
}
881891

@@ -895,7 +905,7 @@ bool AssetNullVerifierDataFromScript(const CScript& scriptPubKey, CNullAssetTxVe
895905
try {
896906
ssData >> verifierData;
897907
} catch(std::exception& e) {
898-
std::cout << "Failed to get the verifier string from the stream: " << e.what() << std::endl;
908+
error("Failed to get the verifier string from the stream: %s", e.what());
899909
return false;
900910
}
901911

src/chainparams.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ class CMainParams : public CChainParams {
146146
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nTimeout = 1610542800; // UTC: Wed Jan 13 2021 13:00:00
147147
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nOverrideRuleChangeActivationThreshold = 1714; // Approx 85% of 2016
148148
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nOverrideMinerConfirmationWindow = 2016;
149+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].bit = 8;
150+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nStartTime = 1588788000; // UTC: Wed May 06 2020 18:00:00
151+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nTimeout = 1620324000; // UTC: Thu May 06 2021 18:00:00
152+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideRuleChangeActivationThreshold = 1714; // Approx 85% of 2016
153+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideMinerConfirmationWindow = 2016;
149154

150155
// The best chain should have at least this much work
151156
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000001445cb2bc4398ebded"); // Block 1040000
@@ -248,7 +253,7 @@ class CMainParams : public CChainParams {
248253
nMessagingActivationBlock = 0; // Messaging activated block height // TODO after messaging goes active on mainnet
249254
nRestrictedActivationBlock = 0; // Restricted activated block height // TODO after restricted goes active on mainnet
250255

251-
nKAAAWWWPOWActivationTime = 4294967295;
256+
nKAAAWWWPOWActivationTime = 1588788000; // UTC: Wed May 06 2020 18:00:00
252257
nKAWPOWActivationTime = nKAAAWWWPOWActivationTime;
253258
/** RVN End **/
254259
}
@@ -291,6 +296,11 @@ class CTestNetParams : public CChainParams {
291296
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nTimeout = 1577257200; // UTC: Wed Dec 25 2019 07:00:00
292297
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nOverrideRuleChangeActivationThreshold = 1310;
293298
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nOverrideMinerConfirmationWindow = 2016;
299+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].bit = 8;
300+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nStartTime = 1586973600; // UTC: Wed Apr 15 2020 18:00:00
301+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nTimeout = 1618509600; // UTC: Thu Apr 15 2021 18:00:00
302+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideRuleChangeActivationThreshold = 1310;
303+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideMinerConfirmationWindow = 2016;
294304

295305
// The best chain should have at least this much work.
296306
consensus.nMinimumChainWork = uint256S("0x00");
@@ -495,6 +505,11 @@ class CRegTestParams : public CChainParams {
495505
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nTimeout = 999999999999ULL; // UTC: Wed Dec 25 2019 07:00:00
496506
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nOverrideRuleChangeActivationThreshold = 108;
497507
consensus.vDeployments[Consensus::DEPLOYMENT_MSG_REST_ASSETS].nOverrideMinerConfirmationWindow = 144;
508+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].bit = 8;
509+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nStartTime = 0;
510+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nTimeout = 999999999999ULL;
511+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideRuleChangeActivationThreshold = 208;
512+
consensus.vDeployments[Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE].nOverrideMinerConfirmationWindow = 288;
498513

499514
// The best chain should have at least this much work.
500515
consensus.nMinimumChainWork = uint256S("0x00");
@@ -640,7 +655,10 @@ class CRegTestParams : public CChainParams {
640655
nMessagingActivationBlock = 0; // Messaging activated block height
641656
nRestrictedActivationBlock = 0; // Restricted activated block height
642657

643-
nKAAAWWWPOWActivationTime = 1582830167;
658+
// TODO, we need to figure out what to do with this for regtest. This effects the unit tests
659+
// For now we can use a timestamp very far away
660+
// If you are looking to test the kawpow hashing function in regtest. You will need to change this number
661+
nKAAAWWWPOWActivationTime = 3582830167;
644662
nKAWPOWActivationTime = nKAAAWWWPOWActivationTime;
645663
/** RVN End **/
646664
}

src/consensus/consensus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR *
3636
//! it causes unused variable warnings when compiling. This UNUSED_VAR removes the unused warnings
3737
UNUSED_VAR static bool fAssetsIsActive = false;
3838
UNUSED_VAR static bool fRip5IsActive = false;
39+
UNUSED_VAR static bool fTransferScriptIsActive = false;
3940

4041
unsigned int GetMaxBlockWeight();
4142
unsigned int GetMaxBlockSerializedSize();

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum DeploymentPos
1818
DEPLOYMENT_TESTDUMMY,
1919
DEPLOYMENT_ASSETS, // Deployment of RIP2
2020
DEPLOYMENT_MSG_REST_ASSETS, // Delpoyment of RIP5 and Restricted assets
21+
DEPLOYMENT_TRANSFER_SCRIPT_SIZE,
2122
// DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
2223
// DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
2324
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp

src/net_processing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
16421642
return false;
16431643
}
16441644

1645+
if (AreTransferScriptsSizeDeployed() && nVersion < KAWPOW_VERSION) {
1646+
LogPrintf("peer=%d using obsolete version %i; disconnecting because peer isn't signalling protocol version for kawpow support\n", pfrom->GetId(), nVersion);
1647+
connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
1648+
strprintf("Version must be %d or greater or equal to", KAWPOW_VERSION)));
1649+
pfrom->fDisconnect = true;
1650+
return false;
1651+
}
1652+
16451653
if (nVersion == 10300)
16461654
nVersion = 300;
16471655
if (!vRecv.empty())

src/rpc/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
14321432
//BIP9SoftForkDescPushBack(bip9_softforks, "segwit", consensusParams, Consensus::DEPLOYMENT_SEGWIT);
14331433
BIP9SoftForkDescPushBack(bip9_softforks, "assets", consensusParams, Consensus::DEPLOYMENT_ASSETS);
14341434
BIP9SoftForkDescPushBack(bip9_softforks, "messaging_restricted", consensusParams, Consensus::DEPLOYMENT_MSG_REST_ASSETS);
1435+
BIP9SoftForkDescPushBack(bip9_softforks, "transfer_script", consensusParams, Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE);
14351436
obj.push_back(Pair("softforks", softforks));
14361437
obj.push_back(Pair("bip9_softforks", bip9_softforks));
14371438

src/validation.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,8 +3489,9 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
34893489
if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
34903490
if (state.IsInvalid()) {
34913491
// The block violates a consensus rule.
3492-
if (!state.CorruptionPossible())
3492+
if (!state.CorruptionPossible()) {
34933493
InvalidChainFound(vpindexToConnect.back());
3494+
}
34943495
state = CValidationState();
34953496
fInvalidFound = true;
34963497
fContinue = false;
@@ -4308,7 +4309,7 @@ bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, CValidatio
43084309
}
43094310

43104311
/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
4311-
static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock)
4312+
static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock, bool fFromLoad = false)
43124313
{
43134314
const CBlock& block = *pblock;
43144315

@@ -4358,11 +4359,17 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
43584359
// Dont force the CheckBlock asset duplciates when checking from this state
43594360
if (!CheckBlock(block, state, chainparams.GetConsensus(), true, true) ||
43604361
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev, currentActiveAssetCache)) {
4361-
if (state.IsInvalid() && !state.CorruptionPossible()) {
4362-
pindex->nStatus |= BLOCK_FAILED_VALID;
4363-
setDirtyBlockIndex.insert(pindex);
4362+
if (fFromLoad && state.GetRejectReason() == "bad-txns-transfer-asset-bad-deserialize") {
4363+
// keep going, we are only loading blocks from database
4364+
CValidationState new_state;
4365+
state = new_state;
4366+
} else {
4367+
if (state.IsInvalid() && !state.CorruptionPossible()) {
4368+
pindex->nStatus |= BLOCK_FAILED_VALID;
4369+
setDirtyBlockIndex.insert(pindex);
4370+
}
4371+
return error("%s: %s", __func__, FormatStateMessage(state));
43644372
}
4365-
return error("%s: %s", __func__, FormatStateMessage(state));
43664373
}
43674374

43684375
// Header is valid/has work, merkle tree and segwit merkle tree are good...RELAY NOW
@@ -5276,11 +5283,12 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
52765283
if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) {
52775284
LOCK(cs_main);
52785285
CValidationState state;
5279-
if (AcceptBlock(pblock, state, chainparams, nullptr, true, dbp, nullptr)) {
5286+
if (AcceptBlock(pblock, state, chainparams, nullptr, true, dbp, nullptr, true)) {
52805287
nLoaded++;
52815288
}
5282-
if (state.IsError())
5289+
if (state.IsError()) {
52835290
break;
5291+
}
52845292
} else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) {
52855293
LogPrint(BCLog::REINDEX, "Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
52865294
}
@@ -5311,7 +5319,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
53115319
head.ToString());
53125320
LOCK(cs_main);
53135321
CValidationState dummy;
5314-
if (AcceptBlock(pblockrecursive, dummy, chainparams, nullptr, true, &it->second, nullptr))
5322+
if (AcceptBlock(pblockrecursive, dummy, chainparams, nullptr, true, &it->second, nullptr, true))
53155323
{
53165324
nLoaded++;
53175325
queue.push_back(pblockrecursive->GetHash());
@@ -5724,6 +5732,18 @@ bool AreMessagesDeployed() {
57245732
return IsRip5Active();
57255733
}
57265734

5735+
bool AreTransferScriptsSizeDeployed() {
5736+
5737+
if (fTransferScriptIsActive)
5738+
return true;
5739+
5740+
const ThresholdState thresholdState = VersionBitsTipState(GetParams().GetConsensus(), Consensus::DEPLOYMENT_TRANSFER_SCRIPT_SIZE);
5741+
if (thresholdState == THRESHOLD_ACTIVE)
5742+
fTransferScriptIsActive = true;
5743+
5744+
return fTransferScriptIsActive;
5745+
}
5746+
57275747
bool AreRestrictedAssetsDeployed() {
57285748

57295749
return IsRip5Active();

src/validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ bool AreRestrictedAssetsDeployed();
597597

598598
bool IsRip5Active();
599599

600+
601+
bool AreTransferScriptsSizeDeployed();
602+
600603
bool IsDGWActive(unsigned int nBlockNumber);
601604
bool IsMessagingActive(unsigned int nBlockNumber);
602605
bool IsRestrictedActive(unsigned int nBlockNumber);

src/version.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static const int ASSETDATA_VERSION = 70017;
3232
//! getassetdata reutrn asstnotfound, and assetdata doesn't have blockhash in the data
3333
static const int X16RV2_VERSION = 70025;
3434

35+
//! getassetdata reutrn asstnotfound, and assetdata doesn't have blockhash in the data
36+
static const int KAWPOW_VERSION = 70027;
37+
3538
//! disconnect from peers older than this proto version
3639
//!!! Anytime this value is changed please also update the "MY_VERSION" value to match in the
3740
//!!! ./test/functional/test_framework/mininode.py file. Not doing so will cause verack to fail!
@@ -65,4 +68,5 @@ static const int ASSETDATA_VERSION_UPDATED = 70020;
6568
//! In this version, 'rip5 (messaging and restricted assets)' was introduced
6669
static const int MESSAGING_RESTRICTED_ASSETS_VERSION = 70026;
6770

71+
6872
#endif // RAVEN_VERSION_H

src/versionbits.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
2222
{
2323
/*.name =*/ "messaging_restricted",
2424
/*.gbt_force =*/ true,
25+
},
26+
{
27+
/*.name =*/ "transfer_script",
28+
/*.gbt_force =*/ true,
2529
}
2630
};
2731

0 commit comments

Comments
 (0)