Skip to content

Commit

Permalink
issues fixes
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer committed Jun 17, 2024
1 parent 97c9cd2 commit 7e6595a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 371 deletions.
83 changes: 29 additions & 54 deletions core/dispute_coordinator/impl/dispute_coordinator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ namespace kagome::dispute {
if (not session_info_opt.has_value()) {
return std::nullopt;
}
auto session_info = std::move(session_info_opt.value());
auto &session_info = session_info_opt.value().get();

std::unordered_set<ValidatorIndex> controlled_indices;
auto keypair = session_keys.getParaKeyPair(session_info.validators);
Expand All @@ -992,7 +992,7 @@ namespace kagome::dispute {
}

return CandidateEnvironment{.session_index = session,
.session = std::move(session_info),
.session = session_info,
.controlled_indices = controlled_indices};
}

Expand All @@ -1015,6 +1015,16 @@ namespace kagome::dispute {
.hash(*hasher_)
: boost::relaxed_get<CandidateHash>(candidate_receipt);

auto env_opt = makeCandidateEnvironment(
*session_keys_, *rolling_session_window_, session);
if (not env_opt.has_value()) {
SL_DEBUG(log_,
"We are lacking a `SessionInfo` for handling import of "
"statements.");
return outcome::success(false);
}
auto &env = env_opt.value();

// In case we are not provided with a candidate receipt we operate under
// the assumption, that a previous vote which included a
// `CandidateReceipt` was seen. This holds since every block is preceded
Expand Down Expand Up @@ -1052,16 +1062,6 @@ namespace kagome::dispute {
relay_parent = old_state_opt->candidate_receipt.descriptor.relay_parent;
}

auto env_opt = makeCandidateEnvironment(
*session_keys_, *rolling_session_window_, session, relay_parent);
if (not env_opt.has_value()) {
SL_DEBUG(log_,
"We are lacking a `SessionInfo` for handling import of "
"statements.");
return outcome::success(false);
}
auto &env = env_opt.value();

auto disabled_validators_res = api_->disabled_validators(relay_parent);
if (disabled_validators_res.has_error()) {
SL_WARN(log_,
Expand Down Expand Up @@ -1154,24 +1154,19 @@ namespace kagome::dispute {
statements.end());
}
++imported_valid_votes;
// return true;
return true;
}
// auto &existing = std::get<0>(it->second);
// return visit_in_place(
// valid,
// [&](const Explicit &) {
// return not is_type<Explicit>(existing);
// },
// [&](const BackingSeconded &) { return false; },
// [&](const BackingValid &) { return false; },
// [&](const ApprovalChecking &) {
// return not is_type<ApprovalChecking>(existing);
// },
// [&](const ApprovalCheckingMultipleCandidates &) {
// return not
// is_type<ApprovalCheckingMultipleCandidates>(
// existing);
// });
auto &existing = std::get<0>(it->second);
return visit_in_place(
valid,
[&](const Explicit &) {
return not is_type<Explicit>(existing);
},
[&](const BackingSeconded &) { return false; },
[&](const BackingValid &) { return false; },
[&](const ApprovalChecking &) {
return not is_type<ApprovalChecking>(existing);
});
},
[&](const InvalidDisputeStatement &invalid) {
auto [it, fresh] = votes.invalid.emplace(
Expand All @@ -1186,9 +1181,9 @@ namespace kagome::dispute {
statements.end());
}
++imported_invalid_votes;
// return true;
return true;
}
// return false;
return false;
});
}

Expand Down Expand Up @@ -1472,11 +1467,7 @@ namespace kagome::dispute {
sig,
session};

SL_TRACE(
log_,
"Sending out own approval vote. session={}, candidate_hash={}",
session,
candidate_hash);
SL_TRACE(log_, "Sending out own approval vote");

auto dispute_message_res = make_dispute_message(
env.session, new_state.votes, statement, validator_index);
Expand Down Expand Up @@ -1800,12 +1791,7 @@ namespace kagome::dispute {
bool valid) {
// https://github.com/paritytech/polkadot/blob/40974fb99c86f5c341105b7db53c7aa0df707d66/node/core/dispute-coordinator/src/initialized.rs#L1102

SL_TRACE(log_,
"Issuing local statement for candidate! "
"session={}, candidate_hash={}, relay_parent={}",
session,
candidate_hash,
candidate_receipt.descriptor.relay_parent);
SL_TRACE(log_, "Issuing local statement for candidate!");

// Load environment:

Expand Down Expand Up @@ -2072,12 +2058,7 @@ namespace kagome::dispute {
std::move(candidate_receipt),
valid);

SL_TRACE(log_,
"DisputeCoordinatorMessage::IssueLocalStatement. "
"session={}, candidate_hash={}, relay_parent={}",
session,
candidate_hash,
candidate_receipt.descriptor.relay_parent);
SL_TRACE(log_, "DisputeCoordinatorMessage::IssueLocalStatement");
auto res = issue_local_statement(
candidate_hash, candidate_receipt, session, valid);

Expand Down Expand Up @@ -2526,12 +2507,6 @@ namespace kagome::dispute {
}
}

