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

Audi store #2303

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Audi store #2303

wants to merge 1 commit into from

Conversation

kamilsa
Copy link
Contributor

@kamilsa kamilsa commented Dec 4, 2024

Referenced issues

Closes #2300

Description of the Change

  • Implements AudiStore that persistently stores discovered authority's peer information

Possible Drawbacks

  • DB-based audi store instead of in-memory

Checklist Before Opening a PR

Before you open a Pull Request (PR), please make sure you've completed the following steps and confirm by answering 'Yes' to each item:

  1. Code is formatted: Have you run your code through clang-format to ensure it adheres to the project's coding standards? [Yes|No]
  2. Code is documented: Have you added comments and documentation to your code according to the guidelines in the project's contributing guidelines? [Yes|No]
  3. Self-review: Have you reviewed your own code to ensure it is free of typos, syntax errors, logical errors, and unresolved TODOs or FIXME without linking to an issue? [Yes|No]
  4. Zombienet Tests: Have you ensured that the zombienet tests are passing? Zombienet is a network simulation and testing tool used in this project. It's important to ensure that these tests pass to maintain the stability and reliability of the project. [Yes|No]

#include "scale/libp2p_types.hpp"

namespace kagome::authority_discovery {
struct AuthorityPeerInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct AuthorityPeerInfo {
struct AuthorityPeerInfo {
SCALE_TIE(3);

Comment on lines +19 to +29
template <class Stream>
requires Stream::is_encoder_stream
Stream &operator<<(Stream &s, const AuthorityPeerInfo &api) {
return s << api.raw << api.time << api.peer;
}

template <class Stream>
requires Stream::is_decoder_stream
Stream &operator>>(Stream &s, AuthorityPeerInfo &api) {
return s >> api.raw >> api.time >> api.peer;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
template <class Stream>
requires Stream::is_encoder_stream
Stream &operator<<(Stream &s, const AuthorityPeerInfo &api) {
return s << api.raw << api.time << api.peer;
}
template <class Stream>
requires Stream::is_decoder_stream
Stream &operator>>(Stream &s, AuthorityPeerInfo &api) {
return s >> api.raw >> api.time >> api.peer;
}

@@ -22,7 +22,8 @@ namespace kagome::storage {
"trie_value",
"dispute_data",
"beefy_justification",
"avaliability_storage"};
"avaliability_storage",
"audi_peers"};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"audi_peers"};
"audi_peers",
};

@@ -281,12 +287,13 @@ namespace kagome::authority_discovery {
scale::decode<TimestampScale>(
qtils::str2byte(record.creation_time().timestamp())));
time = *tmp;
if (it != auth_to_peer_cache_.end() and time <= it->second.time) {
if (it != std::nullopt and time <= it->time->number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (it != std::nullopt and time <= it->time->number) {
if (it and it->time and time <= it->time->number) {

Comment on lines +161 to +172
// remove outdated authorities
std::deque<std::pair<primitives::AuthorityDiscoveryId, AuthorityPeerInfo>>
to_remove;
audi_store_->forEach([&](const primitives::AuthorityDiscoveryId &id,
const AuthorityPeerInfo &info) {
if (not has(authorities, id)) {
to_remove.emplace_back(id, info);
}
});
for (auto &pair : to_remove) {
audi_store_->remove(pair.first);
validation_protocol_.get()->reserve(pair.second.peer.id, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May simplify

audi_store_->retain([&](id, info) {
  if (has(id)) return true;
  reserve(info.peer, false);
  return false;
});

return decoded.value();
}

bool AudiStoreImpl::remove(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value is not used.
remove always returns outcome::success, even for non-existing key

Suggested change
bool AudiStoreImpl::remove(
void AudiStoreImpl::remove(

bool AudiStoreImpl::contains(
const primitives::AuthorityDiscoveryId &authority) const {
auto res = space_->tryGet(authority);
return res.has_value() ? res.value().has_value() : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return res.has_value() ? res.value().has_value() : false;
return res.has_value() and res.value().has_value();

void AudiStoreImpl::forEach(
std::function<void(const primitives::AuthorityDiscoveryId &,
const AuthorityPeerInfo &)> f) const {
auto cursor = space_->cursor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto cursor = space_->cursor();
auto cursor = space_->cursor();
std::ignore = cursor->seekFirst();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants