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

refactor: small cleanup #2123

Merged
merged 5 commits into from
May 12, 2021
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 contrib/devtools/circular-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def module_name(path):
files = dict()
deps = dict()

RE = re.compile("^#include <(.*)>")
RE = re.compile("^#include [<\"](.*)[\">]")

# Iterate over files, and create list of modules
for arg in sys.argv[1:]:
Expand Down
27 changes: 14 additions & 13 deletions contrib/devtools/copyright_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def compile_copyright_regex(copyright_style, year_style, name):
r"Intel Corporation ?",
r"The Zcash developers",
r"Jeremy Rubin",
r"The Gridcoin developers",
]

DOMINANT_STYLE_COMPILED = {}
Expand Down Expand Up @@ -336,7 +337,7 @@ def write_file_lines(filename, file_lines):
COPYRIGHT = r'Copyright \(c\)'
YEAR = "20[0-9][0-9]"
YEAR_RANGE = '(%s)(-%s)?' % (YEAR, YEAR)
HOLDER = 'The Bitcoin Core developers'
HOLDER = 'The Gridcoin developers'
UPDATEABLE_LINE_COMPILED = re.compile(' '.join([COPYRIGHT, YEAR_RANGE, HOLDER]))

def get_updatable_copyright_line(file_lines):
Expand Down Expand Up @@ -401,24 +402,24 @@ def exec_update_header_year(base_directory):
################################################################################

UPDATE_USAGE = """
Updates all the copyright headers of "The Bitcoin Core developers" which were
Updates all the copyright headers of "The Gridcoin developers" which were
changed in a year more recent than is listed. For example:

// Copyright (c) <firstYear>-<lastYear> The Bitcoin Core developers
// Copyright (c) <firstYear>-<lastYear> The Gridcoin developers

will be updated to:

// Copyright (c) <firstYear>-<lastModifiedYear> The Bitcoin Core developers
// Copyright (c) <firstYear>-<lastModifiedYear> The Gridcoin developers

where <lastModifiedYear> is obtained from the 'git log' history.

This subcommand also handles copyright headers that have only a single year. In those cases:

// Copyright (c) <year> The Bitcoin Core developers
// Copyright (c) <year> The Gridcoin developers

will be updated to:

// Copyright (c) <year>-<lastModifiedYear> The Bitcoin Core developers
// Copyright (c) <year>-<lastModifiedYear> The Gridcoin developers

where the update is appropriate.

Expand Down Expand Up @@ -451,7 +452,7 @@ def get_header_lines(header, start_year, end_year):
return [line + '\n' for line in lines]

CPP_HEADER = '''
// Copyright (c) %s The Bitcoin Core developers
// Copyright (c) %s The Gridcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
'''
Expand All @@ -460,7 +461,7 @@ def get_cpp_header_lines_to_insert(start_year, end_year):
return reversed(get_header_lines(CPP_HEADER, start_year, end_year))

SCRIPT_HEADER = '''
# Copyright (c) %s The Bitcoin Core developers
# Copyright (c) %s The Gridcoin developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
'''
Expand Down Expand Up @@ -515,7 +516,7 @@ def insert_cpp_header(filename, file_lines, start_year, end_year):
def exec_insert_header(filename, style):
file_lines = read_file_lines(filename)
if file_already_has_core_copyright(file_lines):
sys.exit('*** %s already has a copyright by The Bitcoin Core developers'
sys.exit('*** %s already has a copyright by The Gridcoin developers'
% (filename))
start_year, end_year = get_git_change_year_range(filename)
if style in ['python', 'shell']:
Expand All @@ -528,7 +529,7 @@ def exec_insert_header(filename, style):
################################################################################

INSERT_USAGE = """
Inserts a copyright header for "The Bitcoin Core developers" at the top of the
Inserts a copyright header for "The Gridcoin developers" at the top of the
file in either Python or C++ style as determined by the file extension. If the
file is a Python file and it has a '#!' starting the first line, the header is
inserted in the line below it.
Expand All @@ -542,7 +543,7 @@ def exec_insert_header(filename, style):

