Skip to content

Commit

Permalink
Merge pull request #406 from HorizenOfficial/AddressIndexing_development
Browse files Browse the repository at this point in the history
  • Loading branch information
cronicc committed Nov 17, 2021
2 parents e3328e3 + 3ade793 commit 0c55780
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Zen 3.0.0-bitcore
Zen 3.0.1-bitcore
================
What is Horizen?
----------------
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 3)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 50)
define(_ZC_BUILD_VAL, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD), m4_eval(_CLIENT_VERSION_BUILD < 50), 1, m4_eval(_CLIENT_VERSION_BUILD - 24), m4_eval(_CLIENT_VERSION_BUILD == 50), 1, , m4_eval(_CLIENT_VERSION_BUILD - 50)))
define(_CLIENT_VERSION_SUFFIX, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, _CLIENT_VERSION_REVISION-beta$1, m4_eval(_CLIENT_VERSION_BUILD < 50), 1, _CLIENT_VERSION_REVISION-rc$1, m4_eval(_CLIENT_VERSION_BUILD == 50), 1, _CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION-$1)))
Expand Down
4 changes: 2 additions & 2 deletions doc/authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Horizen Contributors

Jack Grigg (778)
abi87 (686)
Alberto Sala (594)
Alberto Sala (596)
Simon Liu (338)
cronicc (270)
cronicc (273)
FranckDG (219)
Sean Bowe (204)
Daira Hopwood (142)
Expand Down
6 changes: 3 additions & 3 deletions doc/man/zen-cli.1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.3.
.TH ZEN-CLI "1" "November 2021" "zen-cli v3.0.0" "User Commands"
.TH ZEN-CLI "1" "November 2021" "zen-cli v3.0.1" "User Commands"
.SH NAME
zen-cli \- manual page for zen-cli v3.0.0
zen-cli \- manual page for zen-cli v3.0.1
.SH DESCRIPTION
Horizen RPC client version v3.0.0
Horizen RPC client version v3.0.1
.SS "Usage:"
.TP
zen\-cli [options] <command> [params]
Expand Down
6 changes: 3 additions & 3 deletions doc/man/zen-tx.1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.3.
.TH ZEN-TX "1" "November 2021" "zen-tx v3.0.0" "User Commands"
.TH ZEN-TX "1" "November 2021" "zen-tx v3.0.1" "User Commands"
.SH NAME
zen-tx \- manual page for zen-tx v3.0.0
zen-tx \- manual page for zen-tx v3.0.1
.SH DESCRIPTION
Horizen zen\-tx utility version v3.0.0
Horizen zen\-tx utility version v3.0.1
.SS "Usage:"
.TP
zen\-tx [options] <hex\-tx> [commands]
Expand Down
8 changes: 4 additions & 4 deletions doc/man/zend.1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.3.
.TH ZEND "1" "November 2021" "zend v3.0.0" "User Commands"
.TH ZEND "1" "November 2021" "zend v3.0.1" "User Commands"
.SH NAME
zend \- manual page for zend v3.0.0
zend \- manual page for zend v3.0.1
.SH DESCRIPTION
Zen Daemon version v3.0.0
Zen Daemon version v3.0.1
.SS "Usage:"
.TP
zend [options]
Expand Down Expand Up @@ -51,7 +51,7 @@ Specify data directory
\fB\-disabledeprecation=\fR<version>
.IP
Disable block\-height node deprecation and automatic shutdown (example:
\fB\-disabledeprecation\fR=\fI\,3\/\fR.0.0)
\fB\-disabledeprecation\fR=\fI\,3\/\fR.0.1)
.HP
\fB\-exportdir=\fR<dir>
.IP
Expand Down
12 changes: 12 additions & 0 deletions doc/release-notes/release-notes-3.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Changelog
=========

Alberto Sala (2):
Added a check on data read in txindex serializer; added indexVersion string in DB
Added constant string definitions for indexVersion; optimized serializer for txindex

cronicc (3):
Set version to 3.0.1
Set version in readme
Update manpages

2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 50

//! Set to true for release, false for prerelease or test build
Expand Down
32 changes: 26 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,12 +1632,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}

// Check that -txindex is enabled when -maturityheightindex is enabled
if (fMaturityHeightIndex && !fTxIndex) {
strLoadError = _("You need to enable -txindex in order to use -maturityheightindex");
break;
}

