forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.cpp
More file actions
1496 lines (1444 loc) · 57.7 KB
/
interfaces.cpp
File metadata and controls
1496 lines (1444 loc) · 57.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2018-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <interfaces/node.h>
#include <addrdb.h>
#include <banman.h>
#include <blockfilter.h>
#include <chain.h>
#include <chainlock/chainlock.h>
#include <chainparams.h>
#include <coinjoin/common.h>
#include <deploymentstatus.h>
#include <evo/chainhelper.h>
#include <evo/creditpool.h>
#include <evo/deterministicmns.h>
#include <governance/classes.h>
#include <governance/exceptions.h>
#include <external_signer.h>
#include <governance/governance.h>
#include <governance/object.h>
#include <governance/vote.h>
#include <index/blockfilterindex.h>
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/coinjoin.h>
#include <interfaces/handler.h>
#include <interfaces/wallet.h>
#include <instantsend/instantsend.h>
#include <llmq/commitment.h>
#include <llmq/context.h>
#include <llmq/options.h>
#include <llmq/quorums.h>
#include <llmq/quorumsman.h>
#include <mapport.h>
#include <masternode/sync.h>
#include <net.h>
#include <net_processing.h>
#include <netaddress.h>
#include <netbase.h>
#include <node/blockstorage.h>
#include <node/coin.h>
#include <node/context.h>
#include <node/interface_ui.h>
#include <node/transaction.h>
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/settings.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <rpc/protocol.h>
#include <rpc/server.h>
#include <rpc/server_util.h>
#include <shutdown.h>
#include <support/allocators/secure.h>
#include <sync.h>
#include <txmempool.h>
#include <uint256.h>
#include <util/check.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
#include <warnings.h>
#include <governance/validators.h>
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <coinjoin/coinjoin.h>
#include <coinjoin/options.h>
#include <univalue.h>
#include <boost/signals2/signal.hpp>
#include <memory>
#include <optional>
#include <utility>
#include <variant>
using interfaces::BlockTip;
using interfaces::Chain;
using interfaces::EVO;
using interfaces::FoundBlock;
using interfaces::GOV;
using interfaces::Handler;
using interfaces::LLMQ;
using interfaces::MakeHandler;
using interfaces::MnEntry;
using interfaces::MnEntryCPtr;
using interfaces::MnList;
using interfaces::MnListPtr;
using interfaces::Node;
using interfaces::WalletLoader;
namespace node {
namespace {
class MnEntryImpl : public MnEntry
{
private:
CDeterministicMNCPtr m_dmn;
public:
MnEntryImpl(const CDeterministicMNCPtr& dmn) :
MnEntry{dmn},
m_dmn{Assert(dmn)}
{
}
~MnEntryImpl() = default;
bool isBanned() const override { return m_dmn->pdmnState->IsBanned(); }
CService getNetInfoPrimary() const override { return m_dmn->pdmnState->netInfo->GetPrimary(); }
MnType getType() const override { return m_dmn->nType; }
UniValue toJson() const override { return m_dmn->ToJson(); }
const CKeyID& getKeyIdOwner() const override { return m_dmn->pdmnState->keyIDOwner; }
const CKeyID& getKeyIdVoting() const override { return m_dmn->pdmnState->keyIDVoting; }
const COutPoint& getCollateralOutpoint() const override { return m_dmn->collateralOutpoint; }
const CScript& getScriptPayout() const override { return m_dmn->pdmnState->scriptPayout; }
const CScript& getScriptOperatorPayout() const override { return m_dmn->pdmnState->scriptOperatorPayout; }
const int32_t& getLastPaidHeight() const override { return m_dmn->pdmnState->nLastPaidHeight; }
const int32_t& getPoSePenalty() const override { return m_dmn->pdmnState->nPoSePenalty; }
const int32_t& getRegisteredHeight() const override { return m_dmn->pdmnState->nRegisteredHeight; }
const uint16_t& getOperatorReward() const override { return m_dmn->nOperatorReward; }
const uint256& getProTxHash() const override { return m_dmn->proTxHash; }
};
class MnListImpl : public MnList
{
private:
CDeterministicMNList m_list;
public:
MnListImpl(const CDeterministicMNList& mn_list) :
MnList{mn_list},
m_list{mn_list}
{
}
~MnListImpl() = default;
Counts getCounts() const override
{
const auto counts{m_list.GetCounts()};
return {
.m_total_evo = counts.m_total_evo,
.m_total_mn = counts.m_total_mn,
.m_total_weighted = counts.m_total_weighted,
.m_valid_evo = counts.m_valid_evo,
.m_valid_mn = counts.m_valid_mn,
.m_valid_weighted = counts.m_valid_weighted,
};
}
int32_t getHeight() const override { return m_list.GetHeight(); }
uint256 getBlockHash() const override { return m_list.GetBlockHash(); }
void forEachMN(bool only_valid, std::function<void(const MnEntryCPtr&)> cb) const override
{
m_list.ForEachMNShared(only_valid, [&cb](const auto& dmn) {
cb(std::make_shared<const MnEntryImpl>(dmn));
});
}
std::vector<MnEntryCPtr> getProjectedMNPayees(const CBlockIndex* pindex) const override
{
std::vector<MnEntryCPtr> ret;
for (const auto& payee : m_list.GetProjectedMNPayees(pindex)) {
ret.emplace_back(std::make_shared<const MnEntryImpl>(payee));
}
return ret;
}
void setContext(NodeContext* context) override
{
m_context = context;
}
private:
// Note: Currently we do nothing with m_context but in the future, if we have a hard fork
// that requires checking for deployment information in deterministic masternode logic,
// we will need NodeContext::chainman. This has been kept around to retain those code
// paths.
[[maybe_unused]] NodeContext* m_context{nullptr};
};
class EVOImpl : public EVO
{
private:
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
NodeContext& context() { return *Assert(m_context); }
public:
std::pair<MnListPtr, const CBlockIndex*> getListAtChainTip() override
{
const auto *tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip());
if (tip && context().dmnman) {
MnListImpl mnList = context().dmnman->GetListForBlock(tip);
if (!mnList.getBlockHash().IsNull()) {
mnList.setContext(m_context);
return {std::make_shared<MnListImpl>(mnList), tip};
}
}
return {nullptr, nullptr};
}
void setContext(NodeContext* context) override
{
m_context = context;
}
private:
NodeContext* m_context{nullptr};
};
class GOVImpl : public GOV
{
private:
NodeContext& context() { return *Assert(m_context); }
public:
void getAllNewerThan(std::vector<CGovernanceObject> &objs, int64_t nMoreThanTime,
bool include_postponed) override
{
if (context().govman != nullptr) {
context().govman->GetAllNewerThan(objs, nMoreThanTime, include_postponed);
}
}
Votes getObjVotes(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) override
{
Votes ret;
if (context().govman != nullptr && context().dmnman != nullptr) {
const auto& tip_mn_list{context().dmnman->GetListAtChainTip()};
if (auto govobj{context().govman->FindGovernanceObject(obj.GetHash())}) {
ret.m_abs = govobj->GetAbstainCount(tip_mn_list, vote_signal);
ret.m_no = govobj->GetNoCount(tip_mn_list, vote_signal);
ret.m_yes = govobj->GetYesCount(tip_mn_list, vote_signal);
} else {
ret.m_abs = obj.GetAbstainCount(tip_mn_list, vote_signal);
ret.m_no = obj.GetNoCount(tip_mn_list, vote_signal);
ret.m_yes = obj.GetYesCount(tip_mn_list, vote_signal);
}
}
return ret;
}
UniqueVoters getObjUniqueVoters(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) override
{
if (context().govman != nullptr && context().dmnman != nullptr) {
const auto& tip_mn_list{context().dmnman->GetListAtChainTip()};
if (auto govobj{context().govman->FindGovernanceObject(obj.GetHash())}) {
const auto count = govobj->GetUniqueVoterCount(tip_mn_list, vote_signal);
return {.m_regular = count.m_regular, .m_evo = count.m_evo};
} else {
const auto count = obj.GetUniqueVoterCount(tip_mn_list, vote_signal);
return {.m_regular = count.m_regular, .m_evo = count.m_evo};
}
}
return {0, 0};
}
bool existsObj(const uint256& hash) override
{
if (context().govman != nullptr) {
return context().govman->HaveObjectForHash(hash);
}
return false;
}
bool isEnabled() override
{
if (context().govman != nullptr) {
return context().govman->IsValid();
}
return false;
}
bool processVoteAndRelay(const CGovernanceVote& vote, std::string& error) override
{
if (context().govman != nullptr && context().connman != nullptr) {
CGovernanceException exception;
bool result = context().govman->ProcessVoteAndRelay(vote, exception, *context().connman);
if (!result) {
error = exception.GetMessage();
}
return result;
}
error = "Governance manager not available";
return false;
}
GovernanceInfo getGovernanceInfo() override
{
GovernanceInfo info;
const Consensus::Params& consensusParams = Params().GetConsensus();
if (context().chainman) {
LOCK(::cs_main);
CSuperblock::GetNearestSuperblocksHeights(context().chainman->ActiveHeight(), info.lastsuperblock, info.nextsuperblock);
info.governancebudget = CSuperblock::GetPaymentsLimit(context().chainman->ActiveChain(), info.nextsuperblock);
if (context().dmnman) {
info.fundingthreshold = static_cast<int>(context().dmnman->GetListAtChainTip().GetCounts().m_valid_weighted / 10);
}
}
info.proposalfee = GOVERNANCE_PROPOSAL_FEE_TX;
info.superblockcycle = consensusParams.nSuperblockCycle;
info.superblockmaturitywindow = consensusParams.nSuperblockMaturityWindow;
info.targetSpacing = consensusParams.nPowTargetSpacing;
info.relayRequiredConfs = GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS;
info.requiredConfs = GOVERNANCE_FEE_CONFIRMATIONS;
return info;
}
std::optional<int32_t> getProposalFundedHeight(const uint256& proposal_hash) override
{
if (context().govman != nullptr && context().chainman != nullptr) {
const int32_t nTipHeight = context().chainman->ActiveHeight();
for (const auto& trigger : context().govman->GetActiveTriggers()) {
if (!trigger || trigger->GetBlockHeight() > nTipHeight) continue;
for (const auto& hash : trigger->GetProposalHashes()) {
if (hash == proposal_hash) {
return trigger->GetBlockHeight();
}
}
}
}
return std::nullopt;
}
FundableResult getFundableProposalHashes() override
{
FundableResult result;
if (context().govman != nullptr && context().chainman != nullptr && context().dmnman != nullptr) {
const auto tip_mn_list{context().dmnman->GetListAtChainTip()};
if (const auto proposals{context().govman->GetApprovedProposals(tip_mn_list)}; !proposals.empty()) {
int32_t last_sb{0}, next_sb{0};
CSuperblock::GetNearestSuperblocksHeights(context().chainman->ActiveHeight(), last_sb, next_sb);
const CAmount budget{CSuperblock::GetPaymentsLimit(context().chainman->ActiveChain(), next_sb)};
for (const auto& proposal : proposals) {
UniValue json = proposal->GetJSONObject();
CAmount payment_amount{0};
try {
payment_amount = ParsePaymentAmount(json["payment_amount"].getValStr());
} catch (...) {
continue;
}
if (result.allocated + payment_amount > budget) {
// Budget is saturated, cannot fulfill proposal
continue;
}
result.allocated += payment_amount;
result.hashes.insert(proposal->GetHash());
}
return result;
}
}
return result;
}
std::optional<CGovernanceObject> createProposal(int32_t revision, int64_t created_time,
const std::string& data_hex, std::string& error) override
{
CGovernanceObject govobj(uint256{}, revision, created_time, uint256{}, data_hex);
if (govobj.GetObjectType() != GovernanceObject::PROPOSAL) {
error = "Invalid object type, only proposals can be validated";
return std::nullopt;
}
CProposalValidator validator(data_hex);
if (!validator.Validate()) {
error = "Invalid proposal data: " + validator.GetErrorMessages();
return std::nullopt;
}
const ChainstateManager& chainman = *Assert(context().chainman);
{
LOCK(::cs_main);
std::string strError;
if (!govobj.IsValidLocally(Assert(context().dmnman)->GetListAtChainTip(), chainman, strError, false)) {
error = "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError;
return std::nullopt;
}
}
return govobj;
}
bool submitProposal(const uint256& parent, int32_t revision, int64_t created_time, const std::string& data_hex,
const uint256& fee_txid, std::string& out_object_hash, std::string& error) override
{
if (!context().govman || !context().dmnman || !context().chainman) { error = "Governance not available"; return false; }
if(!Assert(context().mn_sync)->IsBlockchainSynced()) { error = "Client not synced"; return false; }
const auto mnList = Assert(context().dmnman)->GetListAtChainTip();
CGovernanceObject govobj(parent, revision, created_time, fee_txid, data_hex);
if (govobj.GetObjectType() == GovernanceObject::TRIGGER) { error = "Submission of triggers is not available"; return false; }
if (govobj.GetObjectType() == GovernanceObject::PROPOSAL) {
CProposalValidator validator(data_hex);
if (!validator.Validate()) { error = "Invalid proposal data: " + validator.GetErrorMessages(); return false; }
}
const CTxMemPool& mempool = *Assert(context().mempool);
bool fMissingConfirmations{false};
{
LOCK2(cs_main, mempool.cs);
std::string strError;
if (!govobj.IsValidLocally(mnList, *Assert(context().chainman), strError, fMissingConfirmations, true) && !fMissingConfirmations) {
error = "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError;
return false;
}
}
if (!Assert(context().govman)->MasternodeRateCheck(govobj)) { error = "Object creation rate limit exceeded"; return false; }
if (fMissingConfirmations) {
context().govman->AddPostponedObject(govobj);
context().govman->RelayObject(govobj);
} else {
context().govman->AddGovernanceObject(govobj);
}
out_object_hash = govobj.GetHash().ToString();
return true;
}
void setContext(NodeContext* context) override
{
m_context = context;
}
private:
NodeContext* m_context{nullptr};
};
class LLMQImpl : public LLMQ
{
private:
NodeContext& context() { return *Assert(m_context); }
public:
CreditPoolCounts getCreditPoolCounts() override
{
CreditPoolCounts ret{};
if (!context().chainman) {
return ret;
}
const auto* pindex{WITH_LOCK(::cs_main, return context().chainman->ActiveChain().Tip())};
if (!pindex || !pindex->pprev) {
return ret;
}
auto& chain_helper{context().chainman->ActiveChainstate().ChainHelper()};
const auto pool{chain_helper.GetCreditPool(pindex)};
ret.m_locked = pool.locked;
ret.m_limit = pool.currentLimit;
ret.m_diff = pool.locked - chain_helper.GetCreditPool(pindex->pprev).locked;
return ret;
}
ChainLockInfo getBestChainLock() override
{
if (!context().chainlocks) {
return {};
}
const auto [clsig, pindex] = context().chainlocks->GetBestChainlockWithPindex();
if (!pindex) {
return {};
}
return {
.m_height = clsig.getHeight(),
.m_block_time = pindex->GetBlockTime(),
.m_hash = clsig.getBlockHash(),
};
}
InstantSendCounts getInstantSendCounts() override
{
if (!context().llmq_ctx || !context().llmq_ctx->isman) {
return {};
}
const auto counts{context().llmq_ctx->isman->GetCounts()};
return {
.m_verified = counts.m_verified,
.m_unverified = counts.m_unverified,
.m_awaiting_tx = counts.m_awaiting_tx,
.m_unprotected_tx = counts.m_unprotected_tx,
};
}
size_t getPendingAssetUnlocks() override
{
if (!context().mempool) {
return 0;
}
LOCK(context().mempool->cs);
return static_cast<size_t>(ranges::count_if(context().mempool->mapTx, [](const auto& entry) {
return entry.GetTx().IsPlatformTransfer();
}));
}
std::vector<QuorumInfo> getQuorumStats() override
{
std::vector<QuorumInfo> stats{};
if (!context().llmq_ctx || !context().llmq_ctx->qman || !context().chainman) {
return stats;
}
const auto* pindex{WITH_LOCK(::cs_main, return context().chainman->ActiveChain().Tip())};
if (!pindex) {
return stats;
}
for (const auto& type : llmq::GetEnabledQuorumTypes(*context().chainman, pindex)) {
const auto llmq_params{Params().GetLLMQ(type)};
if (!llmq_params.has_value()) {
continue;
}
const auto quorums{context().llmq_ctx->qman->ScanQuorums(type, pindex, llmq_params->signingActiveQuorumCount)};
double health{0.0};
for (const auto& q : quorums) {
size_t numMembers = q->members.size();
size_t numValidMembers = q->qc->CountValidMembers();
health += (numMembers > 0) ? (double(numValidMembers) / double(numMembers)) : 0.0;
}
health = quorums.empty() ? 0.0 : (health / quorums.size());
const int32_t newest_height{(!quorums.empty() && quorums[0]->m_quorum_base_block_index)
? quorums[0]->m_quorum_base_block_index->nHeight : 0};
const int32_t expiry_height{(newest_height > 0)
? newest_height + llmq_params->signingActiveQuorumCount * llmq_params->dkgInterval
: 0};
stats.emplace_back(QuorumInfo{
.m_name = std::string(llmq_params->name),
.m_count = quorums.size(),
.m_health = health,
.m_rotates = llmq_params->useRotation,
.m_data_retention_blocks = llmq_params->max_store_depth(),
.m_newest_height = newest_height,
.m_expiry_height = expiry_height,
});
}
return stats;
}
void setContext(NodeContext* context) override
{
m_context = context;
}
private:
NodeContext* m_context{nullptr};
};
namespace Masternode = interfaces::Masternode;
class MasternodeSyncImpl : public Masternode::Sync
{
private:
NodeContext& context() { return *Assert(m_context); }
public:
bool isSynced() override
{
if (context().mn_sync != nullptr) {
return context().mn_sync->IsSynced();
}
return false;
}
bool isBlockchainSynced() override
{
if (context().mn_sync != nullptr) {
return context().mn_sync->IsBlockchainSynced();
}
return false;
}
bool isGovernanceSynced() override
{
if (context().mn_sync != nullptr) {
return context().mn_sync->GetAssetID() > MASTERNODE_SYNC_GOVERNANCE;
}
return false;
}
std::string getSyncStatus() override
{
if (context().mn_sync != nullptr) {
return context().mn_sync->GetSyncStatus();
}
return "";
}
void setContext(NodeContext* context) override
{
m_context = context;
}
private:
NodeContext* m_context{nullptr};
};
namespace CoinJoin = interfaces::CoinJoin;
class CoinJoinOptionsImpl : public CoinJoin::Options
{
public:
int getSessions() override
{
return CCoinJoinClientOptions::GetSessions();
}
int getRounds() override
{
return CCoinJoinClientOptions::GetRounds();
}
int getAmount() override
{
return CCoinJoinClientOptions::GetAmount();
}
int getDenomsGoal() override
{
return CCoinJoinClientOptions::GetDenomsGoal();
}
int getDenomsHardCap() override
{
return CCoinJoinClientOptions::GetDenomsHardCap();
}
void setEnabled(bool fEnabled) override
{
return CCoinJoinClientOptions::SetEnabled(fEnabled);
}
void setMultiSessionEnabled(bool fEnabled) override
{
CCoinJoinClientOptions::SetMultiSessionEnabled(fEnabled);
}
void setSessions(int sessions) override
{
CCoinJoinClientOptions::SetSessions(sessions);
}
void setRounds(int nRounds) override
{
CCoinJoinClientOptions::SetRounds(nRounds);
}
void setAmount(CAmount amount) override
{
CCoinJoinClientOptions::SetAmount(amount);
}
void setDenomsGoal(int denoms_goal) override
{
CCoinJoinClientOptions::SetDenomsGoal(denoms_goal);
}
void setDenomsHardCap(int denoms_hardcap) override
{
CCoinJoinClientOptions::SetDenomsHardCap(denoms_hardcap);
}
bool isEnabled() override
{
return CCoinJoinClientOptions::IsEnabled();
}
bool isMultiSessionEnabled() override
{
return CCoinJoinClientOptions::IsMultiSessionEnabled();
}
bool isCollateralAmount(CAmount nAmount) override
{
return ::CoinJoin::IsCollateralAmount(nAmount);
}
CAmount getMinCollateralAmount() override
{
return ::CoinJoin::GetCollateralAmount();
}
CAmount getMaxCollateralAmount() override
{
return ::CoinJoin::GetMaxCollateralAmount();
}
CAmount getSmallestDenomination() override
{
return ::CoinJoin::GetSmallestDenomination();
}
bool isDenominated(CAmount nAmount) override
{
return ::CoinJoin::IsDenominatedAmount(nAmount);
}
std::array<CAmount, 5> getStandardDenominations() override
{
return ::CoinJoin::GetStandardDenominations();
}
};
#ifdef ENABLE_EXTERNAL_SIGNER
class ExternalSignerImpl : public interfaces::ExternalSigner
{
public:
ExternalSignerImpl(::ExternalSigner signer) : m_signer(std::move(signer)) {}
std::string getName() override { return m_signer.m_name; }
private:
::ExternalSigner m_signer;
};
#endif
class NodeImpl : public Node
{
private:
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
public:
EVOImpl m_evo;
GOVImpl m_gov;
LLMQImpl m_llmq;
MasternodeSyncImpl m_masternodeSync;
CoinJoinOptionsImpl m_coinjoin;
explicit NodeImpl(NodeContext& context) { setContext(&context); }
void initLogging() override { InitLogging(*Assert(m_context->args)); }
void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); }
bilingual_str getWarnings() override { return GetWarnings(true); }
uint64_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
bool baseInitialize() override
{
return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(gArgs) && AppInitSanityChecks() &&
AppInitLockDataDirectory() && AppInitInterfaces(*m_context);
}
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
{
return AppInitMain(*m_context, tip_info);
}
void appShutdown() override
{
Interrupt(*m_context);
Shutdown(*m_context);
}
void appPrepareShutdown() override
{
Interrupt(*m_context);
StartRestart();
PrepareShutdown(*m_context);
}
void startShutdown() override
{
StartShutdown();
// Stop RPC for clean shutdown if any of waitfor* commands is executed.
if (gArgs.GetBoolArg("-server", false)) {
InterruptRPC();
StopRPC();
}
}
bool shutdownRequested() override { return ShutdownRequested(); }
bool isSettingIgnored(const std::string& name) override
{
bool ignored = false;
gArgs.LockSettings([&](util::Settings& settings) {
if (auto* options = util::FindKey(settings.command_line_options, name)) {
ignored = !options->empty();
}
});
return ignored;
}
util::SettingsValue getPersistentSetting(const std::string& name) override { return gArgs.GetPersistentSetting(name); }
void updateRwSetting(const std::string& name, const util::SettingsValue& value) override
{
gArgs.LockSettings([&](util::Settings& settings) {
if (value.isNull()) {
settings.rw_settings.erase(name);
} else {
settings.rw_settings[name] = value;
}
});
gArgs.WriteSettingsFile();
}
void forceSetting(const std::string& name, const util::SettingsValue& value) override
{
gArgs.LockSettings([&](util::Settings& settings) {
if (value.isNull()) {
settings.forced_settings.erase(name);
} else {
settings.forced_settings[name] = value;
}
});
}
void resetSettings() override
{
gArgs.WriteSettingsFile(/*errors=*/nullptr, /*backup=*/true);
gArgs.LockSettings([&](util::Settings& settings) {
settings.rw_settings.clear();
});
gArgs.WriteSettingsFile();
}
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
bool getProxy(Network net, Proxy& proxy_info) override { return GetProxy(net, proxy_info); }
size_t getNodeCount(ConnectionDirection flags) override
{
return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
}
bool getNodesStats(NodesStats& stats) override
{
stats.clear();
if (m_context->connman) {
std::vector<CNodeStats> stats_temp;
m_context->connman->GetNodeStats(stats_temp);
stats.reserve(stats_temp.size());
for (auto& node_stats_temp : stats_temp) {
stats.emplace_back(std::move(node_stats_temp), false, CNodeStateStats());
}
// Try to retrieve the CNodeStateStats for each node.
if (m_context->peerman) {
TRY_LOCK(::cs_main, lockMain);
if (lockMain) {
for (auto& node_stats : stats) {
std::get<1>(node_stats) =
m_context->peerman->GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats));
}
}
}
return true;
}
return false;
}
bool getBanned(banmap_t& banmap) override
{
if (m_context->banman) {
m_context->banman->GetBanned(banmap);
return true;
}
return false;
}
bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) override
{
if (m_context->banman) {
m_context->banman->Ban(net_addr, ban_time_offset);
return true;
}
return false;
}
bool unban(const CSubNet& ip) override
{
if (m_context->banman) {
m_context->banman->Unban(ip);
return true;
}
return false;
}
bool disconnectByAddress(const CNetAddr& net_addr) override
{
if (m_context->connman) {
return m_context->connman->DisconnectNode(net_addr);
}
return false;
}
bool disconnectById(NodeId id) override
{
if (m_context->connman) {
return m_context->connman->DisconnectNode(id);
}
return false;
}
std::vector<std::unique_ptr<interfaces::ExternalSigner>> listExternalSigners() override
{
#ifdef ENABLE_EXTERNAL_SIGNER
std::vector<ExternalSigner> signers = {};
const std::string command = gArgs.GetArg("-signer", "");
if (command == "") return {};
ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;
for (auto& signer : signers) {
result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));
}
return result;
#else
// This result is indistinguishable from a successful call that returns
// no signers. For the current GUI this doesn't matter, because the wallet
// creation dialog disables the external signer checkbox in both
// cases. The return type could be changed to std::optional<std::vector>
// (or something that also includes error messages) if this distinction
// becomes important.
return {};
#endif // ENABLE_EXTERNAL_SIGNER
}
int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }
int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
size_t getMempoolMaxUsage() override { return gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; }
bool getHeaderTip(int& height, int64_t& block_time) override
{
LOCK(::cs_main);
auto best_header = chainman().m_best_header;
if (best_header) {
height = best_header->nHeight;
block_time = best_header->GetBlockTime();
return true;
}
return false;
}
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
{
if (m_context->connman)
return m_context->connman->getNetLocalAddresses();
else
return {};
}
int getNumBlocks() override
{
LOCK(::cs_main);
return chainman().ActiveChain().Height();
}
uint256 getBestBlockHash() override
{
const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip());
return tip ? tip->GetBlockHash() : Params().GenesisBlock().GetHash();
}
int64_t getLastBlockTime() override
{
LOCK(::cs_main);
if (chainman().ActiveChain().Tip()) {
return chainman().ActiveChain().Tip()->GetBlockTime();
}
return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
}
std::string getLastBlockHash() override
{
LOCK(::cs_main);
if (m_context->chainman->ActiveChain().Tip()) {
return m_context->chainman->ActiveChain().Tip()->GetBlockHash().ToString();
}
return Params().GenesisBlock().GetHash().ToString(); // Genesis block's hash of current network
}
double getVerificationProgress() override
{
const CBlockIndex* tip;
{
LOCK(::cs_main);
tip = chainman().ActiveChain().Tip();
}
return GuessVerificationProgress(Params().TxData(), tip);
}
bool isInitialBlockDownload() override {
return chainman().ActiveChainstate().IsInitialBlockDownload();
}
bool isMasternode() override
{
return m_context->active_ctx != nullptr;
}
bool isLoadingBlocks() override { return node::fReindex || node::fImporting; }
void setNetworkActive(bool active) override
{
if (m_context->connman) {
m_context->connman->SetNetworkActive(active, m_context->mn_sync.get());
}
}
bool getNetworkActive() override { return m_context->connman && m_context->connman->GetNetworkActive(); }
CFeeRate getDustRelayFee() override { return ::dustRelayFee; }
UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
{
JSONRPCRequest req;
req.context = *m_context;
req.params = params;
req.strMethod = command;
req.URI = uri;
return ::tableRPC.execute(req);
}
std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }
void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); }
void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); }
bool getUnspentOutput(const COutPoint& output, Coin& coin) override
{
LOCK(::cs_main);
return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin);
}
TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, bilingual_str& err_string) override
{
return BroadcastTransaction(*m_context, std::move(tx), err_string, max_tx_fee, /*relay=*/ true, /*wait_callback=*/ false);
}
WalletLoader& walletLoader() override
{
return *Assert(m_context->wallet_loader);
}
EVO& evo() override { return m_evo; }
GOV& gov() override { return m_gov; }
LLMQ& llmq() override { return m_llmq; }
Masternode::Sync& masternodeSync() override { return m_masternodeSync; }
CoinJoin::Options& coinJoinOptions() override { return m_coinjoin; }
std::unique_ptr<interfaces::CoinJoin::Loader>& coinJoinLoader() override { return m_context->coinjoin_loader; }
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
{
return MakeHandler(::uiInterface.InitMessage_connect(fn));
}
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
{
return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn));
}
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
{
return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn));
}
std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
{
return MakeHandler(::uiInterface.ShowProgress_connect(fn));
}
std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override
{
return MakeHandler(::uiInterface.InitWallet_connect(fn));
}
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
{
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
}
std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
{
return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn));
}
std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
{
return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn));
}
std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
{
return MakeHandler(::uiInterface.BannedListChanged_connect(fn));
}
std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
{
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()},
GuessVerificationProgress(Params().TxData(), block));
}));
}
std::unique_ptr<Handler> handleNotifyChainLock(NotifyChainLockFn fn) override
{
return MakeHandler(::uiInterface.NotifyChainLock_connect([fn](const std::string& bestChainLockHash, int bestChainLockHeight) {