"<current_year>"

If the file already has a copyright for "The Bitcoin Core developers", the
If the file already has a copyright for "The Gridcoin developers", the
script will exit.

Usage:
Expand Down Expand Up @@ -576,8 +577,8 @@ def insert_cmd(argv):
################################################################################

USAGE = """
copyright_header.py - utilities for managing copyright headers of 'The Bitcoin
Core developers' in repository source files.
copyright_header.py - utilities for managing copyright headers of 'The Gridcoin
developers' in repository source files.

Usage:
$ ./copyright_header <subcommand>
Expand Down
8 changes: 4 additions & 4 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <addrdb.h>

#include <addrman.h>
// #include <chainparams.h>
#include <chainparams.h>
// #include <clientversion.h>
#include <hash.h>
// #include <random.h>
Expand All @@ -26,8 +26,8 @@ bool SerializeDB(Stream& stream, const Data& data)
// Write and commit header, data
try {
CHashWriter hasher(SER_DISK, CLIENT_VERSION);
stream << pchMessageStart << data;
hasher << pchMessageStart << data;
stream << Params().MessageStart() << data;
hasher << Params().MessageStart() << data;
stream << hasher.GetHash();
} catch (const std::exception& e) {
return error("%s: Serialize or I/O error - %s", __func__, e.what());
Expand Down Expand Up @@ -85,7 +85,7 @@ bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
unsigned char pchMsgTmp[4];
verifier >> pchMsgTmp;
// ... verify the network matches ours
if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
return error("%s: Invalid network magic number", __func__);

// de-serialize data
Expand Down
31 changes: 5 additions & 26 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ std::string msMiningErrorsExcluded;

//When syncing, we grandfather block rejection rules up to this block, as rules became stricter over time and fields changed
int nGrandfather = 1034700;
int nNewIndex = 271625;
int nNewIndex2 = 364500;

int64_t nGenesisSupply = 340569880;

Expand Down Expand Up @@ -2755,16 +2753,10 @@ bool LoadBlockIndex(bool fAllowNew)
if (fTestNet)
{
// GLOBAL TESTNET SETTINGS - R HALFORD
pchMessageStart[0] = 0xcd;
pchMessageStart[1] = 0xf2;
pchMessageStart[2] = 0xc0;
pchMessageStart[3] = 0xef;
bnProofOfWorkLimit = bnProofOfWorkLimitTestNet; // 16 bits PoW target limit for testnet
nStakeMinAge = 1 * 60 * 60; // test net min age is 1 hour
nCoinbaseMaturity = 10; // test maturity is 10 blocks
nGrandfather = 196550;
nNewIndex = 10;
nNewIndex2 = 36500;
//1-24-2016
MAX_OUTBOUND_CONNECTIONS = (int)GetArg("-maxoutboundconnections", 8);
}
Expand Down Expand Up @@ -2976,18 +2968,18 @@ bool LoadExternalBlockFile(FILE* fileIn)
nPos = (unsigned int)-1;
break;
}
void* nFind = memchr(pchData, pchMessageStart[0], nRead+1-sizeof(pchMessageStart));
void* nFind = memchr(pchData, Params().MessageStart()[0], nRead + 1 - CMessageHeader::MESSAGE_START_SIZE);
if (nFind)
{
if (memcmp(nFind, pchMessageStart, sizeof(pchMessageStart))==0)
if (memcmp(nFind, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE) == 0)
{
nPos += ((unsigned char*)nFind - pchData) + sizeof(pchMessageStart);
nPos += ((unsigned char*)nFind - pchData) + CMessageHeader::MESSAGE_START_SIZE;
break;
}
nPos += ((unsigned char*)nFind - pchData) + 1;
}
else
nPos += sizeof(pchData) - sizeof(pchMessageStart) + 1;
nPos += sizeof(pchData) - CMessageHeader::MESSAGE_START_SIZE + 1;
} while(!fRequestShutdown);
if (nPos == (unsigned int)-1)
break;
Expand Down Expand Up @@ -3099,25 +3091,12 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
}




// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
unsigned char pchMessageStart[4] = { 0x70, 0x35, 0x22, 0x05 };

bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived)
{
RandAddSeedPerfmon();

LogPrint(BCLog::LogFlags::NOISY, "received: %s from %s (%" PRIszu " bytes)", strCommand, pfrom->addrName, vRecv.size());

if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
LogPrintf("dropmessagestest DROPPING RECV MESSAGE");
return true;
}

if (strCommand == "aries")
{
// Each connection can only send one version message
Expand Down Expand Up @@ -3926,7 +3905,7 @@ bool ProcessMessages(CNode* pfrom)
it++;

// Scan for message start
if (memcmp(msg.hdr.pchMessageStart, pchMessageStart, sizeof(pchMessageStart)) != 0) {
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
LogPrint(BCLog::LogFlags::NOISY, "PROCESSMESSAGE: INVALID MESSAGESTART");
fOk = false;
break;
Expand Down
7 changes: 2 additions & 5 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ extern CBlockIndex* pindexBest;
extern const std::string strMessageMagic;
extern CCriticalSection cs_setpwalletRegistered;
extern std::set<CWallet*> setpwalletRegistered;
extern unsigned char pchMessageStart[4];
extern std::map<uint256, CBlock*> mapOrphanBlocks;

// Settings
Expand All @@ -108,8 +107,6 @@ extern std::string msMiningErrorsIncluded;
extern std::string msMiningErrorsExcluded;

extern int nGrandfather;
extern int nNewIndex;
extern int nNewIndex2;

class GlobalStatus
{
Expand Down Expand Up @@ -506,7 +503,7 @@ class CBlock : public CBlockHeader

// Write index header
unsigned int nSize = GetSerializeSize(fileout, *this);
fileout << pchMessageStart << nSize;
fileout << Params().MessageStart() << nSize;

// Write block
long fileOutPos = ftell(fileout.Get());
Expand Down Expand Up @@ -943,7 +940,7 @@ class CDiskBlockIndex : public CBlockIndex
uint32_t is_superblock = this->IsSuperblock();
uint32_t is_contract = this->IsContract();

if (this->nHeight > nNewIndex2) {
if (IsResearchAgeEnabled(this->nHeight)) {
READWRITE(is_superblock);
READWRITE(is_contract);

Expand Down
7 changes: 0 additions & 7 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,6 @@ class CNode

void EndMessage()
{
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
LogPrintf("dropmessages DROPPING SEND MESSAGE");
AbortMessage();
return;
}

if (ssSend.size() == 0)
return;

Expand Down
7 changes: 4 additions & 3 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "chainparams.h"
#include "netbase.h"
#include "protocol.h"
#include "util.h"
Expand All @@ -22,15 +23,15 @@ static const char* ppszTypeName[] =

CMessageHeader::CMessageHeader()
{
memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
memcpy(pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE);
memset(pchCommand, 0, sizeof(pchCommand));
nMessageSize = -1;
memset(pchChecksum, 0, CHECKSUM_SIZE);
}

CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn)
{
memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
memcpy(pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE);

// Copy the command name, zero-padding to COMMAND_SIZE bytes
size_t i = 0;
Expand All @@ -53,7 +54,7 @@ std::string CMessageHeader::GetCommand() const
bool CMessageHeader::IsValid() const
{
// Check start string
if (memcmp(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)) != 0)
if (memcmp(pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0)
return false;

// Check the command string for errors
Expand Down
2 changes: 0 additions & 2 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
}


extern unsigned char pchMessageStart[4];

/** Message header.
* (4) message start.
* (12) command.
Expand Down