Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dpow #2

Merged
merged 17 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libgincoinconsensus.pc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ includedir=${prefix}/include

Name: Bitcoin Core consensus library
Description: Library for the Bitcoin consensus protocol.
Version: 1.1.0
Version: 1.2.0
Libs: -L${libdir} -lgincoinconsensus
Cflags: -I${includedir}
Requires.private: libcrypto
2 changes: 2 additions & 0 deletions qa/pull-tester/rpc-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@

#Tests
testScripts = [
'dpow.py',
'dpowconfs.py',
'bip68-112-113-p2p.py',
'wallet.py',
'wallet-hd.py',
Expand Down
35 changes: 35 additions & 0 deletions qa/rpc-tests/dpow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Hush developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
start_node, stop_node, wait_bitcoinds

class DPoWTest(BitcoinTestFramework):

def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
num_nodes = 1
initialize_chain_clean(self.options.tmpdir, num_nodes)

def setup_network(self):
self.nodes = []
self.is_network_split = False
self.nodes.append(start_node(0, self.options.tmpdir))
self.sync_all()

def run_test(self):
self.nodes[0].generate(3)
rpc = self.nodes[0]

result = rpc.getinfo()
print result
# regtest should have no notarization data, this test makes sure we do not see mainnet values as well!
assert_equal(result['notarized'],0)
assert_equal(result['notarizedhash'],'0000000000000000000000000000000000000000000000000000000000000000')
assert_equal(result['notarizedtxid'],'0000000000000000000000000000000000000000000000000000000000000000')

if __name__ == '__main__':
DPoWTest().main()
52 changes: 52 additions & 0 deletions qa/rpc-tests/dpowconfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Hush developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
start_node, stop_node, wait_bitcoinds


class DPoWConfsTest(BitcoinTestFramework):

def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
num_nodes = 1
initialize_chain_clean(self.options.tmpdir, num_nodes)

def setup_network(self):
self.nodes = []
self.is_network_split = False
self.nodes.append(start_node(0, self.options.tmpdir))
self.sync_all()

def run_test(self):
rpc = self.nodes[0]
# 98 is notarized, next will be 105. Must mine at least 101
# blocks for 100 block maturity rule
blockhashes = rpc.generate(101)
# block 98, this is 0 indexed
notarizedhash = blockhashes[97]
print rpc.getinfo()

taddr = rpc.getnewaddress()
rpc.sendtoaddress(taddr, 1987.420)
rpc.generate(2)

info = rpc.getinfo()
assert_equal( info['notarizedhash'], notarizedhash)

result = rpc.listunspent()

# this xtn has 2 raw confs, but not in a notarized block,
# so dpowconfs holds it at 1
for res in result:
#print res
if (res['address'] == taddr):
assert_equal( result[0]['confirmations'], 1 )
assert_equal( result[0]['rawconfirmations'], 2 )


if __name__ == '__main__':
DPoWConfsTest().main()
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
#if ENABLE_ZMQ
#include "zmq/zmqnotificationinterface.h"
#endif
#include "komodo_validation012.h"

using namespace std;

Expand Down Expand Up @@ -822,6 +823,8 @@ bool AppInitServers(boost::thread_group& threadGroup)
// Parameter interaction based on rules
void InitParameterInteraction()
{
int32_t komodo_init();
komodo_init();
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
if (mapArgs.count("-bind")) {
Expand Down
150 changes: 150 additions & 0 deletions src/komodo_notaries.h

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions src/komodo_rpcblockchain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/******************************************************************************
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#ifndef komodo_rpcblockchain_h
#define komodo_rpcblockchain_h

#include "validation.h"

int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t height,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth);
extern char ASSETCHAINS_SYMBOL[65];
uint32_t DPOWCONFS = 1;
extern int32_t NOTARIZED_HEIGHT;

int32_t komodo_dpowconfs(int32_t txheight,int32_t numconfs)
{
// DPoW confs are on by default
int32_t dpowconfs = 1;
DPOWCONFS = GetArg("-dpowconfs",dpowconfs);
if ( DPOWCONFS != 0 && txheight > 0 && numconfs > 0 )
{
if ( NOTARIZED_HEIGHT > 0 )
{
if ( txheight < NOTARIZED_HEIGHT )
return(numconfs);
else return(1);
}
}
return(numconfs);
}

int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip)
{
int32_t depth,notarized_ht; uint256 MoM,kmdtxid;
depth = komodo_MoMdata(&notarized_ht,&MoM,&kmdtxid,nHeight,MoMoMp,MoMoMoffsetp,MoMoMdepthp,kmdstartip,kmdendip);
memset(MoMp,0,sizeof(*MoMp));
memset(kmdtxidp,0,sizeof(*kmdtxidp));
*notarized_heightp = 0;
if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht )
{
*MoMp = MoM;
*notarized_heightp = notarized_ht;
*kmdtxidp = kmdtxid;
}
return(depth);
}

UniValue calc_MoM(const UniValue& params, bool fHelp)
{
int32_t height,MoMdepth; uint256 MoM; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
if ( fHelp || params.size() != 2 )
throw std::runtime_error("calc_MoM height MoMdepth\n");
LOCK(cs_main);
height = atoi(params[0].get_str().c_str());
MoMdepth = atoi(params[1].get_str().c_str());
if ( height <= 0 )
throw std::runtime_error("calc_MoM illegal height, must be positive\n");
if ( MoMdepth <= 0 || MoMdepth >= height )
throw std::runtime_error("calc_MoM illegal MoMdepth, must be positive and less than height\n");

//fprintf(stderr,"height_MoM height.%d\n",height);
MoM = komodo_calcMoM(height,MoMdepth);
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
ret.push_back(Pair("height",height));
ret.push_back(Pair("MoMdepth",MoMdepth));
ret.push_back(Pair("MoM",MoM.GetHex()));
return ret;
}

UniValue height_MoM(const UniValue& params, bool fHelp)
{
int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
if ( fHelp || params.size() != 1 )
throw std::runtime_error("height_MoM height\n");
LOCK(cs_main);
height = atoi(params[0].get_str().c_str());
if ( height <= 0 )
{
if ( chainActive.Tip() == 0 )
{
ret.push_back(Pair("error",(char *)"no active chain yet"));
return(ret);
}
height = chainActive.Tip()->nHeight;
}
//fprintf(stderr,"height_MoM height.%d\n",height);
depth = komodo_MoM(&notarized_height,&MoM,&kmdtxid,height,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi);
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
ret.push_back(Pair("height",height));
ret.push_back(Pair("timestamp",(uint64_t)timestamp));
if ( depth > 0 )
{
ret.push_back(Pair("depth",depth));
ret.push_back(Pair("notarized_height",notarized_height));
ret.push_back(Pair("MoM",MoM.GetHex()));
ret.push_back(Pair("kmdtxid",kmdtxid.GetHex()));
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
ret.push_back(Pair("MoMoM",MoMoM.GetHex()));
ret.push_back(Pair("MoMoMoffset",MoMoMoffset));
ret.push_back(Pair("MoMoMdepth",MoMoMdepth));
ret.push_back(Pair("kmdstarti",kmdstarti));
ret.push_back(Pair("kmdendi",kmdendi));
}
} else ret.push_back(Pair("error",(char *)"no MoM for height"));

return ret;
}

#endif /* komodo_rpcblockchain_h */
Loading