-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Audi store #2303
Conversation
#include "scale/libp2p_types.hpp" | ||
|
||
namespace kagome::authority_discovery { | ||
struct AuthorityPeerInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct AuthorityPeerInfo { | |
struct AuthorityPeerInfo { | |
SCALE_TIE(3); |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (it != std::nullopt and time <= it->time->number) { | |
if (it and it->time and time <= it->time->number) { |
// 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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto cursor = space_->cursor(); | |
auto cursor = space_->cursor(); | |
std::ignore = cursor->seekFirst(); |
Referenced issues
Closes #2300
Description of the Change
Possible Drawbacks
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: