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

Cleanup old quorum contributions #419

Open
wants to merge 1 commit into
base: develop
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: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,7 @@ bool AppInitMain(const util::Ref &context, NodeContext &node, interfaces::BlockA
if (fSmartnodeMode) {
node.scheduler->scheduleEvery(
std::bind(&CCoinJoinServer::DoMaintenance, std::ref(coinJoinServer), std::ref(*node.connman)), 1000);
node.scheduler->scheduleEvery(&llmq::DoMaintenance, 3600000); // run every 1 hours
#ifdef ENABLE_WALLET
} else if(CCoinJoinClientOptions::IsEnabled()) {
node.scheduler->scheduleEvery(std::bind(&DoCoinJoinMaintenance, std::ref(*node.connman)), 1000);
Expand Down
44 changes: 44 additions & 0 deletions src/llmq/quorums_dkgsessionmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,48 @@ namespace llmq {
return sporkManager.IsSporkActive(SPORK_17_QUORUM_DKG_ENABLED);
}

void CDKGSessionManager::CleanupOldContributions() const
{
if (db->IsEmpty()) {
return;
}

const auto prefixes = {DB_VVEC, DB_SKCONTRIB, DB_ENC_CONTRIB, DB_NODE_VOTE};

for (const auto& p : Params().GetConsensus().llmqs) {
auto& params = p.second;
LogPrint(BCLog::LLMQ, "CDKGSessionManager::%s -- looking for old entries for llmq type %d\n", __func__, params.type);

CDBBatch batch(*db);
size_t cnt_old{0}, cnt_all{0};
for (const auto& prefix : prefixes) {
std::unique_ptr<CDBIterator> pcursor(db->NewIterator());
auto start = std::make_tuple(prefix, params.type, uint256(), uint256());
decltype(start) k;

pcursor->Seek(start);
LOCK(cs_main);
while (pcursor->Valid() || std::get<0>(k) != prefix || std::get<1>(k) != params.type) {
if (!pcursor->GetKey(k)) {
break;
}
cnt_all++;
const CBlockIndex* pindexQuorum = LookupBlockIndex(std::get<2>(k));
if (pindexQuorum == nullptr || ::ChainActive().Tip()->nHeight - pindexQuorum->nHeight > params.max_store_depth()) {
// not found or too old
batch.Erase(k);
cnt_old++;
}
pcursor->Next();
}
pcursor.reset();
}
LogPrint(BCLog::LLMQ, "CDKGSessionManager::%s -- found %lld entries for llmq type %d\n", __func__, cnt_all, uint8_t(params.type));
if (cnt_old > 0) {
db->WriteBatch(batch);
LogPrint(BCLog::LLMQ, "CDKGSessionManager::%s -- removed %lld old entries for llmq type %d\n", __func__, cnt_old, uint8_t(params.type));
}
}
}

} // namespace llmq
2 changes: 2 additions & 0 deletions src/llmq/quorums_dkgsessionmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace llmq {
const CBlockIndex *pQuorumBaseBlockIndex,
const uint256 &proTxHash,
const uint32_t& updateVote);

void CleanupOldContributions() const;

private:
void MigrateDKG();
Expand Down
6 changes: 6 additions & 0 deletions src/llmq/quorums_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ namespace llmq {
}
}

void DoMaintenance() {
if (quorumDKGSessionManager != nullptr) {
quorumDKGSessionManager->CleanupOldContributions();
}
}

} // namespace llmq
2 changes: 2 additions & 0 deletions src/llmq/quorums_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace llmq {
void StopLLMQSystem();

void InterruptLLMQSystem();

void DoMaintenance();
} // namespace llmq

#endif //RAPTOREUM_QUORUMS_INIT_H
30 changes: 30 additions & 0 deletions src/llmq/quorums_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,21 @@ namespace Consensus {
// should be at least one more then the active quorums set.
int keepOldConnections;

// The number of quorums for which we should keep keys. Usually it's equal to signingActiveQuorumCount * 2.
// Unlike for other quorum types we want to keep data (secret key shares and vvec)
// for Platform quorums for much longer because Platform can be restarted and
// it must be able to re-sign stuff.

int keepOldKeys;

// How many members should we try to send all sigShares to before we give up.
int recoveryMembers;
public:
// For how many blocks recent DKG info should be kept
[[ nodiscard ]] constexpr int max_store_depth() const
{
return keepOldKeys * dkgInterval;
}
};

static constexpr LLMQParams
Expand All @@ -112,6 +125,7 @@ namespace Consensus {
.signingActiveQuorumCount = 2, // just a few ones to allow easier testing

.keepOldConnections = 3,
.keepOldKeys = 4,
.recoveryMembers = 3,
};

Expand All @@ -132,6 +146,7 @@ namespace Consensus {
.signingActiveQuorumCount = 2, // just a few ones to allow easier testing

.keepOldConnections = 3,
.keepOldKeys = 4,
.recoveryMembers = 3,
};

Expand All @@ -152,6 +167,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // two days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 5,
};

Expand All @@ -172,6 +188,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // four days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 5,
};

Expand All @@ -192,6 +209,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // two days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 5,
};

Expand All @@ -212,6 +230,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // four days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 5,
};

Expand All @@ -232,6 +251,7 @@ namespace Consensus {
.signingActiveQuorumCount = 6, // just a few ones to allow easier testing

.keepOldConnections = 7,
.keepOldKeys = 12,
.recoveryMembers = 7,
};

Expand All @@ -252,6 +272,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // two days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 5,
};

Expand All @@ -272,6 +293,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // four days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 5,
};

Expand All @@ -292,6 +314,7 @@ namespace Consensus {
.signingActiveQuorumCount = 24, // a full day worth of LLMQs

.keepOldConnections = 25,
.keepOldKeys = 48,
.recoveryMembers = 25,
};

Expand All @@ -312,6 +335,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // two days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 100,
};

Expand All @@ -333,6 +357,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // four days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 100,
};

Expand All @@ -353,6 +378,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // two days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 50,
};

Expand All @@ -375,6 +401,7 @@ namespace Consensus {
.signingActiveQuorumCount = 4, // four days worth of LLMQs

.keepOldConnections = 5,
.keepOldKeys = 8,
.recoveryMembers = 50,
};

Expand All @@ -396,6 +423,7 @@ namespace Consensus {
.signingActiveQuorumCount = 2, // just a few ones to allow easier testing

.keepOldConnections = 3,
.keepOldKeys = 4,
.recoveryMembers = 3,
};

Expand All @@ -416,6 +444,7 @@ namespace Consensus {
.signingActiveQuorumCount = 24, // a full day worth of LLMQs

.keepOldConnections = 25,
.keepOldKeys = 48,
.recoveryMembers = 50,
};

Expand All @@ -437,6 +466,7 @@ namespace Consensus {
.signingActiveQuorumCount = 24, // a full day worth of LLMQs

.keepOldConnections = 25,
.keepOldKeys = 48,
.recoveryMembers = 50,
};

Expand Down
Loading