Merge branch 'dev' into duke

This commit is contained in:
Duke Leto
2021-04-07 17:45:06 -04:00
21 changed files with 455 additions and 130 deletions

View File

@@ -215,8 +215,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
info.fInTried = true;
}
void CAddrMan::Good_(const CService& addr, int64_t nTime)
{
void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime) {
int nId;
CAddrInfo* pinfo = Find(addr, &nId);
@@ -258,12 +257,101 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime)
if (nUBucket == -1)
return;
LogPrint("addrman", "Moving %s to tried\n", addr.ToString());
// which tried bucket to move the entry to
int tried_bucket = info.GetTriedBucket(nKey,m_asmap);
int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket);
// move nId to the tried tables
MakeTried(info, nId);
// Will moving this address into tried evict another entry?
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) {
LogPrint("addrman", "Collision inserting element into tried table, moving %s to m_tried_collisions=%d\n", addr.ToString(), m_tried_collisions.size());
if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
m_tried_collisions.insert(nId);
}
} else {
LogPrint("addrman", "Moving %s to tried\n", addr.ToString());
printf("%s: Moving %s to tried\n", __func__, addr.ToString().c_str() );
// move nId to the tried tables
MakeTried(info, nId);
}
}
void CAddrMan::ResolveCollisions_() {
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
int id_new = *it;
bool erase_collision = false;
// If id_new not found in mapInfo remove it from m_tried_collisions
if (mapInfo.count(id_new) != 1) {
erase_collision = true;
} else {
CAddrInfo& info_new = mapInfo[id_new];
// Which tried bucket to move the entry to.
int tried_bucket = info_new.GetTriedBucket(nKey,m_asmap);
int tried_bucket_pos = info_new.GetBucketPosition(nKey, false, tried_bucket);
if (!info_new.IsValid()) { // id_new may no longer map to a valid address
erase_collision = true;
} else if (vvTried[tried_bucket][tried_bucket_pos] != -1) { // The position in the tried bucket is not empty
// Get the to-be-evicted address that is being tested
int id_old = vvTried[tried_bucket][tried_bucket_pos];
CAddrInfo& info_old = mapInfo[id_old];
// Has successfully connected in last X hours
if (GetTime() - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60*60)) {
erase_collision = true;
} else if (GetTime() - info_old.nLastTry < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { // attempted to connect and failed in last X hours
// Give address at least 60 seconds to successfully connect
if (GetTime() - info_old.nLastTry > 60) {
LogPrint("addrman", "Swapping %s for %s in tried table\n", info_new.ToString(), info_old.ToString());
// Replaces an existing address already in the tried table with the new address
Good_(info_new, false, GetTime());
erase_collision = true;
}
}
} else { // Collision is not actually a collision anymore
Good_(info_new, false, GetTime());
erase_collision = true;
}
}
if (erase_collision) {
m_tried_collisions.erase(it++);
} else {
it++;
}
}
}
CAddrInfo CAddrMan::SelectTriedCollision_() {
if (m_tried_collisions.size() == 0) return CAddrInfo();
std::set<int>::iterator it = m_tried_collisions.begin();
// Selects a random element from m_tried_collisions
std::advance(it, GetRandInt(m_tried_collisions.size()));
int id_new = *it;
// If id_new not found in mapInfo remove it from m_tried_collisions
if (mapInfo.count(id_new) != 1) {
m_tried_collisions.erase(it);
return CAddrInfo();
}
CAddrInfo& newInfo = mapInfo[id_new];
// which tried bucket to move the entry to
int tried_bucket = newInfo.GetTriedBucket(nKey,m_asmap);
int tried_bucket_pos = newInfo.GetBucketPosition(nKey, false, tried_bucket);
int id_old = vvTried[tried_bucket][tried_bucket_pos];
return mapInfo[id_old];
}
bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
{
if (!addr.IsRoutable())

View File

@@ -1,8 +1,7 @@
// Copyright (c) 2012 Pieter Wuille
// Copyright (c) 2016-2020 The Hush developers
// Copyright (c) 2016-2021 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -31,7 +30,6 @@
#include "clientversion.h"
#include "hash.h"
#include "netbase.h"
#include <map>
#include <set>
#include <stdint.h>
@@ -43,7 +41,6 @@
class CAddrInfo : public CAddress
{
public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;
@@ -174,12 +171,18 @@ public:
//! after how many failed attempts we give up on a new node
#define ADDRMAN_RETRIES 3
//! the maximum number of tried addr collisions to store
#define ADDRMAN_SET_TRIED_COLLISION_SIZE 10
//! how many successive failures are allowed ...
#define ADDRMAN_MAX_FAILURES 10
//! ... in at least this many days
#define ADDRMAN_MIN_FAIL_DAYS 7
//! how recent a successful connection should be before we allow an address to be evicted from tried
#define ADDRMAN_REPLACEMENT_HOURS 4
//! the maximum percentage of nodes to return in a getaddr call
#define ADDRMAN_GETADDR_MAX_PCT 23
@@ -220,6 +223,12 @@ private:
//! list of "new" buckets
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
//! last time Good was called (memory only)
int64_t nLastGood;
//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discpline used to resolve these collisions.
std::set<int> m_tried_collisions;
protected:
//! secret key to randomize bucket select with
uint256 nKey;
@@ -244,7 +253,14 @@ protected:
void ClearNew(int nUBucket, int nUBucketPos);
//! Mark an entry "good", possibly moving it from "new" to "tried".
void Good_(const CService &addr, int64_t nTime);
void Good_(const CService &addr, bool test_before_evict, int64_t time);
//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
void ResolveCollisions_();
//! Return a random to-be-evicted tried table address.
CAddrInfo SelectTriedCollision_();
//! Add an entry to the "new" table.
bool Add_(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty);
@@ -583,12 +599,12 @@ public:
}
//! Mark an entry as accessible.
void Good(const CService &addr, int64_t nTime = GetTime())
void Good(const CService &addr, bool test_before_evict = true, int64_t nTime = GetTime())
{
{
LOCK(cs);
Check();
Good_(addr, nTime);
Good_(addr, test_before_evict, nTime);
Check();
}
}
@@ -604,9 +620,30 @@ public:
}
}
/**
* Choose an address to connect to.
*/
//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
void ResolveCollisions()
{
LOCK(cs);
Check();
ResolveCollisions_();
Check();
}
//! Randomly select an address in tried that another address is attempting to evict.
CAddrInfo SelectTriedCollision()
{
CAddrInfo ret;
{
LOCK(cs);
Check();
ret = SelectTriedCollision_();
Check();
}
return ret;
}
// Choose an address to connect to.
CAddrInfo Select(bool newOnly = false)
{
CAddrInfo addrRet;

View File

@@ -1,9 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin Core developers
// Copyright (c) 2016-2020 The Hush developers
// Copyright (c) 2016-2021 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -18,17 +17,14 @@
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "chainparamsbase.h"
#include "clientversion.h"
#include "rpc/client.h"
#include "rpc/protocol.h"
#include "util.h"
#include "utilstrencodings.h"
#include <boost/filesystem/operations.hpp>
#include <stdio.h>
#include <event2/buffer.h>
#include <event2/keyvalq_struct.h>
#include "support/events.h"
@@ -63,15 +59,8 @@ std::string HelpMessageCli()
return strUsage;
}
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
//
// Exception thrown on connection error. This error is used to determine
// when to wait if -rpcwait is given.
//
class CConnectionFailed : public std::runtime_error
{
public:
@@ -82,19 +71,15 @@ public:
};
//
// This function returns either one of EXIT_ codes when it's expected to stop the process or
// CONTINUE_EXECUTION when it's expected to continue further.
//
static int AppInitRPC(int argc, char* argv[])
{
static_assert(CONTINUE_EXECUTION != EXIT_FAILURE,
"CONTINUE_EXECUTION should be different from EXIT_FAILURE");
static_assert(CONTINUE_EXECUTION != EXIT_SUCCESS,
"CONTINUE_EXECUTION should be different from EXIT_SUCCESS");
//
// Parameters
//
ParseParameters(argc, argv);
std:string name;
name = GetArg("-ac_name","");
@@ -144,7 +129,6 @@ static int AppInitRPC(int argc, char* argv[])
return CONTINUE_EXECUTION;
}
/** Reply structure for request_done to fill in */
struct HTTPReply
{
@@ -277,7 +261,7 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
// Parse reply
UniValue valReply(UniValue::VSTR);
if (!valReply.read(response.body))
throw std::runtime_error("couldn't parse reply from server");
throw std::runtime_error(strprintf("couldn't parse reply from server: %s",response.body));
const UniValue& reply = valReply.get_obj();
if (reply.empty())
throw std::runtime_error("expected reply to have result, error and id properties");

View File

@@ -722,10 +722,51 @@ void *chainparams_commandline() {
(431000, uint256S("0x0000000d709ec810da6a2f55ff5d10bff9a5580ffe4fee8ce27abaf175cb6312"))
(432000, uint256S("0x000000007d91ea56e7e129991aa33e57224d0f898a5a46b02efb81f40aae5ed8"))
(433000, uint256S("0x00000009da7df1aad22c96ed458fa7feae1216811568fb0e9c2f09db25dee3f0"))
(434000, uint256S("0x0000001003f3460d4b0414f94e35025c76f72b8607e0ea00c7790e10172ef8e3")),
(int64_t) 1613879454, // time of last checkpointed block
(int64_t) 752357, // total txs
(double) 1187 // txs in the last day before block 434429
(434000, uint256S("0x0000001003f3460d4b0414f94e35025c76f72b8607e0ea00c7790e10172ef8e3"))
(435000, uint256S("0x0000001c399778d54b821c0622087149f39ee688e80bb88b6960ec6e42788918"))
(436000, uint256S("0x0000000c4e21e0ac0f9541357c1a3ce483fd2dd210874ca930dc5b271c7e6b21"))
(437000, uint256S("0x00000003ce6d4b0ea02f483633abae9da2b71e62e14e08f20af13452ab6814a7"))
(438000, uint256S("0x0000000d845b717aec3b273f9cb2d894d3caa05f91b3ad41b6581adfd90b267c"))
(439000, uint256S("0x000000099a44794ccf54bcba10780b163b6a369292263df1d8d62d2d58cc7cea"))
(440000, uint256S("0x0000000b741bda60e14a5d668581f60bfb852b09249428ca7c3a59b01db31af0"))
(441000, uint256S("0x000000150189ff4e6b3292d9feaebc1ed741a6c0534f1050cc152ad65d30906a"))
(442000, uint256S("0x0000000fd26b6822fbda02990619e1729b7f8e7cf1c39178b6040893b92a2cc9"))
(443000, uint256S("0x0000000ce6172397f985d9e3bec3d06c87d5606969a602eff9bae3a6a0e0eeae"))
(444000, uint256S("0x00000011997fb375389ecaecca589e722f9e6fbc147570cb39e88db51811d2fb"))
(445000, uint256S("0x0000000643bf6fd35088aecbebca66d313c4e153176b5da42102197164fef65c"))
(446000, uint256S("0x0000000441b5fb7d9c59fc75fb77cbf9b455dc5b4562bae0ce356500d7f422fd"))
(447000, uint256S("0x0000001978b57b5c4e49a03687a9e002a782548263918b6636cdcc36cdb11627"))
(448000, uint256S("0x0000001f1aa382c9ff75b41da17185a61db07569a4d1afa5040b836dbf7e38b0"))
(449000, uint256S("0x0000001bd53db30e282b94504a8fdb36ede55e3d3ce71336ef844df45b25d51a"))
(450000, uint256S("0x0000001648e3028682b133bc209c2538c6c776bd7d3d4b275dffef75db7bb9f4"))
(451000, uint256S("0x0000001c60e7abdebf883831bd899c5dbd8cac1ea68bb0957701e5595c8011b5"))
(452000, uint256S("0x0000000add6e6c36ec20a4e3091195c052a8f9d6498e1e85dbb10c45b70c08d3"))
(453000, uint256S("0x0000000a2bb73fff81add4d521655fe4566b6c656a9790cd2846f6f1ac7061d1"))
(454000, uint256S("0x000000059a0f7d5f1a381c20d485a1ce2bb41cfc8bc5abcbbf736a236732c3e8"))
(455000, uint256S("0x00000008542e9c1e83fdf4f71ad758ae0d372f95d486d93aaa1c448c529f1e6b"))
(456000, uint256S("0x000000093c40dcbb7152bc2561fdee97d0ddd202348db723755e8e47e10a1cf1"))
(457000, uint256S("0x000000176c7bd888c00198072ff533dd5daa7f0dd1991ee478c97ce2576a544f"))
(458000, uint256S("0x00000012f38a317148fa969062776ad7b30362b1901565f07af3045a324df8c5"))
(459000, uint256S("0x00000008f68f2b3b355f3d6c94d3eb2979e000a3817ae8089b4994d0a04ae13e"))
(460000, uint256S("0x0000001220f5bd3de5167b332268f52d056c5943b9334513d4ee138b97782759"))
(461000, uint256S("0x000000017d7c3a8b03f0b761ad56c1f6678d2642fb1d6a1a286e95fb47a43235"))
(462000, uint256S("0x00000001adb35a7234f02de06199ecd27f857b1304655ff9c37bd2c80c7e82c5"))
(463000, uint256S("0x00000015ee085765078c7c32770f4f6d8c38e25b1f16d3e4f3cea6da27a9e026"))
(464000, uint256S("0x000000165b10b74fa665df705954d8eae919bf6e8912fc8a9a4adb90179a4858"))
(465000, uint256S("0x000000051bd8d780ce69151738f6d4a81ea8b93305dd873396bff24835e9e6fb"))
(466000, uint256S("0x00000006cea7acd52ca5e0bbe0b759b5e26ee1d1f65eddd6b545020c4bd5f4a0"))
(467000, uint256S("0x00000018df5117519d46a4b825c2603927fd62a13d180474135a97af6b5a02dd"))
(468000, uint256S("0x0000000acb30c045fa367e947e1785b9bd65c06d5b67494529450f1ebff3f303"))
(469000, uint256S("0x000000097152a491ad065423de4324ada41f3612de5b80ffb585e28d2a11d2c6"))
(470000, uint256S("0x000000043ed32a85a784f1adf8328f80350b3960698c73345951d99ab369275f"))
(471000, uint256S("0x0000000dabe6173ccc2e8be79774c0aed930c8f24a311e466e543b3bbf36be3f"))
(472000, uint256S("0x0000001f727ffbe5b1ad17206c060aa77e9b20257f1764f1ac018a0f64f19bd1"))
(473000, uint256S("0x0000000b7ee1e1d0f6b577c02a924733d2c4d6d5805daa51e44e543eadacba8b"))
(474000, uint256S("0x0000001260b7935e520244a3591cb6b37de3b36c45dae5318f0bb7eda6847e17"))
(475000, uint256S("0x0000000db956f0dcecc58ccfc8463f49910d455fc3c223ab36a93c5c468513cc")),
(int64_t) 1617173192, // time of last checkpointed block
(int64_t) 809511, // total txs
(double) 3228 // txs in the last day before block 475640
};
} else {
checkpointData = //(Checkpoints::CCheckpointData)

View File

@@ -3,6 +3,7 @@
// Copyright (c) 2016-2021 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
// What happened to the SuperNET developers, who cared about privacy?
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -28,8 +29,8 @@
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
// Must be kept in sync with configure.ac , ugh!
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 6
#define CLIENT_VERSION_REVISION 3
#define CLIENT_VERSION_MINOR 7
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 50
//! Set to true for release, false for prerelease or test build

View File

@@ -1,9 +1,9 @@
// Copyright (c) 2015 The Bitcoin Core developers
// Copyright (c) 2016-2021 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "httpserver.h"
#include "chainparamsbase.h"
#include "compat.h"
#include "util.h"
@@ -12,15 +12,12 @@
#include "sync.h"
#include "ui_interface.h"
#include "utilstrencodings.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <event2/event.h>
#include <event2/http.h>
#include <event2/thread.h>
@@ -292,10 +289,11 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
if (i != iend) {
std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(hreq.release(), path, i->handler));
assert(workQueue);
if (workQueue->Enqueue(item.get()))
if (workQueue->Enqueue(item.get())) {
item.release(); /* if true, queue took ownership */
else
item->req->WriteReply(HTTP_INTERNAL, "Work queue depth exceeded");
} else {
item->req->WriteReply(HTTP_INTERNAL, strprintf("Work queue depth %d exceeded", workQueue->Depth() ));
}
} else {
hreq->WriteReply(HTTP_NOTFOUND);
}

View File

@@ -1,4 +1,5 @@
// Copyright (c) 2015 The Bitcoin Core developers
// Copyright (c) 2016-2021 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
@@ -14,7 +15,7 @@
#include <boost/scoped_ptr.hpp>
#include <boost/function.hpp>
static const int DEFAULT_HTTP_THREADS=4;
static const int DEFAULT_HTTP_THREADS=8;
static const int DEFAULT_HTTP_WORKQUEUE=16;
static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;

View File

@@ -425,8 +425,11 @@ bool TLSManager::CheckKeyCert()
return false;
}
if (wolfSSL_X509_verify(mycert, mykey) == WOLFSSL_SUCCESS) {
int err = wolfSSL_X509_verify(mycert, mykey);
if (err == WOLFSSL_SUCCESS) {
return true;
} else {
LogPrintf("%s: x509 verification error: %d = %s\n", __func__, err);
}
LogPrintf("Generated key and certificate do not match!!!\n");

View File

@@ -43,6 +43,7 @@ WOLFSSL_EVP_PKEY* GenerateEcKey(int nid)
WOLFSSL_X509* GenerateCertificate(WOLFSSL_EVP_PKEY *keypair)
{
if (!keypair) {
LogPrintf("%s: Null keypair!\n", __func__);
return NULL;
}
@@ -60,12 +61,17 @@ WOLFSSL_X509* GenerateCertificate(WOLFSSL_EVP_PKEY *keypair)
// private key from keypair is used; signature will be set inside of the cert
bCertSigned = wolfSSL_X509_sign(cert, keypair, wolfSSL_EVP_sha512());
}
} else {
LogPrintf("%s: Unable to alloc rand bytes!\n", __func__);
}
if (!bCertSigned) {
LogPrintf("%s: TLS cert not signed correctly!\n", __func__);
wolfSSL_X509_free(cert);
cert = NULL;
}
} else {
LogPrintf("%s: Unable to create x509 cert!\n", __func__);
}
return cert;

