@@ -55,7 +55,7 @@ RCLConsensus::RCLConsensus(
55
55
LedgerMaster& ledgerMaster,
56
56
LocalTxs& localTxs,
57
57
InboundTransactions& inboundTransactions,
58
- Consensus<Adaptor>::clock_type const & clock,
58
+ Consensus<Adaptor>::clock_type& clock,
59
59
ValidatorKeys const & validatorKeys,
60
60
beast::Journal journal)
61
61
: adaptor_(
@@ -171,6 +171,9 @@ RCLConsensus::Adaptor::share(RCLCxPeerPos const& peerPos)
171
171
auto const sig = peerPos.signature ();
172
172
prop.set_signature (sig.data (), sig.size ());
173
173
174
+ if (proposal.ledgerSeq ().has_value ())
175
+ prop.set_ledgerseq (*proposal.ledgerSeq ());
176
+
174
177
app_.overlay ().relay (prop, peerPos.suppressionID (), peerPos.publicKey ());
175
178
}
176
179
@@ -180,7 +183,7 @@ RCLConsensus::Adaptor::share(RCLCxTx const& tx)
180
183
// If we didn't relay this transaction recently, relay it to all peers
181
184
if (app_.getHashRouter ().shouldRelay (tx.id ()))
182
185
{
183
- JLOG (j_.debug ()) << " Relaying disputed tx " << tx.id ();
186
+ JLOG (j_.trace ()) << " Relaying disputed tx " << tx.id ();
184
187
auto const slice = tx.tx_ ->slice ();
185
188
protocol::TMTransaction msg;
186
189
msg.set_rawtransaction (slice.data (), slice.size ());
@@ -192,13 +195,13 @@ RCLConsensus::Adaptor::share(RCLCxTx const& tx)
192
195
}
193
196
else
194
197
{
195
- JLOG (j_.debug ()) << " Not relaying disputed tx " << tx.id ();
198
+ JLOG (j_.trace ()) << " Not relaying disputed tx " << tx.id ();
196
199
}
197
200
}
198
201
void
199
202
RCLConsensus::Adaptor::propose (RCLCxPeerPos::Proposal const & proposal)
200
203
{
201
- JLOG (j_.trace ()) << (proposal.isBowOut () ? " We bow out: " : " We propose: " )
204
+ JLOG (j_.debug ()) << (proposal.isBowOut () ? " We bow out: " : " We propose: " )
202
205
<< ripple::to_string (proposal.prevLedger ()) << " -> "
203
206
<< ripple::to_string (proposal.position ());
204
207
@@ -212,6 +215,7 @@ RCLConsensus::Adaptor::propose(RCLCxPeerPos::Proposal const& proposal)
212
215
prop.set_closetime (proposal.closeTime ().time_since_epoch ().count ());
213
216
prop.set_nodepubkey (
214
217
validatorKeys_.publicKey .data (), validatorKeys_.publicKey .size ());
218
+ prop.set_ledgerseq (*proposal.ledgerSeq ());
215
219
216
220
auto sig = signDigest (
217
221
validatorKeys_.publicKey ,
297
301
RCLConsensus::Adaptor::onClose (
298
302
RCLCxLedger const & ledger,
299
303
NetClock::time_point const & closeTime,
300
- ConsensusMode mode) -> Result
304
+ ConsensusMode mode,
305
+ clock_type& clock) -> Result
301
306
{
302
307
const bool wrongLCL = mode == ConsensusMode::wrongLedger;
303
308
const bool proposing = mode == ConsensusMode::proposing;
@@ -379,7 +384,6 @@ RCLConsensus::Adaptor::onClose(
379
384
380
385
// Needed because of the move below.
381
386
auto const setHash = initialSet->getHash ().as_uint256 ();
382
-
383
387
return Result{
384
388
std::move (initialSet),
385
389
RCLCxPeerPos::Proposal{
@@ -388,7 +392,9 @@ RCLConsensus::Adaptor::onClose(
388
392
setHash,
389
393
closeTime,
390
394
app_.timeKeeper ().closeTime (),
391
- validatorKeys_.nodeID }};
395
+ validatorKeys_.nodeID ,
396
+ initialLedger->info ().seq ,
397
+ clock }};
392
398
}
393
399
394
400
void
@@ -400,50 +406,43 @@ RCLConsensus::Adaptor::onForceAccept(
400
406
ConsensusMode const & mode,
401
407
Json::Value&& consensusJson)
402
408
{
403
- doAccept (
404
- result,
405
- prevLedger,
406
- closeResolution,
407
- rawCloseTimes,
408
- mode,
409
- std::move (consensusJson));
409
+ auto txsBuilt = buildAndValidate (
410
+ result, prevLedger, closeResolution, mode, std::move (consensusJson));
411
+ prepareOpenLedger (std::move (txsBuilt), result, rawCloseTimes, mode);
410
412
}
411
413
412
414
void
413
415
RCLConsensus::Adaptor::onAccept (
414
416
Result const & result,
415
- RCLCxLedger const & prevLedger,
416
- NetClock::duration const & closeResolution,
417
417
ConsensusCloseTimes const & rawCloseTimes,
418
418
ConsensusMode const & mode,
419
- Json::Value&& consensusJson)
419
+ Json::Value&& consensusJson,
420
+ std::pair<CanonicalTxSet_t, Ledger_t>&& tb)
420
421
{
421
422
app_.getJobQueue ().addJob (
422
423
jtACCEPT,
423
424
" acceptLedger" ,
424
- [=, this , cj = std::move (consensusJson)]() mutable {
425
+ [=,
426
+ this ,
427
+ cj = std::move (consensusJson),
428
+ txsBuilt = std::move (tb)]() mutable {
425
429
// Note that no lock is held or acquired during this job.
426
430
// This is because generic Consensus guarantees that once a ledger
427
431
// is accepted, the consensus results and capture by reference state
428
432
// will not change until startRound is called (which happens via
429
433
// endConsensus).
430
- this ->doAccept (
431
- result,
432
- prevLedger,
433
- closeResolution,
434
- rawCloseTimes,
435
- mode,
436
- std::move (cj));
434
+ prepareOpenLedger (std::move (txsBuilt), result, rawCloseTimes, mode);
437
435
this ->app_ .getOPs ().endConsensus ();
438
436
});
439
437
}
440
438
441
- void
442
- RCLConsensus::Adaptor::doAccept (
439
+ std::pair<
440
+ RCLConsensus::Adaptor::CanonicalTxSet_t,
441
+ RCLConsensus::Adaptor::Ledger_t>
442
+ RCLConsensus::Adaptor::buildAndValidate (
443
443
Result const & result,
444
- RCLCxLedger const & prevLedger,
445
- NetClock::duration closeResolution,
446
- ConsensusCloseTimes const & rawCloseTimes,
444
+ Ledger_t const & prevLedger,
445
+ NetClock::duration const & closeResolution,
447
446
ConsensusMode const & mode,
448
447
Json::Value&& consensusJson)
449
448
{
@@ -497,12 +496,12 @@ RCLConsensus::Adaptor::doAccept(
497
496
{
498
497
retriableTxs.insert (
499
498
std::make_shared<STTx const >(SerialIter{item.slice ()}));
500
- JLOG (j_.debug ()) << " Tx: " << item.key ();
499
+ JLOG (j_.trace ()) << " Tx: " << item.key ();
501
500
}
502
501
catch (std::exception const & ex)
503
502
{
504
503
failed.insert (item.key ());
505
- JLOG (j_.warn ())
504
+ JLOG (j_.trace ())
506
505
<< " Tx: " << item.key () << " throws: " << ex.what ();
507
506
}
508
507
}
@@ -579,6 +578,19 @@ RCLConsensus::Adaptor::doAccept(
579
578
ledgerMaster_.consensusBuilt (
580
579
built.ledger_ , result.txns .id (), std::move (consensusJson));
581
580
581
+ return {retriableTxs, built};
582
+ }
583
+
584
+ void
585
+ RCLConsensus::Adaptor::prepareOpenLedger (
586
+ std::pair<CanonicalTxSet_t, Ledger_t>&& txsBuilt,
587
+ Result const & result,
588
+ ConsensusCloseTimes const & rawCloseTimes,
589
+ ConsensusMode const & mode)
590
+ {
591
+ auto & retriableTxs = txsBuilt.first ;
592
+ auto const & built = txsBuilt.second ;
593
+
582
594
// -------------------------------------------------------------------------
583
595
{
584
596
// Apply disputed transactions that didn't get in
@@ -601,7 +613,7 @@ RCLConsensus::Adaptor::doAccept(
601
613
// we voted NO
602
614
try
603
615
{
604
- JLOG (j_.debug ())
616
+ JLOG (j_.trace ())
605
617
<< " Test applying disputed transaction that did"
606
618
<< " not get in " << dispute.tx ().id ();
607
619
@@ -619,7 +631,7 @@ RCLConsensus::Adaptor::doAccept(
619
631
}
620
632
catch (std::exception const & ex)
621
633
{
622
- JLOG (j_.debug ()) << " Failed to apply transaction we voted "
634
+ JLOG (j_.trace ()) << " Failed to apply transaction we voted "
623
635
" NO on. Exception: "
624
636
<< ex.what ();
625
637
}
@@ -669,6 +681,7 @@ RCLConsensus::Adaptor::doAccept(
669
681
// we entered the round with the network,
670
682
// see how close our close time is to other node's
671
683
// close time reports, and update our clock.
684
+ bool const consensusFail = result.state == ConsensusState::MovedOn;
672
685
if ((mode == ConsensusMode::proposing ||
673
686
mode == ConsensusMode::observing) &&
674
687
!consensusFail)
@@ -889,12 +902,30 @@ RCLConsensus::Adaptor::onModeChange(ConsensusMode before, ConsensusMode after)
889
902
mode_ = after;
890
903
}
891
904
905
+ bool
906
+ RCLConsensus::Adaptor::retryAccept (
907
+ Ledger_t const & newLedger,
908
+ std::optional<std::chrono::time_point<std::chrono::steady_clock>>& start)
909
+ const
910
+ {
911
+ static bool const standalone = ledgerMaster_.standalone ();
912
+ auto const & validLedger = ledgerMaster_.getValidatedLedger ();
913
+
914
+ return (app_.getOPs ().isFull () && !standalone &&
915
+ (validLedger && (newLedger.id () != validLedger->info ().hash ) &&
916
+ (newLedger.seq () >= validLedger->info ().seq ))) &&
917
+ (!start ||
918
+ std::chrono::steady_clock::now () - *start < std::chrono::seconds{5 });
919
+ }
920
+
921
+ // -----------------------------------------------------------------------------
922
+
892
923
Json::Value
893
924
RCLConsensus::getJson (bool full) const
894
925
{
895
926
Json::Value ret;
896
927
{
897
- std::lock_guard _{mutex_ };
928
+ std::lock_guard _{adaptor_. peekMutex () };
898
929
ret = consensus_.getJson (full);
899
930
}
900
931
ret[" validating" ] = adaptor_.validating ();
@@ -906,7 +937,7 @@ RCLConsensus::timerEntry(NetClock::time_point const& now)
906
937
{
907
938
try
908
939
{
909
- std::lock_guard _{mutex_ };
940
+ std::lock_guard _{adaptor_. peekMutex () };
910
941
consensus_.timerEntry (now);
911
942
}
912
943
catch (SHAMapMissingNode const & mn)
@@ -922,7 +953,7 @@ RCLConsensus::gotTxSet(NetClock::time_point const& now, RCLTxSet const& txSet)
922
953
{
923
954
try
924
955
{
925
- std::lock_guard _{mutex_ };
956
+ std::lock_guard _{adaptor_. peekMutex () };
926
957
consensus_.gotTxSet (now, txSet);
927
958
}
928
959
catch (SHAMapMissingNode const & mn)
@@ -940,7 +971,7 @@ RCLConsensus::simulate(
940
971
NetClock::time_point const & now,
941
972
std::optional<std::chrono::milliseconds> consensusDelay)
942
973
{
943
- std::lock_guard _{mutex_ };
974
+ std::lock_guard _{adaptor_. peekMutex () };
944
975
consensus_.simulate (now, consensusDelay);
945
976
}
946
977
@@ -949,7 +980,7 @@ RCLConsensus::peerProposal(
949
980
NetClock::time_point const & now,
950
981
RCLCxPeerPos const & newProposal)
951
982
{
952
- std::lock_guard _{mutex_ };
983
+ std::lock_guard _{adaptor_. peekMutex () };
953
984
return consensus_.peerProposal (now, newProposal);
954
985
}
955
986
@@ -1022,6 +1053,12 @@ RCLConsensus::Adaptor::getQuorumKeys() const
1022
1053
return app_.validators ().getQuorumKeys ();
1023
1054
}
1024
1055
1056
+ std::size_t
1057
+ RCLConsensus::Adaptor::quorum () const
1058
+ {
1059
+ return app_.validators ().quorum ();
1060
+ }
1061
+
1025
1062
std::size_t
1026
1063
RCLConsensus::Adaptor::laggards (
1027
1064
Ledger_t::Seq const seq,
@@ -1051,12 +1088,13 @@ RCLConsensus::startRound(
1051
1088
hash_set<NodeID> const & nowUntrusted,
1052
1089
hash_set<NodeID> const & nowTrusted)
1053
1090
{
1054
- std::lock_guard _{mutex_ };
1091
+ std::lock_guard _{adaptor_. peekMutex () };
1055
1092
consensus_.startRound (
1056
1093
now,
1057
1094
prevLgrId,
1058
1095
prevLgr,
1059
1096
nowUntrusted,
1060
1097
adaptor_.preStartRound (prevLgr, nowTrusted));
1061
1098
}
1099
+
1062
1100
} // namespace ripple
0 commit comments