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

Create Komodo Testnet #520

Closed
wants to merge 14 commits into from
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ AC_LANG_PUSH([C++])
AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])

if test "x$enable_debug" = xyes; then
CPPFLAGS="$CPPFLAGS -DDEBUG -DDEBUG_LOCKORDER"
CPPFLAGS="$CPPFLAGS -DDEBUG"
if test "x$GCC" = xyes; then
CFLAGS="$CFLAGS -g3 -O0"
fi
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ libbitcoin_common_a_SOURCES = \
komodo_events.cpp \
komodo_gateway.cpp \
komodo_globals.cpp \
komodo_hardfork.cpp \
komodo_interest.cpp \
komodo_jumblr.cpp \
komodo_kv.cpp \
Expand Down
48 changes: 29 additions & 19 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,33 @@ friend class CAddrManTest;
//! Wraps GetRandInt to allow tests to override RandomInt and make it deterministic.
virtual int RandomInt(int nMax);

/***
* @brief Clears the internal collections and fills them again
* @note the mutex should be held before this method is called
* @note the constructor calls this directly with no lock
*/
void Clear_()
{
std::vector<int>().swap(vRandom);
nKey = GetRandHash();
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvNew[bucket][entry] = -1;
}
}
for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvTried[bucket][entry] = -1;
}
}

nIdCount = 0;
nTried = 0;
nNew = 0;
mapInfo.clear();
mapAddr.clear();
}

#ifdef DEBUG_ADDRMAN
//! Perform consistency check. Returns an error code or zero.
int Check_();
Expand Down Expand Up @@ -502,29 +529,12 @@ friend class CAddrManTest;
void Clear()
{
LOCK(cs);
std::vector<int>().swap(vRandom);
nKey = GetRandHash();
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvNew[bucket][entry] = -1;
}
}
for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvTried[bucket][entry] = -1;
}
}

nIdCount = 0;
nTried = 0;
nNew = 0;
mapInfo.clear();
mapAddr.clear();
Clear_();
}

CAddrMan()
{
Clear();
Clear_();
}

~CAddrMan()
Expand Down
191 changes: 111 additions & 80 deletions src/chainparams.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class CChainParams
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::string& Bech32HRP(Bech32Type type) const { return bech32HRPs[type]; }
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
const std::vector<std::pair<std::string, std::string> > GenesisNotaries() const { return genesisNotaries; }
const CCheckpointData& Checkpoints() const { return checkpointData; }
/** Return the founder's reward address and script for a given block height */
std::string GetFoundersRewardAddressAtHeight(int height) const;
Expand Down Expand Up @@ -156,6 +157,7 @@ class CChainParams
bool fTestnetToBeDeprecatedFieldRPC = false;
CCheckpointData checkpointData;
std::vector<std::string> vFoundersRewardAddress;
std::vector< std::pair<std::string, std::string> > genesisNotaries;
};