SL_TRACE( // FIXME It's temporary code. Remove after tests
log_,
"Dispute (candidate={}) did not send. Disabled",
candidate_hash);
return;

auto protocol = router_->getSendDisputeProtocol();
BOOST_ASSERT_MSG(protocol,
"Router did not provide `send dispute` protocol");
Expand Down
5 changes: 2 additions & 3 deletions core/dispute_coordinator/impl/dispute_coordinator_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ namespace kagome::dispute {
std::vector<Indexed<SignedDisputeStatement>> statements,
CbOutcome<void> &&cb);

std::optional<CandidateEnvironment> makeCandidateEnvironment(
static std::optional<CandidateEnvironment> makeCandidateEnvironment(
crypto::SessionKeys &session_keys,
RollingSessionWindow &rolling_session_window,
SessionIndex session,
primitives::BlockHash relay_parent);
SessionIndex session);

outcome::result<void> process_on_chain_votes(ScrapedOnChainVotes votes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,9 @@ namespace kagome::dispute {

// Transform all `CandidateVotes` into `MultiDisputeStatementSet`.
MultiDisputeStatementSet result;

SL_TRACE(log_, "XXX >>> PrioritizedSelection::select_disputes");

for (auto &[key, votes] : dispute_candidate_votes) {
auto &[session_index, candidate_hash] = key;

SL_TRACE(log_,
"XXX session={}, candidate_hash={}",
session_index,
candidate_hash);

auto &statement_set = result.emplace_back(
DisputeStatementSet{candidate_hash, session_index, {}});

Expand All @@ -116,11 +108,6 @@ namespace kagome::dispute {
ValidDisputeStatement(statement), //
validator_index,
validator_signature);

SL_TRACE(log_,
"XXX Valid, validator_index={}, validator_sign={}",
validator_index,
validator_signature);
}

for (auto &[validator_index, value] : votes.invalid) {
Expand All @@ -129,16 +116,9 @@ namespace kagome::dispute {
InvalidDisputeStatement(statement),
validator_index,
validator_signature);

SL_TRACE(log_,
"XXX Invalid, validator_index={}, validator_sign={}",
validator_index,
validator_signature);
}
}

SL_TRACE(log_, "XXX <<< PrioritizedSelection::select_disputes");

return result;
}

