m3 test proven
This commit is contained in:
@@ -199,7 +199,7 @@ bool Eval::ImportPayout(const std::vector<uint8_t> params, const CTransaction &i
|
||||
|
||||
// Check disputeTx solves momproof from vout[0]
|
||||
{
|
||||
NotarisationData data;
|
||||
NotarisationData data(0);
|
||||
if (!GetNotarisationData(proof.notarisationHash, data))
|
||||
return Invalid("coudnt-load-mom");
|
||||
|
||||
|
||||
@@ -124,11 +124,18 @@ extern char ASSETCHAINS_SYMBOL[65];
|
||||
*/
|
||||
class NotarisationData
|
||||
{
|
||||
bool IsBack()
|
||||
{
|
||||
if (IsBackNotarisation == 2) {
|
||||
return ASSETCHAINS_SYMBOL[0] != 0;
|
||||
}
|
||||
return (bool) IsBackNotarisation;
|
||||
}
|
||||
public:
|
||||
bool IsBackNotarisation = 0;
|
||||
int IsBackNotarisation = 0;
|
||||
uint256 blockHash;
|
||||
uint32_t height;
|
||||
uint256 txHash; // Only get this guy in asset chains not in KMD
|
||||
uint256 txHash;
|
||||
char symbol[64] = "\0";
|
||||
uint256 MoM;
|
||||
uint32_t MoMDepth;
|
||||
@@ -136,7 +143,7 @@ public:
|
||||
uint256 MoMoM;
|
||||
uint32_t MoMoMDepth;
|
||||
|
||||
NotarisationData(bool IsBack=0) : IsBackNotarisation(IsBack) {}
|
||||
NotarisationData(int IsBack=2) : IsBackNotarisation(IsBack) {}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
@@ -144,14 +151,14 @@ public:
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
READWRITE(blockHash);
|
||||
READWRITE(height);
|
||||
if (IsBackNotarisation || (!ser_action.ForRead() && !txHash.IsNull()))
|
||||
if (IsBack())
|
||||
READWRITE(txHash);
|
||||
SerSymbol(s, ser_action);
|
||||
READWRITE(MoM);
|
||||
READWRITE(MoMDepth);
|
||||
if (s.size() == 0) return;
|
||||
READWRITE(ccId);
|
||||
if (IsBackNotarisation) {
|
||||
if (IsBack()) {
|
||||
READWRITE(MoMoM);
|
||||
READWRITE(MoMoMDepth);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
|
||||
|
||||
// Check proof confirms existance of burnTx
|
||||
{
|
||||
NotarisationData data;
|
||||
NotarisationData data(1);
|
||||
if (!GetNotarisationData(proof.notarisationHeight, data, true))
|
||||
return Invalid("coudnt-load-momom");
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "cc/eval.h"
|
||||
#include "main.h"
|
||||
#include "notarisationdb.h"
|
||||
#include "komodo_structs.h"
|
||||
|
||||
|
||||
/* On KMD */
|
||||
@@ -12,6 +13,8 @@ uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vect
|
||||
* including the block height of the last notarisation until the height before the
|
||||
* previous notarisation.
|
||||
*/
|
||||
*assetChainHeight = -1;
|
||||
|
||||
if (targetCCid <= 1)
|
||||
return uint256();
|
||||
|
||||
@@ -33,24 +36,31 @@ uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vect
|
||||
if (strcmp(data.symbol, symbol) == 0)
|
||||
{
|
||||
seenOwnNotarisations++;
|
||||
printf("seenOwnNotarisations:%i\n", seenOwnNotarisations);
|
||||
if (seenOwnNotarisations == 2)
|
||||
goto end;
|
||||
if (seenOwnNotarisations == 1)
|
||||
*assetChainHeight = data.height; // TODO: Needed?
|
||||
continue; // Don't include own MoMs
|
||||
}
|
||||
if (seenOwnNotarisations == 1)
|
||||
if (seenOwnNotarisations == 1) {
|
||||
moms.push_back(data.MoM);
|
||||
printf("Pushed a MoM@%i:%s\n", kmdHeight-i, data.MoM.GetHex().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
printf("GetProofRoot {\n");
|
||||
printf(" CC:%i S:%s H:%i\n", targetCCid, symbol, kmdHeight);
|
||||
for (int i=0; i<moms.size(); i++) printf(" %s", moms[i].GetHex().data());
|
||||
printf("\n R:%s\n", GetMerkleRoot(moms).GetHex().data());
|
||||
printf("}\n");
|
||||
return GetMerkleRoot(moms);
|
||||
}
|
||||
|
||||
|
||||
/* On KMD */
|
||||
std::pair<uint256,MerkleBranch> GetCrossChainProof(uint256 txid, char* targetSymbol,
|
||||
MerkleBranch GetCrossChainProof(uint256 txid, char* targetSymbol,
|
||||
uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof)
|
||||
{
|
||||
/*
|
||||
@@ -79,15 +89,18 @@ std::pair<uint256,MerkleBranch> GetCrossChainProof(uint256 txid, char* targetSym
|
||||
// Get MoMs for kmd height and symbol
|
||||
std::vector<uint256> moms;
|
||||
int targetChainStartHeight;
|
||||
printf("Getting Proof Root\n");
|
||||
uint256 MoMoM = GetProofRoot(targetSymbol, targetCCid, kmdHeight, moms, &targetChainStartHeight);
|
||||
if (MoMoM.IsNull())
|
||||
throw std::runtime_error("No MoMs found");
|
||||
|
||||
// Find index of source MoM in MoMoM
|
||||
int nIndex;
|
||||
for (nIndex=0; nIndex<moms.size(); nIndex++)
|
||||
for (nIndex=0; nIndex<moms.size(); nIndex++) {
|
||||
printf("findMoM: %s == %s\n", moms[nIndex].GetHex().data(), MoM.GetHex().data());
|
||||
if (moms[nIndex] == MoM)
|
||||
goto cont;
|
||||
}
|
||||
throw std::runtime_error("Couldn't find MoM within MoMoM set");
|
||||
cont:
|
||||
|
||||
@@ -109,10 +122,15 @@ cont:
|
||||
newProof << MerkleBranch(nIndex, newBranch);
|
||||
|
||||
// Check proof
|
||||
printf("GetCrossChainProof {\n txid: %s\n momom: %s\n", txid.GetHex().data(), MoMoM.GetHex().data());
|
||||
printf(" idx: %i\n", newProof.nIndex);
|
||||
for (int i=0; i<newProof.branch.size(); i++) printf(" %s", newProof.branch[i].GetHex().data());
|
||||
printf("\n}\n");
|
||||
|
||||
if (newProof.Exec(txid) != MoMoM)
|
||||
throw std::runtime_error("Proof check failed");
|
||||
|
||||
return std::make_pair(uint256(), newProof);
|
||||
return newProof;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +146,8 @@ bool ValidateCrossChainProof(uint256 txid, int notarisationHeight, MerkleBranch
|
||||
|
||||
|
||||
|
||||
struct notarized_checkpoint* komodo_npptr_for_height(int32_t height, int *idx);
|
||||
|
||||
int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
|
||||
|
||||
/*
|
||||
@@ -135,11 +155,12 @@ int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_
|
||||
* in: txid
|
||||
* out: pair<notarisationTxHash,merkleBranch>
|
||||
*/
|
||||
std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash)
|
||||
std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash, int &npIdx)
|
||||
{
|
||||
uint256 notarisationHash, MoM,MoMoM; int32_t notarisedHeight, depth; CBlockIndex* blockIndex;
|
||||
int nIndex;
|
||||
CBlockIndex* blockIndex;
|
||||
struct notarized_checkpoint* np;
|
||||
std::vector<uint256> branch;
|
||||
int nIndex,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi;
|
||||
|
||||
{
|
||||
uint256 blockHash;
|
||||
@@ -148,14 +169,12 @@ std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash)
|
||||
throw std::runtime_error("cannot find transaction");
|
||||
|
||||
blockIndex = mapBlockIndex[blockHash];
|
||||
|
||||
depth = komodo_MoM(¬arisedHeight, &MoM, ¬arisationHash, blockIndex->nHeight,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi);
|
||||
|
||||
if (!depth)
|
||||
if (!(np = komodo_npptr_for_height(blockIndex->nHeight, &npIdx)))
|
||||
throw std::runtime_error("notarisation not found");
|
||||
|
||||
// index of block in MoM leaves
|
||||
nIndex = notarisedHeight - blockIndex->nHeight;
|
||||
printf("notarised at: %i\n", np->notarized_height);
|
||||
nIndex = np->notarized_height - blockIndex->nHeight;
|
||||
}
|
||||
|
||||
// build merkle chain from blocks to MoM
|
||||
@@ -163,8 +182,8 @@ std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash)
|
||||
// since the merkle branch code is tied up in a block class
|
||||
// and we want to make a merkle branch for something that isnt transactions
|
||||
CBlock fakeBlock;
|
||||
for (int i=0; i<depth; i++) {
|
||||
uint256 mRoot = chainActive[notarisedHeight - i]->hashMerkleRoot;
|
||||
for (int i=0; i<np->MoMdepth; i++) {
|
||||
uint256 mRoot = chainActive[np->notarized_height - i]->hashMerkleRoot;
|
||||
CTransaction fakeTx;
|
||||
// first value in CTransaction memory is it's hash
|
||||
memcpy((void*)&fakeTx, mRoot.begin(), 32);
|
||||
@@ -173,7 +192,7 @@ std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash)
|
||||
branch = fakeBlock.GetMerkleBranch(nIndex);
|
||||
|
||||
// Check branch
|
||||
if (MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex))
|
||||
if (np->MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex))
|
||||
throw std::runtime_error("Failed merkle block->MoM");
|
||||
}
|
||||
|
||||
@@ -208,10 +227,10 @@ std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash)
|
||||
}
|
||||
|
||||
// Check the proof
|
||||
if (MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex))
|
||||
if (np->MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex))
|
||||
throw std::runtime_error("Failed validating MoM");
|
||||
|
||||
// All done!
|
||||
CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION);
|
||||
return std::make_pair(notarisationHash, MerkleBranch(nIndex, branch));
|
||||
return std::make_pair(np->notarized_desttxid, MerkleBranch(nIndex, branch));
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
|
||||
/* On assetchain */
|
||||
std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash);
|
||||
std::pair<uint256,MerkleBranch> GetAssetchainProof(uint256 hash, int &npIdx);
|
||||
|
||||
/* On KMD */
|
||||
uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vector<uint256> &moms, int* assetChainHeight);
|
||||
|
||||
/* On KMD */
|
||||
std::pair<uint256,MerkleBranch> GetCrossChainProof(uint256 txid, char* targetSymbol,
|
||||
MerkleBranch GetCrossChainProof(uint256 txid, char* targetSymbol,
|
||||
uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof);
|
||||
|
||||
/* On assetchain */
|
||||
|
||||
@@ -1268,6 +1268,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
|
||||
int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
{
|
||||
uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev;
|
||||
return 1; // TODO: obviously cant commit this
|
||||
if ( !CheckEquihashSolution(pblock, Params()) )
|
||||
{
|
||||
fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height);
|
||||
|
||||
@@ -384,18 +384,35 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,
|
||||
|
||||
//struct komodo_state *komodo_stateptr(char *symbol,char *dest);
|
||||
|
||||
struct notarized_checkpoint *komodo_npptr(int32_t height)
|
||||
struct notarized_checkpoint *komodo_npptr_for_height(int32_t height, int *idx)
|
||||
{
|
||||
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t i; struct komodo_state *sp; struct notarized_checkpoint *np = 0;
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
|
||||
{
|
||||
for (i=sp->NUM_NPOINTS-1; i>=0; i--)
|
||||
{
|
||||
*idx = i;
|
||||
np = &sp->NPOINTS[i];
|
||||
if ( np->MoMdepth > 0 && height > np->notarized_height-np->MoMdepth && height <= np->notarized_height )
|
||||
return(np);
|
||||
}
|
||||
}
|
||||
*idx = -1;
|
||||
return(0);
|
||||
}
|
||||
|
||||
struct notarized_checkpoint *komodo_npptr(int32_t height)
|
||||
{
|
||||
int idx;
|
||||
return komodo_npptr_for_height(height, &idx);
|
||||
}
|
||||
|
||||
struct notarized_checkpoint *komodo_npptr_at(int idx)
|
||||
{
|
||||
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
|
||||
if (idx < sp->NUM_NPOINTS)
|
||||
return &sp->NPOINTS[idx];
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,19 +9,18 @@
|
||||
NotarisationDB *pnotarisations;
|
||||
|
||||
|
||||
NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) {
|
||||
}
|
||||
NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) { }
|
||||
|
||||
|
||||
NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight)
|
||||
{
|
||||
EvalRef eval;
|
||||
NotarisationsInBlock vNotarisations;
|
||||
bool IsBackNotarisation = ASSETCHAINS_SYMBOL[0] != 0;
|
||||
|
||||
for (unsigned int i = 0; i < block.vtx.size(); i++) {
|
||||
CTransaction tx = block.vtx[i];
|
||||
if (eval->CheckNotaryInputs(tx, nHeight, block.nTime)) {
|
||||
NotarisationData data(IsBackNotarisation);
|
||||
NotarisationData data;
|
||||
if (ParseNotarisationOpReturn(tx, data))
|
||||
vNotarisations.push_back(std::make_pair(tx.GetHash(), data));
|
||||
else
|
||||
@@ -40,7 +39,9 @@ void WriteBackNotarisations(NotarisationsInBlock notarisations)
|
||||
{
|
||||
BOOST_FOREACH(Notarisation &n, notarisations)
|
||||
{
|
||||
if (n.second.IsBackNotarisation)
|
||||
if (n.second.IsBackNotarisation) {
|
||||
pnotarisations->Write(n.second.txHash, n);
|
||||
printf("WriteBackNotarisations {\n m3:%s\n}\n", n.second.MoMoM.GetHex().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -940,7 +940,8 @@ UniValue txMoMproof(const UniValue& params, bool fHelp)
|
||||
|
||||
hash = uint256S(params[0].get_str());
|
||||
|
||||
std::vector<uint8_t> proofData = E_MARSHAL(ss << GetAssetchainProof(hash));
|
||||
int npIdx;
|
||||
std::vector<uint8_t> proofData = E_MARSHAL(ss << GetAssetchainProof(hash, npIdx));
|
||||
return HexStr(proofData);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
#include "core_io.h"
|
||||
#include "crosschain.h"
|
||||
#include "key.h"
|
||||
#include "komodo_structs.h"
|
||||
#include "main.h"
|
||||
#include "notarisationdb.h"
|
||||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "script/cc.h"
|
||||
@@ -26,6 +28,7 @@
|
||||
|
||||
|
||||
extern uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth);
|
||||
extern struct notarized_checkpoint *komodo_npptr_at(int idx);
|
||||
|
||||
|
||||
/*
|
||||
@@ -40,8 +43,8 @@ class TestCrossChain : public ::testing::Test, public Eval {
|
||||
public:
|
||||
bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const
|
||||
{
|
||||
NotarisationData data;
|
||||
return ParseNotarisationOpReturn(tx, data);
|
||||
NotarisationData data(2);
|
||||
return ParseNotarisationOpReturn(tx, data); // If it parses it's valid
|
||||
}
|
||||
protected:
|
||||
static void SetUpTestCase() { }
|
||||
@@ -52,6 +55,15 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
uint256 endianHash(uint256 h)
|
||||
{
|
||||
uint256 out;
|
||||
for (int i=0; i<32; i++) {
|
||||
out.begin()[31-i] = h.begin()[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TestCrossChain, testCreateAndValidateImportProof)
|
||||
{
|
||||
@@ -66,10 +78,13 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof)
|
||||
int childPid = fork();
|
||||
void *ctx = zmq_ctx_new();
|
||||
void *socket = zmq_socket(ctx, ZMQ_PAIR);
|
||||
if (!childPid)
|
||||
strcpy(ASSETCHAINS_SYMBOL, "PIZZA");
|
||||
setupChain();
|
||||
std::vector<CBlock> blocks;
|
||||
blocks.resize(10);
|
||||
NotarisationData a2kmd, kmd2a(true);
|
||||
blocks.resize(1000);
|
||||
NotarisationData a2kmd(0), kmd2a(1);
|
||||
int numTestNotarisations = 10;
|
||||
|
||||
|
||||
auto SendIPC = [&] (std::vector<uint8_t> v) {
|
||||
@@ -101,75 +116,93 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof)
|
||||
|
||||
auto RunTestAssetchain = [&] ()
|
||||
{
|
||||
NotarisationData back(1);
|
||||
strcpy(ASSETCHAINS_SYMBOL, "symbolA");
|
||||
strcpy(a2kmd.symbol, "symbolA");
|
||||
a2kmd.ccId = 2;
|
||||
|
||||
/*
|
||||
* Notarisation 1
|
||||
*/
|
||||
generateBlock(&blocks[1]);
|
||||
generateBlock(&blocks[2]);
|
||||
a2kmd.blockHash = blocks[2].GetHash();
|
||||
a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2);
|
||||
SendIPC(E_MARSHAL(ss << a2kmd));
|
||||
E_UNMARSHAL(RecvIPC(), ss >> back);
|
||||
RecordNotarisation(blocks[1].vtx[0], back);
|
||||
NotarisationData n(0), back(1);
|
||||
strcpy(n.symbol, "PIZZA");
|
||||
n.ccId = 2;
|
||||
int height = 0;
|
||||
|
||||
/*
|
||||
* Notarisation 2
|
||||
* Send notarisations and write backnotarisations
|
||||
*/
|
||||
generateBlock(&blocks[3]);
|
||||
generateBlock(&blocks[4]);
|
||||
a2kmd.blockHash = blocks[4].GetHash();
|
||||
a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2);
|
||||
SendIPC(E_MARSHAL(ss << a2kmd));
|
||||
E_UNMARSHAL(RecvIPC(), ss >> back);
|
||||
RecordNotarisation(blocks[3].vtx[0], back);
|
||||
for (int ni=0; ni<numTestNotarisations; ni++)
|
||||
{
|
||||
generateBlock(&blocks[++height]);
|
||||
generateBlock(&blocks[++height]);
|
||||
n.blockHash = blocks[height].GetHash();
|
||||
n.MoM = endianHash(komodo_calcMoM(n.height=height, n.MoMDepth=2));
|
||||
SendIPC(E_MARSHAL(ss << n));
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> back));
|
||||
RecordNotarisation(blocks[height].vtx[0], back);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate proof
|
||||
*/
|
||||
generateBlock(&blocks[5]);
|
||||
uint256 txid = blocks[3].vtx[0].GetHash();
|
||||
std::pair<uint256,MerkleBranch> assetChainProof = GetAssetchainProof(txid);
|
||||
SendIPC(E_MARSHAL(ss << txid; ss << assetChainProof));
|
||||
uint256 txid = blocks[7].vtx[0].GetHash();
|
||||
int npIdx;
|
||||
std::pair<uint256,MerkleBranch> proof = GetAssetchainProof(txid, npIdx);
|
||||
SendIPC(E_MARSHAL(ss << txid; ss << proof));
|
||||
|
||||
/*
|
||||
* Test proof
|
||||
*/
|
||||
std::pair<uint256,MerkleBranch> ccProof;
|
||||
E_UNMARSHAL(RecvIPC(), ss >> ccProof);
|
||||
|
||||
// Now we have the branch with the hash of the notarisation on KMD
|
||||
// What we'd like is the notarised height on PIZZA so we can go forward
|
||||
// to the next backnotarisation, and then to the next, to get the M3.
|
||||
uint256 result = ccProof.second.Exec(txid);
|
||||
printf("result m3: %s\n", result.GetHex().data());
|
||||
struct notarized_checkpoint* np = komodo_npptr_at(npIdx+1);
|
||||
std::pair<uint256,NotarisationData> b;
|
||||
pnotarisations->Read(np->notarized_desttxid, b);
|
||||
printf("m3@1: %s\n", b.second.MoMoM.GetHex().data());
|
||||
|
||||
{
|
||||
printf("RunTestAssetChain.test {\n txid: %s\n momom: %s\n", txid.GetHex().data(), b.second.MoMoM.GetHex().data());
|
||||
printf(" idx: %i\n", ccProof.second.nIndex);
|
||||
for (int i=0; i<ccProof.second.branch.size(); i++) printf(" %s", ccProof.second.branch[i].GetHex().data());
|
||||
printf("\n}\n");
|
||||
}
|
||||
|
||||
return b.second.MoMoM == result ? 0 : 1;
|
||||
};
|
||||
|
||||
auto RunTestKmd = [&] ()
|
||||
{
|
||||
NotarisationData n;
|
||||
NotarisationData n(0);
|
||||
int height = 0;
|
||||
|
||||
/*
|
||||
* Notarisation 1
|
||||
* Write notarisations and send backnotarisations
|
||||
*/
|
||||
E_UNMARSHAL(RecvIPC(), ss >> n);
|
||||
// Grab a coinbase input to fund notarisation
|
||||
generateBlock(&blocks[1]);
|
||||
n.txHash = RecordNotarisation(blocks[1].vtx[0], a2kmd);
|
||||
n.height = chainActive.Height();
|
||||
SendIPC(E_MARSHAL(ss << n));
|
||||
|
||||
/*
|
||||
* Notarisation 2
|
||||
*/
|
||||
E_UNMARSHAL(RecvIPC(), ss >> n);
|
||||
// Grab a coinbase input to fund notarisation
|
||||
generateBlock(&blocks[2]);
|
||||
n.txHash = RecordNotarisation(blocks[2].vtx[0], a2kmd);
|
||||
n.height = chainActive.Height();
|
||||
SendIPC(E_MARSHAL(ss << n));
|
||||
for (int ni=0; ni<numTestNotarisations; ni++)
|
||||
{
|
||||
n.IsBackNotarisation = 0;
|
||||
E_UNMARSHAL(RecvIPC(), ss >> n);
|
||||
// Grab a coinbase input to fund notarisation
|
||||
generateBlock(&blocks[++height]);
|
||||
n.txHash = RecordNotarisation(blocks[height].vtx[0], n);
|
||||
{
|
||||
std::vector<uint256> moms;
|
||||
int assetChainHeight;
|
||||
n.MoMoM = GetProofRoot(n.symbol, 2, height, moms, &assetChainHeight);
|
||||
}
|
||||
printf("RunTestKmd {\n kmdnotid:%s\n momom:%s\n}\n", n.txHash.GetHex().data(), n.MoMoM.GetHex().data());
|
||||
n.IsBackNotarisation = 1;
|
||||
SendIPC(E_MARSHAL(ss << n));
|
||||
}
|
||||
|
||||
/*
|
||||
* Extend proof
|
||||
*/
|
||||
std::pair<uint256,MerkleBranch> assetChainProof;
|
||||
std::pair<uint256,MerkleBranch> proof;
|
||||
uint256 txid;
|
||||
// Extend proof to MoMoM
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> kmd2a));
|
||||
std::pair<uint256,MerkleBranch> ccProof = GetCrossChainProof(txid, (char*)"symbolA",
|
||||
2, assetChainProof.first, assetChainProof.second);
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> proof));
|
||||
proof.second = GetCrossChainProof(txid, (char*)"PIZZA", 2, proof.first, proof.second);
|
||||
SendIPC(E_MARSHAL(ss << proof));
|
||||
};
|
||||
|
||||
const char endpoint[] = "ipc://tmpKomodoTestCrossChainSock";
|
||||
@@ -177,8 +210,9 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof)
|
||||
if (!childPid) {
|
||||
assert(0 == zmq_connect(socket, endpoint));
|
||||
usleep(20000);
|
||||
RunTestAssetchain();
|
||||
exit(0);
|
||||
int out = RunTestAssetchain();
|
||||
if (!out) printf("Assetchain success\n");
|
||||
exit(out);
|
||||
}
|
||||
else {
|
||||
assert(0 == zmq_bind(socket, endpoint));
|
||||
@@ -190,77 +224,13 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*
|
||||
* Assetchain notarisation 2
|
||||
*
|
||||
|
||||
ON_ASSETCHAIN {
|
||||
a2kmd.blockHash = blocks[4].GetHash();
|
||||
a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2);
|
||||
SendIPC(E_MARSHAL(ss << a2kmd));
|
||||
}
|
||||
|
||||
ON_KMD {
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> a2kmd));
|
||||
// Grab a coinbase input to fund notarisation
|
||||
RecordNotarisation(blocks[2].vtx[0], a2kmd);
|
||||
}
|
||||
|
||||
generateBlock(&blocks[5]);
|
||||
generateBlock(&blocks[6]);
|
||||
|
||||
*
|
||||
* Backnotarisation
|
||||
*
|
||||
* This is what will contain the MoMoM which allows us to prove across chains
|
||||
*
|
||||
std::vector<uint256> moms;
|
||||
int assetChainHeight;
|
||||
|
||||
ON_KMD {
|
||||
memset(kmd2a.txHash.begin(), 1, 32); // Garbage but non-null
|
||||
kmd2a.symbol[0] = 0; // KMD
|
||||
kmd2a.MoMoM = GetProofRoot((char*)"symbolA", 2, chainActive.Height(), moms, &assetChainHeight);
|
||||
kmd2a.MoMoMDepth = 0; // Needed?
|
||||
SendIPC(E_MARSHAL(ss << kmd2a));
|
||||
}
|
||||
|
||||
ON_ASSETCHAIN {
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> kmd2a));
|
||||
RecordNotarisation(blocks[1].vtx[0], kmd2a);
|
||||
}
|
||||
|
||||
|
||||
*
|
||||
* We can now prove a tx from A on A, via a merkle root backpropagated from KMD.
|
||||
*
|
||||
*
|
||||
* The transaction that we'll try to prove is the coinbase from the 3rd block.
|
||||
* We should be able to start with only that transaction ID, and generate a merkle
|
||||
* proof.
|
||||
*
|
||||
|
||||
std::pair<uint256,MerkleBranch> assetChainProof;
|
||||
uint256 txid;
|
||||
|
||||
ON_ASSETCHAIN {
|
||||
txid = blocks[2].vtx[0].GetHash();
|
||||
|
||||
// First thing to do is get the proof from the assetchain
|
||||
assetChainProof = GetAssetchainProof(txid);
|
||||
SendIPC(E_MARSHAL(ss << txid; ss << assetChainProof));
|
||||
}
|
||||
|
||||
ON_KMD {
|
||||
// Extend proof to MoMoM
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> kmd2a));
|
||||
std::pair<uint256,MerkleBranch> ccProof = GetCrossChainProof(txid, (char*)"symbolA",
|
||||
2, assetChainProof.first, assetChainProof.second);
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,84 +21,84 @@ extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t t
|
||||
namespace TestEvalNotarisation {
|
||||
|
||||
|
||||
class EvalMock : public Eval
|
||||
{
|
||||
public:
|
||||
uint32_t nNotaries;
|
||||
uint8_t notaries[64][33];
|
||||
std::map<uint256, CTransaction> txs;
|
||||
std::map<uint256, CBlockIndex> blocks;
|
||||
|
||||
int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const
|
||||
class EvalMock : public Eval
|
||||
{
|
||||
memcpy(pubkeys, notaries, sizeof(notaries));
|
||||
return nNotaries;
|
||||
}
|
||||
public:
|
||||
uint32_t nNotaries;
|
||||
uint8_t notaries[64][33];
|
||||
std::map<uint256, CTransaction> txs;
|
||||
std::map<uint256, CBlockIndex> blocks;
|
||||
|
||||
bool GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
|
||||
{
|
||||
auto r = txs.find(hash);
|
||||
if (r != txs.end()) {
|
||||
txOut = r->second;
|
||||
if (blocks.count(hash) > 0)
|
||||
hashBlock = hash;
|
||||
return true;
|
||||
int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const
|
||||
{
|
||||
memcpy(pubkeys, notaries, sizeof(notaries));
|
||||
return nNotaries;
|
||||
}
|
||||
|
||||
bool GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
|
||||
{
|
||||
auto r = txs.find(hash);
|
||||
if (r != txs.end()) {
|
||||
txOut = r->second;
|
||||
if (blocks.count(hash) > 0)
|
||||
hashBlock = hash;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
||||
{
|
||||
auto r = blocks.find(hash);
|
||||
if (r == blocks.end()) return false;
|
||||
blockIdx = r->second;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static auto noop = [&](CMutableTransaction &mtx){};
|
||||
|
||||
|
||||
template<typename Modifier>
|
||||
void SetupEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify)
|
||||
{
|
||||
eval.nNotaries = komodo_notaries(eval.notaries, 780060, 1522946781);
|
||||
|
||||
// make fake notary inputs
|
||||
notary.vin.resize(11);
|
||||
for (int i=0; i<notary.vin.size(); i++) {
|
||||
CMutableTransaction txIn;
|
||||
txIn.vout.resize(1);
|
||||
txIn.vout[0].scriptPubKey << VCH(eval.notaries[i*2], 33) << OP_CHECKSIG;
|
||||
notary.vin[i].prevout = COutPoint(txIn.GetHash(), 0);
|
||||
eval.txs[txIn.GetHash()] = CTransaction(txIn);
|
||||
}
|
||||
|
||||
modify(notary);
|
||||
|
||||
eval.txs[notary.GetHash()] = CTransaction(notary);
|
||||
eval.blocks[notary.GetHash()].nHeight = 780060;
|
||||
eval.blocks[notary.GetHash()].nTime = 1522946781;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
||||
{
|
||||
auto r = blocks.find(hash);
|
||||
if (r == blocks.end()) return false;
|
||||
blockIdx = r->second;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static auto noop = [&](CMutableTransaction &mtx){};
|
||||
|
||||
|
||||
template<typename Modifier>
|
||||
void SetupEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify)
|
||||
{
|
||||
eval.nNotaries = komodo_notaries(eval.notaries, 780060, 1522946781);
|
||||
|
||||
// make fake notary inputs
|
||||
notary.vin.resize(11);
|
||||
for (int i=0; i<notary.vin.size(); i++) {
|
||||
CMutableTransaction txIn;
|
||||
txIn.vout.resize(1);
|
||||
txIn.vout[0].scriptPubKey << VCH(eval.notaries[i*2], 33) << OP_CHECKSIG;
|
||||
notary.vin[i].prevout = COutPoint(txIn.GetHash(), 0);
|
||||
eval.txs[txIn.GetHash()] = CTransaction(txIn);
|
||||
}
|
||||
// https://kmd.explorer.supernet.org/tx/5b8055d37cff745a404d1ae45e21ffdba62da7b28ed6533c67468d7379b20bae
|
||||
// inputs have been dropped
|
||||
static auto rawNotaryTx = "01000000000290460100000000002321020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9ac0000000000000000506a4c4dae8e0f3e6e5de498a072f5967f3c418c4faba5d56ac8ce17f472d029ef3000008f2e0100424f545300050ba773f0bc31da5839fc7cb9bd7b87f3b765ca608e5cf66785a466659b28880500000000000000";
|
||||
CTransaction notaryTx;
|
||||
static bool init = DecodeHexTx(notaryTx, rawNotaryTx);
|
||||
|
||||
modify(notary);
|
||||
static uint256 proofTxHash = uint256S("37f76551a16093fbb0a92ee635bbd45b3460da8fd00cf7d5a6b20d93e727fe4c");
|
||||
static auto vMomProof = ParseHex("0303faecbdd4b3da128c2cd2701bb143820a967069375b2ec5b612f39bbfe78a8611978871c193457ab1e21b9520f4139f113b8d75892eb93ee247c18bccfd067efed7eacbfcdc8946cf22de45ad536ec0719034fb9bc825048fe6ab61fee5bd6e9aae0bb279738d46673c53d68eb2a72da6dbff215ee41a4d405a74ff7cd355805b"); // $ fiat/bots txMoMproof $proofTxHash
|
||||
|
||||
eval.txs[notary.GetHash()] = CTransaction(notary);
|
||||
eval.blocks[notary.GetHash()].nHeight = 780060;
|
||||
eval.blocks[notary.GetHash()].nTime = 1522946781;
|
||||
}
|
||||
/*
|
||||
TEST(TestEvalNotarisation, testGetNotarisation)
|
||||
{
|
||||
EvalMock eval;
|
||||
CMutableTransaction notary(notaryTx);
|
||||
SetupEval(eval, notary, noop);
|
||||
|
||||
|
||||
// https://kmd.explorer.supernet.org/tx/5b8055d37cff745a404d1ae45e21ffdba62da7b28ed6533c67468d7379b20bae
|
||||
// inputs have been dropped
|
||||
static auto rawNotaryTx = "01000000000290460100000000002321020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9ac0000000000000000506a4c4dae8e0f3e6e5de498a072f5967f3c418c4faba5d56ac8ce17f472d029ef3000008f2e0100424f545300050ba773f0bc31da5839fc7cb9bd7b87f3b765ca608e5cf66785a466659b28880500000000000000";
|
||||
CTransaction notaryTx;
|
||||
static bool init = DecodeHexTx(notaryTx, rawNotaryTx);
|
||||
|
||||
static uint256 proofTxHash = uint256S("37f76551a16093fbb0a92ee635bbd45b3460da8fd00cf7d5a6b20d93e727fe4c");
|
||||
static auto vMomProof = ParseHex("0303faecbdd4b3da128c2cd2701bb143820a967069375b2ec5b612f39bbfe78a8611978871c193457ab1e21b9520f4139f113b8d75892eb93ee247c18bccfd067efed7eacbfcdc8946cf22de45ad536ec0719034fb9bc825048fe6ab61fee5bd6e9aae0bb279738d46673c53d68eb2a72da6dbff215ee41a4d405a74ff7cd355805b"); // $ fiat/bots txMoMproof $proofTxHash
|
||||
|
||||
/*
|
||||
TEST(TestEvalNotarisation, testGetNotarisation)
|
||||
{
|
||||
EvalMock eval;
|
||||
CMutableTransaction notary(notaryTx);
|
||||
SetupEval(eval, notary, noop);
|
||||
|
||||
NotarisationData data;
|
||||
NotarisationData data;
|
||||
ASSERT_TRUE(eval.GetNotarisationData(notary.GetHash(), data));
|
||||
EXPECT_EQ(data.height, 77455);
|
||||
EXPECT_EQ(data.blockHash.GetHex(), "000030ef29d072f417cec86ad5a5ab4f8c413c7f96f572a098e45d6e3e0f8eae");
|
||||
@@ -134,7 +134,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationBadOpReturn)
|
||||
notary.vout[1].scriptPubKey = CScript() << OP_RETURN << 0;
|
||||
SetupEval(eval, notary, noop);
|
||||
|
||||
NotarisationData data;
|
||||
NotarisationData data(0);
|
||||
ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data));
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationTxNotEnoughSigs)
|
||||
tx.vin.resize(10);
|
||||
});
|
||||
|
||||
NotarisationData data;
|
||||
NotarisationData data(0);
|
||||
ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data));
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationTxDoesntExist)
|
||||
|
||||
SetupEval(eval, notary, noop);
|
||||
|
||||
NotarisationData data;
|
||||
NotarisationData data(0);
|
||||
ASSERT_FALSE(eval.GetNotarisationData(uint256(), data));
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationDupeNotary)
|
||||
tx.vin[1] = tx.vin[3];
|
||||
});
|
||||
|
||||
NotarisationData data;
|
||||
NotarisationData data(0);
|
||||
ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data));
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationInputNotCheckSig)
|
||||
eval.txs[txIn.GetHash()] = CTransaction(txIn);
|
||||
});
|
||||
|
||||
NotarisationData data;
|
||||
NotarisationData data(0);
|
||||
ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ void setupChain()
|
||||
// Init blockchain
|
||||
ClearDatadirCache();
|
||||
auto pathTemp = GetTempPath() / strprintf("test_komodo_%li_%i", GetTime(), GetRand(100000));
|
||||
if (ASSETCHAINS_SYMBOL[0])
|
||||
pathTemp = pathTemp / strprintf("_%s", ASSETCHAINS_SYMBOL);
|
||||
boost::filesystem::create_directories(pathTemp);
|
||||
mapArgs["-datadir"] = pathTemp.string();
|
||||
pblocktree = new CBlockTreeDB(1 << 20, true);
|
||||
@@ -71,7 +73,7 @@ void generateBlock(CBlock *block)
|
||||
SetMockTime(nMockTime+=100); // CreateNewBlock can fail if not enough time passes
|
||||
|
||||
char symbolPrefix = ASSETCHAINS_SYMBOL[0];
|
||||
ASSETCHAINS_SYMBOL[0] = 0; // generate block fails otherwise
|
||||
//ASSETCHAINS_SYMBOL[0] = 0; // generate block fails otherwise
|
||||
|
||||
try {
|
||||
UniValue out = generate(params, false);
|
||||
|
||||
Reference in New Issue
Block a user