Browse Source

Refactor z2z and additionally set ac_private=1 when loading block index from disk

This should avoid the edge case when a node starts up after the z2z block height but
has not yet seen a new block and so does not yet know it is an -ac_private=1 chain,
as currently that is set in ConnectBlock.
pull/100/head
Duke Leto 4 years ago
parent
commit
41a4c84633
  1. 18
      src/main.cpp

18
src/main.cpp

@ -114,6 +114,8 @@ bool fAlerts = DEFAULT_ALERTS;
/* If the tip is older than this (in seconds), the node is considered to be in initial block download.
*/
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
bool ishush3 = strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0 ? true : false;
unsigned int z2zForkHeight = 340000;
unsigned int expiryDelta = DEFAULT_TX_EXPIRY_DELTA;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
@ -1742,14 +1744,12 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
{
AssertLockHeld(cs_main);
uint32_t z2zTransitionWindow = 10;
uint32_t z2zTransitionStart = 340000 - z2zTransitionWindow;
uint32_t z2zTransitionEnd = 340000;
bool ishush3 = strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0 ? true : false;
uint32_t nHeight = chainActive.Height();
uint32_t z2zTransitionStart = z2zForkHeight - z2zTransitionWindow;
uint32_t nHeight = chainActive.Height();
// This only applies to HUSH3, other chains can start off z2z via ac_private=1
if(ishush3) {
if((nHeight >= z2zTransitionStart) || (nHeight <= z2zTransitionEnd)) {
if((nHeight >= z2zTransitionStart) || (nHeight <= z2zForkHeight)) {
// During the z2z transition window, only coinbase tx's as part of blocks are allowed
// Theory: We want an empty mempool at our fork block height, and the only way to assure that
// is to have an empty mempool for a few previous blocks, to take care of potential re-orgs
@ -3371,7 +3371,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
bool ishush3 = strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0 ? true : false;
if(!ASSETCHAINS_PRIVATE && ishush3) {
unsigned int z2zForkHeight = 340000;
unsigned int nHeight = pindex->GetHeight();
if(nHeight >= z2zForkHeight) {
// At startup, HUSH3 doesn't know a block height yet and so we must wait until
@ -6338,6 +6337,13 @@ bool static LoadBlockIndexDB()
chainActive.SetTip(it->second);
// Try to detect if we are z2z based on height of blocks on disk
// This helps to set it correctly on startup before a new block is connected
if(ishush3 && chainActive.Height() >= z2zForkHeight) {
LogPrintf("%s: enabled ac_private=1 at height=%d\n", __func__, chainActive.Height());
ASSETCHAINS_PRIVATE = 1;
}
// Set hashFinalSproutRoot for the end of best chain
it->second->hashFinalSproutRoot = pcoinsTip->GetBestAnchor(SPROUT);

Loading…
Cancel
Save