Expand Down
51 changes: 4 additions & 47 deletions core/dispute_coordinator/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,10 @@ namespace kagome::dispute {
using BackingValid = Tagged<CandidateHash, struct BackingValidTag>;
/// An approval vote from the approval checking phase.
using ApprovalChecking = Tagged<Empty, struct ApprovalCheckingTag>;
/// An approval vote from the new version.
/// We can't create this version until all nodes have been updated to support
/// it and max_approval_coalesce_count is set to more than 1.
using ApprovalCheckingMultipleCandidates =
Tagged<std::vector<CandidateHash>,
struct ApprovalCheckingMultipleCandidatesTag>;

/// A valid statement, of the given kind
using ValidDisputeStatement =
boost::variant<Explicit, // 0
BackingSeconded, // 1
BackingValid, // 2
ApprovalChecking, // 3
ApprovalCheckingMultipleCandidates // 4
>;
boost::variant<Explicit, BackingSeconded, BackingValid, ApprovalChecking>;

/// An invalid statement, of the given kind.
using InvalidDisputeStatement = boost::variant<Explicit>;
Expand Down Expand Up @@ -163,7 +152,7 @@ namespace kagome::dispute {
/// The session the candidate appeared in.
SessionIndex session_index;
/// Session for above index.
SessionInfo session;
SessionInfo &session;
/// Validator indices controlled by this node.
std::unordered_set<ValidatorIndex> controlled_indices{};
};
Expand Down Expand Up @@ -230,7 +219,7 @@ namespace kagome::dispute {

/// A set of statements about a specific candidate.
struct DisputeStatementSet {
// SCALE_TIE(3);
SCALE_TIE(3);

/// The candidate referenced by this set.
CandidateHash candidate_hash;
Expand All @@ -242,30 +231,14 @@ namespace kagome::dispute {
std::vector<
std::tuple<DisputeStatement, ValidatorIndex, ValidatorSignature>>
statements;

template <class Stream>
friend inline Stream &operator<<(Stream &s, const DisputeStatementSet &x) {
s << x.candidate_hash;
s << x.session;
s << x.statements;
return s;
}

template <class Stream>
friend inline Stream &operator>>(Stream &s, DisputeStatementSet &x) {
s >> x.candidate_hash;
s >> x.session;
s >> x.statements;
return s;
}
};

/// A set of dispute statements.
using MultiDisputeStatementSet = std::vector<DisputeStatementSet>;

/// Scraped runtime backing votes and resolved disputes.
struct ScrapedOnChainVotes {
// SCALE_TIE(3);
SCALE_TIE(3);

/// The session in which the block was included.
SessionIndex session;
Expand All @@ -281,22 +254,6 @@ namespace kagome::dispute {
/// Note that the above `backing_validators` are
/// unrelated to the backers of the disputes candidates.
MultiDisputeStatementSet disputes;

template <class Stream>
friend inline Stream &operator<<(Stream &s, const ScrapedOnChainVotes &x) {
s << x.session;
s << x.backing_validators_per_candidate;
s << x.disputes;
return s;
}

template <class Stream>
friend inline Stream &operator>>(Stream &s, ScrapedOnChainVotes &x) {
s >> x.session;
s >> x.backing_validators_per_candidate;
s >> x.disputes;
return s;
}
};

/// Describes a relay-chain block by the para-chain candidates
Expand Down
2 changes: 1 addition & 1 deletion core/log/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace kagome::log {
sinks:
- name: console
type: console
stream: stdout
stream: stderr
thread: name
color: false
latency: 0
Expand Down
30 changes: 11 additions & 19 deletions core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ namespace kagome::network {
}

void PeerManagerImpl::align() {
SL_INFO(log_, "DEBUG: call align()");

SL_TRACE(log_, "Try to align peers number");

const auto hard_limit = app_config_.inPeers() + app_config_.inPeersLight()
Expand Down Expand Up @@ -600,8 +598,6 @@ namespace kagome::network {
}

void PeerManagerImpl::processDiscoveredPeer(const PeerId &peer_id) {
SL_INFO(log_, "DEBUG: call processDiscoveredPeer()");

// Ignore himself
if (isSelfPeer(peer_id)) {
return;
Expand Down Expand Up @@ -652,16 +648,13 @@ namespace kagome::network {
return;
}

SL_INFO(self->log_, "DEBUG: call openOutgoing::<lambda>()");

auto &peer_id = peer_info.id;

if (not stream_res.has_value()) {
SL_VERBOSE(self->log_,
"Unable to create stream {} with {}: {}",
protocol->protocolName(),
peer_id,
stream_res.error());
self->log_->verbose("Unable to create stream {} with {}: {}",
protocol->protocolName(),
peer_id,
stream_res.error());
self->connecting_peers_.erase(peer_id);
self->disconnectFromPeer(peer_id);
return;
Expand All @@ -670,7 +663,7 @@ namespace kagome::network {
? PeerType::PEER_TYPE_OUT
: PeerType::PEER_TYPE_IN;

// Add to the active peer list
// Add to active peer list
if (auto [ap_it, added] = self->active_peers_.emplace(
peer_id, PeerDescriptor{peer_type, self->clock_->now()});
added) {
Expand All @@ -679,11 +672,12 @@ namespace kagome::network {
// And remove from queue
if (auto piq_it = self->peers_in_queue_.find(peer_id);
piq_it != self->peers_in_queue_.end()) {
auto qtc_it = std::find_if(self->queue_to_connect_.cbegin(),
self->queue_to_connect_.cend(),
[&peer_id](const auto &item) {
return peer_id == item.get();
});
auto qtc_it =
std::find_if(self->queue_to_connect_.cbegin(),
self->queue_to_connect_.cend(),
[&peer_id = peer_id](const auto &item) {
return peer_id == item.get();
});
self->queue_to_connect_.erase(qtc_it);
self->peers_in_queue_.erase(piq_it);
BOOST_ASSERT(self->queue_to_connect_.size()
Expand Down Expand Up @@ -775,8 +769,6 @@ namespace kagome::network {
}

void PeerManagerImpl::processFullyConnectedPeer(const PeerId &peer_id) {
SL_INFO(log_, "DEBUG: call processFullyConnectedPeer()");

// Skip connection to itself
if (isSelfPeer(peer_id)) {
connecting_peers_.erase(peer_id);
Expand Down
Loading

0 comments on commit 7e6595a

Please sign in to comment.