/**
Expand Down
409 changes: 3 additions & 406 deletions src/komodo_defs.h

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions src/komodo_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ int32_t NUM_PRICES; uint32_t *PVALS;
struct knotaries_entry *Pubkeys;

struct komodo_state KOMODO_STATES[34];
const uint32_t nStakedDecemberHardforkTimestamp = 1576840000; //December 2019 hardfork 12/20/2019 @ 11:06am (UTC)
const int32_t nDecemberHardforkHeight = 1670000; //December 2019 hardfork

const uint32_t nS4Timestamp = 1592146800; //dPoW Season 4 2020 hardfork Sunday, June 14th, 2020 03:00:00 PM UTC
const int32_t nS4HardforkHeight = 1922000; //dPoW Season 4 2020 hardfork Sunday, June 14th, 2020

const uint32_t nS5Timestamp = 1623682800; //dPoW Season 5 Monday, June 14th, 2021 (03:00:00 PM UTC)
const int32_t nS5HardforkHeight = 2437300; //dPoW Season 5 Monday, June 14th, 2021

#define _COINBASE_MATURITY 100
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
Expand Down
417 changes: 417 additions & 0 deletions src/komodo_hardfork.cpp

Large diffs are not rendered by default.

51 changes: 6 additions & 45 deletions src/komodo_notary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,6 @@
#include "komodo_structs.h" // KOMODO_NOTARIES_HARDCODED
#include "komodo_utils.h" // komodo_stateptr

const char *Notaries_genesis[][2] =
{
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
{ "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" },
{ "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" },
{ "crackers_EU", "0340c66cf2c41c41efb420af57867baa765e8468c12aa996bfd816e1e07e410728" },
{ "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" },
{ "locomb_EU", "025c6d26649b9d397e63323d96db42a9d3caad82e1d6076970efe5056c00c0779b" },
{ "fullmoon_AE", "0204a908350b8142698fdb6fabefc97fe0e04f537adc7522ba7a1e8f3bec003d4a" },
{ "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" },
{ "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" },
{ "crackers_NA", "029e1c01131974f4cd3f564cc0c00eb87a0f9721043fbc1ca60f9bd0a1f73f64a1" },
{ "proto_EU", "03681ffdf17c8f4f0008cefb7fa0779c5e888339cdf932f0974483787a4d6747c1" }, // 10
{ "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" },
{ "farl4web_EU", "035caa40684ace968677dca3f09098aa02b70e533da32390a7654c626e0cf908e1" },
{ "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" },
{ "traderbill_EU", "03196e8de3e2e5d872f31d79d6a859c8704a2198baf0af9c7b21e29656a7eb455f" },
{ "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, // 15
{ "titomane_EU", "03517fcac101fed480ae4f2caf775560065957930d8c1facc83e30077e45bdd199" },
{ "supernet_AE", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" },
{ "supernet_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" },
{ "supernet_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" },
{ "yassin_EU", "033fb7231bb66484081952890d9a03f91164fb27d392d9152ec41336b71b15fbd0" }, // 20
{ "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" },
{ "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" },
{ "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" },
{ "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" },
{ "rnr_EU", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" },
{ "crackers_SH", "02313d72f9a16055737e14cfc528dcd5d0ef094cfce23d0348fe974b6b1a32e5f0" },
{ "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" },
{ "polycryptoblock_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" },
{ "titomane_NA", "0387046d9745414fb58a0fa3599078af5073e10347e4657ef7259a99cb4f10ad47" },
{ "titomane_AE", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" },
{ "kolo_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" },
{ "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" },
{ "eclips_EU", "0339369c1f5a2028d44be7be6f8ec3b907fdec814f87d2dead97cab4edb71a42e9" },
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
};

int32_t getkmdseason(int32_t height)
{
if ( height <= KMD_SEASON_HEIGHTS[0] )
Expand Down Expand Up @@ -482,22 +443,22 @@ void komodo_init(int32_t height)
{
static int didinit;
uint256 zero;
int32_t k,n;
uint8_t pubkeys[64][33];
memset(&zero,0,sizeof(zero));
if ( didinit == 0 )
{
decode_hex(NOTARY_PUBKEY33,33,NOTARY_PUBKEY.c_str());
if ( height >= 0 )
{
n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis));
for (k=0; k<n; k++)
int32_t count = 0;
for( auto pair : Params().GenesisNotaries() )
{
if ( Notaries_genesis[k][0] == 0 || Notaries_genesis[k][1] == 0 || Notaries_genesis[k][0][0] == 0 || Notaries_genesis[k][1][0] == 0 )
if (pair.first.empty() || pair.second.empty() )
break;
decode_hex(pubkeys[k],33,(char *)Notaries_genesis[k][1]);
decode_hex(pubkeys[count],33,(char *)pair.second.c_str());
++count;
}
komodo_notarysinit(0,pubkeys,k);
komodo_notarysinit(0,pubkeys,count);
}
didinit = 1;
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,zero,0);
Expand Down
4 changes: 2 additions & 2 deletions src/komodo_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ void komodo_args(char *argv0)
else
{
char fname[512],username[512],password[4096]; int32_t iter; FILE *fp;
ASSETCHAINS_P2PPORT = 7770;
ASSETCHAINS_P2PPORT = Params().GetDefaultPort();
ASSETCHAINS_RPCPORT = 7771;
for (iter=0; iter<2; iter++)
{
Expand All @@ -1916,7 +1916,7 @@ void komodo_args(char *argv0)
else strcat(fname,ntz_dest_path.c_str());
#else
if ( iter == 0 )
strcat(fname,".komodo/komodo.conf");
strcat(fname,"komodo.conf");
else strcat(fname,ntz_dest_path.c_str());
#endif
#endif
Expand Down
95 changes: 53 additions & 42 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,58 @@ UniValue getgenerate(const UniValue& params, bool fHelp, const CPubKey& mypk)

extern uint8_t NOTARY_PUBKEY33[33];

/*****
* Calculate the PoW value for a block
* @param pblock the block to work on
* @returns true when the PoW is completed
*/
bool CalcPoW(CBlock *pblock)
{
unsigned int n = Params().EquihashN();
unsigned int k = Params().EquihashK();
// Hash state
crypto_generichash_blake2b_state eh_state;
EhInitialiseState(n, k, eh_state);

// I = the block header minus nonce and solution.
CEquihashInput I{*pblock};
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << I;

// H(I||...
crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size());