View File

@@ -3095,7 +3095,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
int32_t futureblock;
CAmount blockReward = GetBlockSubsidy(pindex->GetHeight(), chainparams.GetConsensus());
uint64_t notarypaycheque = 0;
// Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in
// Check it again to verify ztx proofs, and in case a previous version let a bad block in
if ( !CheckBlock(&futureblock,pindex->GetHeight(),pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck) || futureblock != 0 )
{
//fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock);
@@ -4968,23 +4969,32 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
assert(pindexPrev);
int nHeight = pindexPrev->GetHeight()+1;
bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false;
int daaForkHeight = GetArg("-daaforkheight", 450000);
int nHeight = pindexPrev->GetHeight()+1;
bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false;
// Check Proof-of-Work difficulty
if (ishush3) {
// The change of blocktime from 150s to 75s caused Weird Stuff in the difficulty/work calculations
// Difficulty (nBits) relies on the current blocktime of this block
if ((ASSETCHAINS_BLOCKTIME != 75) && (nHeight >= nFirstHalvingHeight)) {
LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,nHeight);
ASSETCHAINS_BLOCKTIME = 75;
hush_changeblocktime();
}
// The change of blocktime from 150s to 75s caused incorrect AWT of 34 blocks instead of 17
// caused by the fact that Difficulty Adjustment Algorithms do not take into account blocktime
// changing at run-time, which breaks assumptions in the algorithm
// changing at run-time, from Consensus::Params being a const struct
unsigned int nNextWork = GetNextWorkRequired(pindexPrev, &block, consensusParams);
//if ((nHeight < 340000 || nHeight > 342500) && block.nBits != nNextWork) {
LogPrintf("%s: nbits ,%d,%lu,%lu,%d\n",__func__, nHeight, nNextWork, block.nBits, nNextWork - block.nBits );
if (block.nBits != nNextWork) {
//cout << "Incorrect HUSH diffbits at height " << nHeight <<
// " " << block.nBits << " block.nBits vs. calc " << nNextWork <<
// " " << block.GetHash().ToString() << " @ " << block.GetBlockTime() << endl;
if (nHeight < 340000) {
return state.DoS(100, error("%s: Incorrect diffbits at height %d", __func__, nHeight), REJECT_INVALID, "bad-diffbits");
// Enforce correct nbits at DAA fork height, before that, ignore
if (nHeight > daaForkHeight) {
//cout << "Incorrect HUSH diffbits at height " << nHeight <<
// " " << block.nBits << " block.nBits vs. calc " << nNextWork <<
// " " << block.GetHash().ToString() << " @ " << block.GetBlockTime() << endl;
return state.DoS(100, error("%s: Incorrect diffbits at height %d: %lu vs %lu ", __func__, nHeight, nNextWork, block.nBits), REJECT_INVALID, "bad-diffbits");
} else {
LogPrintf("%s: Ignoring nbits calc : %lu vs block %lu\n",__func__, nNextWork, block.nBits );
cout << "Ignoring nbits for height=" << nHeight << endl;
}
}
@@ -5306,33 +5316,6 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
void hush_currentheight_set(int32_t height);
CBlockIndex *komodo_ensure(CBlock *pblock, uint256 hash)
{
CBlockIndex *pindex = 0;
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
if ( miSelf != mapBlockIndex.end() )
{
if ( (pindex = miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail
{
miSelf->second = AddToBlockIndex(*pblock);
//fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second);
}
/*if ( hash != Params().GetConsensus().hashGenesisBlock )
{
miSelf = mapBlockIndex.find(pblock->hashPrevBlock);
if ( miSelf != mapBlockIndex.end() )
{
if ( miSelf->second == 0 )
{
miSelf->second = InsertBlockIndex(pblock->hashPrevBlock);
fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str());
}
}
}*/
}
return(pindex);
}
bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp)
{
// Preliminary checks

View File

@@ -1434,6 +1434,7 @@ void ThreadOpenConnections()
}
}
// Initiate network connections
int64_t nStart = GetTime();
while (true)
@@ -1476,12 +1477,19 @@ void ThreadOpenConnections()
}
}
int64_t nANow = GetTime();
addrman.ResolveCollisions();
int nTries = 0;
while (true)
{
CAddrInfo addr = addrman.Select();
int64_t nANow = GetTime();
int nTries = 0;
while (true) {
CAddrInfo addr = addrman.SelectTriedCollision();
// SelectTriedCollision returns an invalid address if it is empty.
/* TODO: Uncomment when merged with feeler connections
if (!fFeeler || !addr.IsValid()) {
addr = addrman.Select(fFeeler);
}
*/
// if we selected an invalid address, restart
if (!addr.IsValid() || setConnected.count(addr.GetGroup(addrman.m_asmap)) || IsLocal(addr))

View File

@@ -508,13 +508,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Changing this requires changing many other things and
// changes consensus. Have fun -- Duke
int64_t AveragingWindowTimespan(int32_t height) {
int64_t AWT = 2550;
/*
int32_t forkHeight = 0;
if (height >= forkHeight) {
AWT = 1275;
}
*/
// used in const methods, beware!
// This is the correct AWT for 75s blocktime, before block 340k
// the correct value was 2550 when the blocktime was 150s
int64_t AWT = 1275;
return AWT;
}
@@ -560,11 +557,11 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
LogPrint("pow", "AveragingWindowTimespan = %d nActualTimespan = %d\n", AWT, nActualTimespan);
LogPrint("pow", "Current average: %08x %s\n", bnAvg.GetCompact(), bnAvg.ToString());
LogPrint("pow", "After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
//if(fDebug) {
if(fDebug) {
fprintf(stderr, "%s: nbits Current average: %08x %s\n", __func__, bnAvg.GetCompact(), bnAvg.ToString().c_str());
fprintf(stderr, "%s: bits After: %08x %s\n", __func__, bnNew.GetCompact(), bnNew.ToString().c_str());
fprintf(stderr,"%s: AWT=%lu ActualTimeSpan=%li MinActual=%li MaxActual=%li\n",__func__, AWT, nActualTimespan, params.MinActualTimespan(), params.MaxActualTimespan());
//}
}
return bnNew.GetCompact();
}

View File

@@ -6,7 +6,6 @@
#include "test/test_bitcoin.h"
#include <string>
#include <boost/test/unit_test.hpp>
#include "hash.h"
#include "random.h"
@@ -49,6 +48,17 @@ public:
{
CAddrMan::Delete(nId);
}
// Simulates connection failure so that we can test eviction of offline nodes
void SimConnFail(CService& addr)
{
int64_t nLastSuccess = 1;
Good_(addr, true, nLastSuccess); // Set last good connection in the deep past.
bool count_failure = false;
int64_t nLastTry = GetAdjustedTime()-61;
Attempt(addr, count_failure, nLastTry);
}
};
BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup)
@@ -519,4 +529,155 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket)
// than 64 buckets.
BOOST_CHECK(buckets.size() > 64);
}
BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
{
CAddrManTest addrman;
// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();
BOOST_CHECK(addrman.size() == 0);
// Empty addrman should return blank addrman info.
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
// Add twenty two addresses.
CNetAddr source = ResolveIP("252.2.2.2");
for (unsigned int i = 1; i < 23; i++) {
CService addr = ResolveService("250.1.1."+std::to_string(i));
addrman.Add(CAddress(addr, NODE_NONE), source);
addrman.Good(addr);
// No collisions yet.
BOOST_CHECK(addrman.size() == i);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
// Ensure Good handles duplicates well.
for (unsigned int i = 1; i < 23; i++) {
CService addr = ResolveService("250.1.1."+std::to_string(i));
addrman.Good(addr);
BOOST_CHECK(addrman.size() == 22);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
}
BOOST_AUTO_TEST_CASE(addrman_noevict)
{
CAddrManTest addrman;
// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();
// Add twenty two addresses.
CNetAddr source = ResolveIP("252.2.2.2");
for (unsigned int i = 1; i < 23; i++) {
CService addr = ResolveService("250.1.1."+std::to_string(i));
addrman.Add(CAddress(addr, NODE_NONE), source);
addrman.Good(addr);
// No collision yet.
BOOST_CHECK(addrman.size() == i);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
// Collision between 23 and 19.
CService addr23 = ResolveService("250.1.1.23");
addrman.Add(CAddress(addr23, NODE_NONE), source);
addrman.Good(addr23);
BOOST_CHECK(addrman.size() == 23);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "250.1.1.19:0");
// 23 should be discarded and 19 not evicted.
addrman.ResolveCollisions();
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
// Lets create two collisions.
for (unsigned int i = 24; i < 33; i++) {
CService addr = ResolveService("250.1.1."+std::to_string(i));
addrman.Add(CAddress(addr, NODE_NONE), source);
addrman.Good(addr);
BOOST_CHECK(addrman.size() == i);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
// Cause a collision.
CService addr33 = ResolveService("250.1.1.33");
addrman.Add(CAddress(addr33, NODE_NONE), source);
addrman.Good(addr33);
BOOST_CHECK(addrman.size() == 33);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "250.1.1.27:0");
// Cause a second collision.
addrman.Add(CAddress(addr23, NODE_NONE), source);
addrman.Good(addr23);
BOOST_CHECK(addrman.size() == 33);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() != "[::]:0");
addrman.ResolveCollisions();
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
BOOST_AUTO_TEST_CASE(addrman_evictionworks)
{
CAddrManTest addrman;
// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();
BOOST_CHECK(addrman.size() == 0);
// Empty addrman should return blank addrman info.
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
// Add twenty two addresses.
CNetAddr source = ResolveIP("252.2.2.2");
for (unsigned int i = 1; i < 23; i++) {
CService addr = ResolveService("250.1.1."+std::to_string(i));
addrman.Add(CAddress(addr, NODE_NONE), source);
addrman.Good(addr);
// No collision yet.
BOOST_CHECK(addrman.size() == i);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
// Collision between 23 and 19.
CService addr = ResolveService("250.1.1.23");
addrman.Add(CAddress(addr, NODE_NONE), source);
addrman.Good(addr);
BOOST_CHECK(addrman.size() == 23);
CAddrInfo info = addrman.SelectTriedCollision();
BOOST_CHECK(info.ToString() == "250.1.1.19:0");
// Ensure test of address fails, so that it is evicted.
addrman.SimConnFail(info);
// Should swap 23 for 19.
addrman.ResolveCollisions();
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
// If 23 was swapped for 19, then this should cause no collisions.
addrman.Add(CAddress(addr, NODE_NONE), source);
addrman.Good(addr);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
// If we insert 19 is should collide with 23.
CService addr19 = ResolveService("250.1.1.19");
addrman.Add(CAddress(addr19, NODE_NONE), source);
addrman.Good(addr19);
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "250.1.1.23:0");
addrman.ResolveCollisions();
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
}
BOOST_AUTO_TEST_SUITE_END()