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.

This commit is contained in:
blackjok3r
2019-04-17 15:27:31 +08:00
parent 78162cf103
commit cf02649727
4 changed files with 30 additions and 16 deletions

View File

@@ -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<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;
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<uint256> 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<CTxOut> payouts; std::vector<uint8_t> 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);
}