Merge pull request #1434 from blackjok3rtt/FSM
Port of MoMoM changes from LABS.
This commit is contained in:
@@ -64,11 +64,12 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
|
|||||||
if (kmdHeight < 0 || kmdHeight > chainActive.Height())
|
if (kmdHeight < 0 || kmdHeight > chainActive.Height())
|
||||||
return uint256();
|
return uint256();
|
||||||
|
|
||||||
int seenOwnNotarisations = 0;
|
int seenOwnNotarisations = 0, i = 0;
|
||||||
|
|
||||||
int authority = GetSymbolAuthority(symbol);
|
int authority = GetSymbolAuthority(symbol);
|
||||||
|
std::set<uint256> tmp_moms;
|
||||||
|
|
||||||
for (int i=0; i<NOTARISATION_SCAN_LIMIT_BLOCKS; i++) {
|
for (i=0; i<NOTARISATION_SCAN_LIMIT_BLOCKS; i++) {
|
||||||
if (i > kmdHeight) break;
|
if (i > kmdHeight) break;
|
||||||
NotarisationsInBlock notarisations;
|
NotarisationsInBlock notarisations;
|
||||||
uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock;
|
uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock;
|
||||||
@@ -82,17 +83,17 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
|
|||||||
seenOwnNotarisations++;
|
seenOwnNotarisations++;
|
||||||
if (seenOwnNotarisations == 1)
|
if (seenOwnNotarisations == 1)
|
||||||
destNotarisationTxid = nota.first;
|
destNotarisationTxid = nota.first;
|
||||||
else if (seenOwnNotarisations == 2)
|
else if (seenOwnNotarisations == 7)
|
||||||
goto end;
|
goto end;
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seenOwnNotarisations == 1) {
|
if (seenOwnNotarisations >= 1) {
|
||||||
BOOST_FOREACH(Notarisation& nota, notarisations) {
|
BOOST_FOREACH(Notarisation& nota, notarisations) {
|
||||||
if (GetSymbolAuthority(nota.second.symbol) == authority)
|
if (GetSymbolAuthority(nota.second.symbol) == authority)
|
||||||
if (nota.second.ccId == targetCCid) {
|
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());
|
//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();
|
return uint256();
|
||||||
|
|
||||||
end:
|
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);
|
return GetMerkleRoot(moms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +143,7 @@ int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &fou
|
|||||||
|
|
||||||
/* On KMD */
|
/* On KMD */
|
||||||
TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid,
|
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
|
* 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);
|
kmdHeight = ScanNotarisationsFromHeight(kmdHeight, isTarget, nota);
|
||||||
if (!kmdHeight)
|
if (!kmdHeight)
|
||||||
throw std::runtime_error("Cannot find notarisation for target inclusive of source");
|
throw std::runtime_error("Cannot find notarisation for target inclusive of source");
|
||||||
|
|
||||||
|
if ( offset != 0 )
|
||||||
|
kmdHeight += offset;
|
||||||
|
|
||||||
// Get MoMs for kmd height and symbol
|
// Get MoMs for kmd height and symbol
|
||||||
std::vector<uint256> moms;
|
std::vector<uint256> moms;
|
||||||
@@ -219,7 +227,7 @@ cont:
|
|||||||
* Takes an importTx that has proof leading to assetchain root
|
* Takes an importTx that has proof leading to assetchain root
|
||||||
* and extends proof to cross chain 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<CTxOut> payouts; std::vector<uint8_t> rawproof;
|
TxProof proof; CTransaction burnTx; std::vector<CTxOut> payouts; std::vector<uint8_t> rawproof;
|
||||||
if (!UnmarshalImportTx(importTx, proof, burnTx, payouts))
|
if (!UnmarshalImportTx(importTx, proof, burnTx, payouts))
|
||||||
@@ -231,7 +239,7 @@ void CompleteImportTransaction(CTransaction &importTx)
|
|||||||
if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof))
|
if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof))
|
||||||
throw std::runtime_error("Couldn't parse burnTx");
|
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);
|
importTx = MakeImportCoinTransaction(proof, burnTx, payouts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx);
|
|||||||
uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight,
|
uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight,
|
||||||
std::vector<uint256> &moms, uint256 &destNotarisationTxid);
|
std::vector<uint256> &moms, uint256 &destNotarisationTxid);
|
||||||
TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid,
|
TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid,
|
||||||
const TxProof assetChainProof);
|
const TxProof assetChainProof,int32_t offset);
|
||||||
void CompleteImportTransaction(CTransaction &importTx);
|
void CompleteImportTransaction(CTransaction &importTx,int32_t offset);
|
||||||
|
|
||||||
/* On assetchain */
|
/* On assetchain */
|
||||||
bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom);
|
bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom);
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "getNotarisationsForBlock", 0},
|
{ "getNotarisationsForBlock", 0},
|
||||||
{ "height_MoM", 1},
|
{ "height_MoM", 1},
|
||||||
{ "calc_MoM", 2},
|
{ "calc_MoM", 2},
|
||||||
|
{ "migrate_completeimporttransaction", 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
class CRPCConvertTable
|
class CRPCConvertTable
|
||||||
|
|||||||
@@ -137,12 +137,12 @@ UniValue MoMoMdata(const UniValue& params, bool fHelp)
|
|||||||
int kmdheight = atoi(params[1].get_str().c_str());
|
int kmdheight = atoi(params[1].get_str().c_str());
|
||||||
uint32_t ccid = atoi(params[2].get_str().c_str());
|
uint32_t ccid = atoi(params[2].get_str().c_str());
|
||||||
ret.push_back(Pair("coin",symbol));
|
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));
|
ret.push_back(Pair("ccid", (int) ccid));
|
||||||
|
|
||||||
uint256 destNotarisationTxid;
|
uint256 destNotarisationTxid;
|
||||||
std::vector<uint256> moms;
|
std::vector<uint256> moms;
|
||||||
uint256 MoMoM = CalculateProofRoot(symbol, ccid, kmdheight, moms, destNotarisationTxid);
|
uint256 MoMoM = CalculateProofRoot(symbol, ccid, kmdheight-5, moms, destNotarisationTxid);
|
||||||
|
|
||||||
UniValue valMoms(UniValue::VARR);
|
UniValue valMoms(UniValue::VARR);
|
||||||
for (int i=0; i<moms.size(); i++) valMoms.push_back(moms[i].GetHex());
|
for (int i=0; i<moms.size(); i++) valMoms.push_back(moms[i].GetHex());
|
||||||
@@ -277,10 +277,11 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
|
UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 1)
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||||
throw runtime_error("migrate_completeimporttransaction importTx\n\n"
|
throw runtime_error("migrate_completeimporttransaction importTx (offset)\n\n"
|
||||||
"Takes a cross chain import tx with proof generated on assetchain "
|
"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)
|
if (ASSETCHAINS_SYMBOL[0] != 0)
|
||||||
throw runtime_error("Must be called on KMD");
|
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))
|
if (!E_UNMARSHAL(ParseHexV(params[0], "argument 1"), ss >> importTx))
|
||||||
throw runtime_error("Couldn't parse 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));
|
return HexStr(E_MARSHAL(ss << importTx));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user