// read the version of the txindexing related version
std::string indexVersionStr = DEFAULT_INDEX_VERSION_STR;
pblocktree->ReadString("indexVersion", indexVersionStr);
LogPrintf("%s: indexVersion %s\n", __func__, indexVersionStr);

#ifdef ENABLE_ADDRESS_INDEXING
// Check for changed -addressindex state
if (fAddressIndex != GetBoolArg("-addressindex", false)) {
Expand All @@ -1650,8 +1649,29 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
strLoadError = _("You need to enable -txindex in order to use -addressindex");
break;
}

if (fAddressIndex && indexVersionStr == DEFAULT_INDEX_VERSION_STR) {
strLoadError = _("You need to reindex in order to use -addressindex");
break;
}
#endif // ENABLE_ADDRESS_INDEXING

if (fMaturityHeightIndex && indexVersionStr == DEFAULT_INDEX_VERSION_STR)
{
indexVersionStr = CURRENT_INDEX_VERSION_STR;
pblocktree->WriteString("indexVersion", indexVersionStr);

std::string dum;
pblocktree->ReadString("indexVersion", dum);
LogPrintf("%s: indexVersion %s\n", __func__, dum);
}

// Check that -txindex is enabled when -maturityheightindex is enabled
if (fMaturityHeightIndex && !fTxIndex) {
strLoadError = _("You need to enable -txindex in order to use -maturityheightindex");
break;
}

// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
// in the past, but is now trying to run unpruned.
if (fHavePruned && !fPruneMode) {
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5845,7 +5845,13 @@ bool InitBlockIndex() {

// Check whether we're already initialized
if (chainActive.Genesis() != NULL)
{
return true;
}

// set the flag upon db initialization
std::string indexVersionStr = CURRENT_INDEX_VERSION_STR;
pblocktree->WriteString("indexVersion", indexVersionStr);

// Use the provided setting for -txindex in the new database
fTxIndex = GetBoolArg("-txindex", false);
Expand Down
10 changes: 10 additions & 0 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,16 @@ bool CBlockTreeDB::blockOnchainActive(const uint256 &hash) {
}
#endif // ENABLE_ADDRESS_INDEXING

bool CBlockTreeDB::WriteString(const std::string &name, std::string sValue) {
return Write(std::make_pair(DB_FLAG, name), sValue);
}

bool CBlockTreeDB::ReadString(const std::string &name, std::string &sValue) {
if (!Read(std::make_pair(DB_FLAG, name), sValue))
return false;
return true;
}

bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) {
return Write(std::make_pair(DB_FLAG, name), fValue ? '1' : '0');
}
Expand Down
23 changes: 19 additions & 4 deletions src/txdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
//! min. -dbcache in (MiB)
static const int64_t nMinDbCache = 4;

static const std::string DEFAULT_INDEX_VERSION_STR = "0.0";
static const std::string CURRENT_INDEX_VERSION_STR = "1.0";

struct CDiskTxPos : public CDiskBlockPos
{
unsigned int nTxOffset; // after header
Expand Down Expand Up @@ -84,10 +87,20 @@ struct CTxIndexValue {
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(txPosition);
READWRITE(VARINT(txIndex));

// Since the maturity can be negative, we have to manipulate it to store the sign bit in a VARINT
READWRITE_VARINT_WITH_SIGN(maturityHeight);

if (ser_action.ForRead() && (s.size() == 0))
{
// can happen when we are reading old records in txindex db
// we have completed the stream buffer, set remaining values to default
txIndex = 0;
maturityHeight = 0;
}
else
{
READWRITE(VARINT(txIndex));
// Since the maturity can be negative, we have to manipulate it to store the sign bit in a VARINT
READWRITE_VARINT_WITH_SIGN(maturityHeight);
}
}

CTxIndexValue(const CDiskTxPos& txPos, int txIdx, int maturity) {
Expand Down Expand Up @@ -184,6 +197,8 @@ class CBlockTreeDB : public CLevelDBWrapper

bool WriteFlag(const std::string &name, bool fValue);
bool ReadFlag(const std::string &name, bool &fValue);
bool WriteString(const std::string &name, std::string fValue);
bool ReadString(const std::string &name, std::string &fValue);
bool LoadBlockIndexGuts();
};

Expand Down

0 comments on commit 0c55780

Please sign in to comment.