@@ -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,7 @@ RCLConsensus::Adaptor::onClose(
379
384
380
385
// Needed because of the move below.
381
386
auto const setHash = initialSet->getHash ().as_uint256 ();
382
-
387
+ initialLedger-> info (). seq ;
383
388
return Result{
384
389
std::move (initialSet),
385
390
RCLCxPeerPos::Proposal{
@@ -388,7 +393,9 @@ RCLConsensus::Adaptor::onClose(
388
393
setHash,
389
394
closeTime,
390
395
app_.timeKeeper ().closeTime (),
391
- validatorKeys_.nodeID }};
396
+ validatorKeys_.nodeID ,
397
+ initialLedger->info ().seq ,
398
+ clock }};
392
399
}
393
400
394
401
void
@@ -400,50 +407,43 @@ RCLConsensus::Adaptor::onForceAccept(
400
407
ConsensusMode const & mode,
401
408
Json::Value&& consensusJson)
402
409
{
403
- doAccept (
404
- result,
405
- prevLedger,
406
- closeResolution,
407
- rawCloseTimes,
408
- mode,
409
- std::move (consensusJson));
410
+ auto txsBuilt = buildAndValidate (
411
+ result, prevLedger, closeResolution, mode, std::move (consensusJson));
412
+ prepareOpenLedger (std::move (txsBuilt), result, rawCloseTimes, mode);
410
413
}
411
414
412
415
void
413
416
RCLConsensus::Adaptor::onAccept (
414
417
Result const & result,
415
- RCLCxLedger const & prevLedger,
416
- NetClock::duration const & closeResolution,
417
418
ConsensusCloseTimes const & rawCloseTimes,
418
419
ConsensusMode const & mode,
419
- Json::Value&& consensusJson)
420
+ Json::Value&& consensusJson,
421
+ std::pair<CanonicalTxSet_t, Ledger_t>&& tb)
420
422
{
421
423
app_.getJobQueue ().addJob (
422
424
jtACCEPT,
423
425
" acceptLedger" ,
424
- [=, this , cj = std::move (consensusJson)]() mutable {
426
+ [=,
427
+ this ,
428
+ cj = std::move (consensusJson),
429
+ txsBuilt = std::move (tb)]() mutable {
425
430
// Note that no lock is held or acquired during this job.
426
431
// This is because generic Consensus guarantees that once a ledger
427
432
// is accepted, the consensus results and capture by reference state
428
433
// will not change until startRound is called (which happens via
429
434
// endConsensus).
430
- this ->doAccept (
431
- result,
432
- prevLedger,
433
- closeResolution,
434
- rawCloseTimes,
435
- mode,
436
- std::move (cj));
435
+ prepareOpenLedger (std::move (txsBuilt), result, rawCloseTimes, mode);
437
436
this ->app_ .getOPs ().endConsensus ();
438
437
});
439
438
}
440
439
441
- void
442
- RCLConsensus::Adaptor::doAccept (
440
+ std::pair<
441
+ RCLConsensus::Adaptor::CanonicalTxSet_t,
442
+ RCLConsensus::Adaptor::Ledger_t>
443
+ RCLConsensus::Adaptor::buildAndValidate (
443
444
Result const & result,
444
- RCLCxLedger const & prevLedger,
445
- NetClock::duration closeResolution,
446
- ConsensusCloseTimes const & rawCloseTimes,
445
+ Ledger_t const & prevLedger,
446
+ NetClock::duration const & closeResolution,
447
447
ConsensusMode const & mode,
448
448
Json::Value&& consensusJson)
449
449
{
@@ -497,12 +497,12 @@ RCLConsensus::Adaptor::doAccept(
497
497
{
498
498
retriableTxs.insert (
499
499
std::make_shared<STTx const >(SerialIter{item.slice ()}));
500
- JLOG (j_.debug ()) << " Tx: " << item.key ();
500
+ JLOG (j_.trace ()) << " Tx: " << item.key ();
501
501
}
502
502
catch (std::exception const & ex)
503
503
{
504
504
failed.insert (item.key ());
505
- JLOG (j_.warn ())
505
+ JLOG (j_.trace ())
506
506
<< " Tx: " << item.key () << " throws: " << ex.what ();
507
507
}
508
508
}
@@ -579,6 +579,19 @@ RCLConsensus::Adaptor::doAccept(
579
579
ledgerMaster_.consensusBuilt (
580
580
built.ledger_ , result.txns .id (), std::move (consensusJson));
581
581
582
+ return {retriableTxs, built};
583
+ }
584
+
585
+ void
586
+ RCLConsensus::Adaptor::prepareOpenLedger (
587
+ std::pair<CanonicalTxSet_t, Ledger_t>&& txsBuilt,
588
+ Result const & result,
589
+ ConsensusCloseTimes const & rawCloseTimes,
590
+ ConsensusMode const & mode)
591
+ {
592
+ auto & retriableTxs = txsBuilt.first ;
593
+ auto const & built = txsBuilt.second ;
594
+
582
595
// -------------------------------------------------------------------------
583
596
{
584
597
// Apply disputed transactions that didn't get in
@@ -601,7 +614,7 @@ RCLConsensus::Adaptor::doAccept(
601
614
// we voted NO
602
615
try
603
616
{
604
- JLOG (j_.debug ())
617
+ JLOG (j_.trace ())
605
618
<< " Test applying disputed transaction that did"
606
619
<< " not get in " << dispute.tx ().id ();
607
620
@@ -619,7 +632,7 @@ RCLConsensus::Adaptor::doAccept(
619
632
}
620
633
catch (std::exception const & ex)
621
634
{
622
- JLOG (j_.debug ()) << " Failed to apply transaction we voted "
635
+ JLOG (j_.trace ()) << " Failed to apply transaction we voted "
623
636
" NO on. Exception: "
624
637
<< ex.what ();
625
638
}
@@ -669,6 +682,7 @@ RCLConsensus::Adaptor::doAccept(
669
682
// we entered the round with the network,
670
683
// see how close our close time is to other node's
671
684
// close time reports, and update our clock.
685
+ const bool consensusFail = result.state == ConsensusState::MovedOn;
672
686
if ((mode == ConsensusMode::proposing ||
673
687
mode == ConsensusMode::observing) &&
674
688
!consensusFail)
@@ -889,12 +903,32 @@ RCLConsensus::Adaptor::onModeChange(ConsensusMode before, ConsensusMode after)
889
903
mode_ = after;
890
904
}
891
905
906
+ bool
907
+ RCLConsensus::Adaptor::retryAccept (
908
+ Ledger_t const & newLedger,
909
+ std::optional<std::chrono::time_point<std::chrono::steady_clock>>& start)
910
+ const
911
+ {
912
+ static bool const standalone = ledgerMaster_.standalone ();
913
+ auto const & validLedger = ledgerMaster_.getValidatedLedger ();
914
+
915
+ return (app_.getOPs ().isFull () && !standalone &&
916
+ (validLedger && (newLedger.id () != validLedger->info ().hash ) &&
917
+ (newLedger.seq () >= validLedger->info ().seq ))) &&
918
+ (!start ||
919
+ std::chrono::duration_cast<std::chrono::seconds>(
920
+ std::chrono::steady_clock::now () - *start)
921
+ .count () < 5 );
922
+ }
923
+
924
+ // -----------------------------------------------------------------------------
925
+
892
926
Json::Value
893
927
RCLConsensus::getJson (bool full) const
894
928
{
895
929
Json::Value ret;
896
930
{
897
- std::lock_guard _{mutex_ };
931
+ std::lock_guard _{adaptor_. peekMutex () };
898
932
ret = consensus_.getJson (full);
899
933
}
900
934
ret[" validating" ] = adaptor_.validating ();
@@ -906,7 +940,7 @@ RCLConsensus::timerEntry(NetClock::time_point const& now)
906
940
{
907
941
try
908
942
{
909
- std::lock_guard _{mutex_ };
943
+ std::lock_guard _{adaptor_. peekMutex () };
910
944
consensus_.timerEntry (now);
911
945
}
912
946
catch (SHAMapMissingNode const & mn)
@@ -922,7 +956,7 @@ RCLConsensus::gotTxSet(NetClock::time_point const& now, RCLTxSet const& txSet)
922
956
{
923
957
try
924
958
{
925
- std::lock_guard _{mutex_ };
959
+ std::lock_guard _{adaptor_. peekMutex () };
926
960
consensus_.gotTxSet (now, txSet);
927
961
}
928
962
catch (SHAMapMissingNode const & mn)
@@ -940,7 +974,7 @@ RCLConsensus::simulate(
940
974
NetClock::time_point const & now,
941
975
std::optional<std::chrono::milliseconds> consensusDelay)
942
976
{
943
- std::lock_guard _{mutex_ };
977
+ std::lock_guard _{adaptor_. peekMutex () };
944
978
consensus_.simulate (now, consensusDelay);
945
979
}
946
980
@@ -949,7 +983,7 @@ RCLConsensus::peerProposal(
949
983
NetClock::time_point const & now,
950
984
RCLCxPeerPos const & newProposal)
951
985
{
952
- std::lock_guard _{mutex_ };
986
+ std::lock_guard _{adaptor_. peekMutex () };
953
987
return consensus_.peerProposal (now, newProposal);
954
988
}
955
989
@@ -1051,12 +1085,13 @@ RCLConsensus::startRound(
1051
1085
hash_set<NodeID> const & nowUntrusted,
1052
1086
hash_set<NodeID> const & nowTrusted)
1053
1087
{
1054
- std::lock_guard _{mutex_ };
1088
+ std::lock_guard _{adaptor_. peekMutex () };
1055
1089
consensus_.startRound (
1056
1090
now,
1057
1091
prevLgrId,
1058
1092
prevLgr,
1059
1093
nowUntrusted,
1060
1094
adaptor_.preStartRound (prevLgr, nowTrusted));
1061
1095
}
1096
+
1062
1097
} // namespace ripple
0 commit comments