From cf02649727557d41026358f89ed040a0d1a4a62c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Apr 2019 15:27:31 +0800 Subject: [PATCH] Change MoMoMData RPC to use a 5 block KMD delay. Change MoMoM hash to use a range of 7 MoM hash. Add offset to migrate_completeimporttransaction. --- src/crosschain.cpp | 24 ++++++++++++++++-------- src/crosschain.h | 4 ++-- src/rpc/client.cpp | 1 + src/rpc/crosschain.cpp | 17 +++++++++++------ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index d65c5dd8c..82a46eaab 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -64,11 +64,12 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh if (kmdHeight < 0 || kmdHeight > chainActive.Height()) return uint256(); - int seenOwnNotarisations = 0; + int seenOwnNotarisations = 0, i = 0; int authority = GetSymbolAuthority(symbol); + std::set tmp_moms; - for (int i=0; i kmdHeight) break; NotarisationsInBlock notarisations; uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock; @@ -82,17 +83,17 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh seenOwnNotarisations++; if (seenOwnNotarisations == 1) destNotarisationTxid = nota.first; - else if (seenOwnNotarisations == 2) + else if (seenOwnNotarisations == 7) goto end; //break; } } - if (seenOwnNotarisations == 1) { + if (seenOwnNotarisations >= 1) { BOOST_FOREACH(Notarisation& nota, notarisations) { if (GetSymbolAuthority(nota.second.symbol) == authority) if (nota.second.ccId == targetCCid) { - moms.push_back(nota.second.MoM); + tmp_moms.insert(nota.second.MoM); //fprintf(stderr, "added mom: %s\n",nota.second.MoM.GetHex().data()); } } @@ -105,6 +106,10 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh return uint256(); end: + // add set to vector. Set makes sure there are no dupes included. + moms.clear(); + std::copy(tmp_moms.begin(), tmp_moms.end(), std::back_inserter(moms)); + //fprintf(stderr, "SeenOwnNotarisations.%i moms.size.%li blocks scanned.%i\n",seenOwnNotarisations, moms.size(), i); return GetMerkleRoot(moms); } @@ -138,7 +143,7 @@ int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &fou /* On KMD */ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid, - const TxProof assetChainProof) + const TxProof assetChainProof, int32_t offset) { /* * Here we are given a proof generated by an assetchain A which goes from given txid to @@ -173,6 +178,9 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_ kmdHeight = ScanNotarisationsFromHeight(kmdHeight, isTarget, nota); if (!kmdHeight) throw std::runtime_error("Cannot find notarisation for target inclusive of source"); + + if ( offset != 0 ) + kmdHeight += offset; // Get MoMs for kmd height and symbol std::vector moms; @@ -219,7 +227,7 @@ cont: * Takes an importTx that has proof leading to assetchain root * and extends proof to cross chain root */ -void CompleteImportTransaction(CTransaction &importTx) +void CompleteImportTransaction(CTransaction &importTx, int32_t offset) { TxProof proof; CTransaction burnTx; std::vector payouts; std::vector rawproof; if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) @@ -231,7 +239,7 @@ void CompleteImportTransaction(CTransaction &importTx) if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof)) throw std::runtime_error("Couldn't parse burnTx"); - proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); + proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof, offset); importTx = MakeImportCoinTransaction(proof, burnTx, payouts); } diff --git a/src/crosschain.h b/src/crosschain.h index b3d1af9b2..9ff41eff1 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -38,8 +38,8 @@ TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx); uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, uint256 &destNotarisationTxid); TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid, - const TxProof assetChainProof); -void CompleteImportTransaction(CTransaction &importTx); + const TxProof assetChainProof,int32_t offset); +void CompleteImportTransaction(CTransaction &importTx,int32_t offset); /* On assetchain */ bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom); diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 26a613f9a..3f0f9dea8 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -175,6 +175,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getNotarisationsForBlock", 0}, { "height_MoM", 1}, { "calc_MoM", 2}, + { "migrate_completeimporttransaction", 1}, }; class CRPCConvertTable diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 0feb5173c..c7992a953 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -137,12 +137,12 @@ UniValue MoMoMdata(const UniValue& params, bool fHelp) int kmdheight = atoi(params[1].get_str().c_str()); uint32_t ccid = atoi(params[2].get_str().c_str()); ret.push_back(Pair("coin",symbol)); - ret.push_back(Pair("kmdheight",kmdheight)); + ret.push_back(Pair("kmdheight",kmdheight-5)); ret.push_back(Pair("ccid", (int) ccid)); uint256 destNotarisationTxid; std::vector moms; - uint256 MoMoM = CalculateProofRoot(symbol, ccid, kmdheight, moms, destNotarisationTxid); + uint256 MoMoM = CalculateProofRoot(symbol, ccid, kmdheight-5, moms, destNotarisationTxid); UniValue valMoms(UniValue::VARR); for (int i=0; i 2) + throw runtime_error("migrate_completeimporttransaction importTx (offset)\n\n" "Takes a cross chain import tx with proof generated on assetchain " - "and extends proof to target chain proof root"); + "and extends proof to target chain proof root\n" + "offset is optional, use it to increase the used KMD height, use when import fails on target."); if (ASSETCHAINS_SYMBOL[0] != 0) throw runtime_error("Must be called on KMD"); @@ -289,7 +290,11 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) if (!E_UNMARSHAL(ParseHexV(params[0], "argument 1"), ss >> importTx)) throw runtime_error("Couldn't parse importTx"); - CompleteImportTransaction(importTx); + int32_t offset = 0; + if ( params.size() == 2 ) + offset = params[1].get_int(); + + CompleteImportTransaction(importTx, offset); return HexStr(E_MARSHAL(ss << importTx)); }