Skip to content

Write to disk on next block after tip disconnected #244

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion src/fluxnode/fluxnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class FluxnodeCacheData {

// New nType Version Checker
if ((nType&FLUXNODE_TX_TYPE_UPGRADED) == FLUXNODE_TX_TYPE_UPGRADED) {
LogPrintf("FLUXNODE_TX_TYPE_UPGRADED Found %d - %s - nType = %d - TX-Type (%d), result = %d\n", __LINE__, __func__, nType, FLUXNODE_TX_TYPE_UPGRADED, nType ^ FLUXNODE_TX_TYPE_UPGRADED);
READWRITE(nFluxTxVersion);
READWRITE(nTransactionType);
// Normal and P2SH data share most fields so for now we can just check at the end for P2SH
Expand Down
15 changes: 11 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ size_t nCoinCacheUsage = 5000 * 300;
uint64_t nPruneTarget = 0;
bool fAlerts = DEFAULT_ALERTS;
bool fIsVerifying = false;
bool fJustDisconnectedTip = false;
/* 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;
Expand Down Expand Up @@ -1425,9 +1426,6 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
}

if (tx.IsFluxnodeTx()) {
if (tx.nVersion == FLUXNODE_TX_UPGRADEABLE_VERSION) {
LogPrintf("Found a upgraded TX --------------------------------\n");
}
// Check type of fluxnode tx
if (tx.nType != FLUXNODE_START_TX_TYPE && tx.nType != FLUXNODE_CONFIRM_TX_TYPE)
return state.DoS(10, error("CheckTransaction(): Is Fluxnode Tx, bad type"),
Expand Down Expand Up @@ -3934,10 +3932,14 @@ bool static DisconnectTip(CValidationState &state, const CChainParams& chainpara
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
uint256 sproutAnchorAfterDisconnect = pcoinsTip->GetBestAnchor(SPROUT);
uint256 saplingAnchorAfterDisconnect = pcoinsTip->GetBestAnchor(SAPLING);

// Write the chain state to disk, if necessary.
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
return false;

// Tracking when recently disconnecting the tip of the chain.
fJustDisconnectedTip = true;

if (!fBare) {
// Resurrect mempool transactions from the disconnected block.
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
Expand Down Expand Up @@ -4056,9 +4058,14 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
}
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);

// Write the chain state to disk, if necessary.
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
// If fJustDisconnectedTip force a disk write
if (!FlushStateToDisk(state, fJustDisconnectedTip ? FLUSH_STATE_ALWAYS : FLUSH_STATE_IF_NEEDED))
return false;

fJustDisconnectedTip = false;

int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
// Remove conflicting transactions from the mempool.
Expand Down
3 changes: 2 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ extern uint64_t nPruneTarget;
/** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of chainActive.Tip() will not be pruned. */
static const unsigned int MIN_BLOCKS_TO_KEEP = 288;


// Track when the chain disconnects from the tip
extern bool fJustDisconnectedTip;

// Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
// At 1MB per block, 288 blocks = 288MB.
Expand Down
1 change: 0 additions & 1 deletion src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ class CTransaction
UpdateHash();
return;
} else if (nVersion == FLUXNODE_TX_UPGRADEABLE_VERSION) { // Support P2SH and Normal Fluxnode Tx
LogPrintf("FLUXNODE_TX_UPGRADEABLE_VERSION Found------------------------- %d\n", nVersion);
READWRITE(*const_cast<int8_t*>(&nType)); // Start, Confirm

if (nType == FLUXNODE_START_TX_TYPE) {
Expand Down
2 changes: 1 addition & 1 deletion src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
}

if (origTx.IsFluxnodeTx()) {
LogPrint("fluxnode", "%s: Remove fluxnode tx from mempool %s\n", __func__, origTx.GetHash().GetHex());
LogPrint("dfluxnode", "%s: Remove fluxnode tx from mempool %s\n", __func__, origTx.GetHash().GetHex());
mapFluxnodeTxMempool.erase(origTx.collateralIn);
}
}
Expand Down