while (true) {
// Yes, there is a chance every nonce could fail to satisfy the -regtest
// target -- 1 in 2^(2^256). That ain't gonna happen
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);

// H(I||V||...
crypto_generichash_blake2b_state curr_state;
curr_state = eh_state;
crypto_generichash_blake2b_update(&curr_state,
pblock->nNonce.begin(),
pblock->nNonce.size());

// (x_1, x_2, ...) = A(I, V, n, k)
std::function<bool(std::vector<unsigned char>)> validBlock =
[&pblock](std::vector<unsigned char> soln)
{
LOCK(cs_main);
pblock->nSolution = soln;
solutionTargetChecks.increment();
return CheckProofOfWork(*pblock,NOTARY_PUBKEY33,chainActive.Height(),Params().GetConsensus());
};
bool found = EhBasicSolveUncancellable(n, k, curr_state, validBlock);
ehSolverRuns.increment();
if (found) {
return true;
}
}
// this should never get hit
return false;
}

//Value generate(const Array& params, bool fHelp)
UniValue generate(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
Expand Down Expand Up @@ -252,8 +304,6 @@ UniValue generate(const UniValue& params, bool fHelp, const CPubKey& mypk)
}
unsigned int nExtraNonce = 0;
UniValue blockHashes(UniValue::VARR);
unsigned int n = Params().EquihashN();
unsigned int k = Params().EquihashK();
uint64_t lastTime = 0;
while (nHeight < nHeightEnd)
{
Expand All @@ -274,46 +324,7 @@ UniValue generate(const UniValue& params, bool fHelp, const CPubKey& mypk)
IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce);
}

// Hash state
crypto_generichash_blake2b_state eh_state;
EhInitialiseState(n, k, eh_state);

// I = the block header minus nonce and solution.
CEquihashInput I{*pblock};
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << I;

// H(I||...
crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size());

while (true) {
// Yes, there is a chance every nonce could fail to satisfy the -regtest
// target -- 1 in 2^(2^256). That ain't gonna happen
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);

// H(I||V||...
crypto_generichash_blake2b_state curr_state;
curr_state = eh_state;
crypto_generichash_blake2b_update(&curr_state,
pblock->nNonce.begin(),
pblock->nNonce.size());

// (x_1, x_2, ...) = A(I, V, n, k)
std::function<bool(std::vector<unsigned char>)> validBlock =
[&pblock](std::vector<unsigned char> soln)
{
LOCK(cs_main);
pblock->nSolution = soln;
solutionTargetChecks.increment();
return CheckProofOfWork(*pblock,NOTARY_PUBKEY33,chainActive.Height(),Params().GetConsensus());
};
bool found = EhBasicSolveUncancellable(n, k, curr_state, validBlock);
ehSolverRuns.increment();
if (found) {
goto endloop;
}
}
endloop:
CalcPoW(pblock);
CValidationState state;
if (!ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, pblock, true, NULL))
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
Expand Down
5 changes: 4 additions & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
}
if ( ASSETCHAINS_CC != 0 )
obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC));
obj.push_back(Pair("name", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL));
std::string symbol = ASSETCHAINS_SYMBOL;
if (symbol.empty())
symbol = Params().CurrencyUnits();
obj.push_back(Pair("name", symbol));

obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT));
obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT));
Expand Down
2 changes: 1 addition & 1 deletion zcutil/build-mac-dtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cd $WD

./autogen.sh
CPPFLAGS="-I$PREFIX/include -arch x86_64 -DTESTMODE" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \
CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -Wno-error=attributes -g -Wl,-undefined -Wl,dynamic_lookup' \
CXXFLAGS="-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -Wno-error=attributes -g -Wl,-undefined -Wl,dynamic_lookup" \
./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG"

make "$@" V=1 NO_GTEST=1 STATIC=1
2 changes: 1 addition & 1 deletion zcutil/build-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cd $WD

./autogen.sh
CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \
CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -Wno-error=attributes -g -Wl,-undefined -Wl,dynamic_lookup' \
CXXFLAGS="-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -Wno-error=attributes -g -Wl,-undefined -Wl,dynamic_lookup" \
./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG"

make "$@" V=1 NO_GTEST=1 STATIC=1