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

Votes cache #1852

Merged
merged 3 commits into from
Oct 27, 2023
Merged

Votes cache #1852

merged 3 commits into from
Oct 27, 2023

Conversation

kamilsa
Copy link
Contributor

@kamilsa kamilsa commented Oct 20, 2023

Referenced issues

None

Description of the Change

Introduces vote message cache to avoid processing of the same vote twice.

Benefits

Cache hit rate 94%

Possible Drawbacks

None

@kamilsa kamilsa requested review from igor-egorov and xDimon October 20, 2023 10:36
}
votes_cache_.put(msg);

if (not info.has_value() or not info->set_id.has_value()
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy of line 953. Need to remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

At least info is used before the definition

Copy link
Member

Choose a reason for hiding this comment

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

No problem, in the line 952 it might be rewritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It got here accidentally. Fixed now

@@ -295,6 +296,8 @@ namespace kagome::consensus::grandpa {
*/
void loadMissingBlocks(GrandpaContext &&grandpa_context);

const size_t kVotesCacheSize
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the value? What it equals to? Where is a semicolon at least?

Copy link
Member

Choose a reason for hiding this comment

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

Looks malformed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}
return false;
}
} // namespace kagome::consensus::grandpa
Copy link
Contributor

Choose a reason for hiding this comment

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

No line break at the end. Please add

private:
LruCache<RoundNumber, std::unordered_set<VotesCacheItem>> lru_cache_;
};
} // namespace kagome::consensus::grandpa
Copy link
Contributor

Choose a reason for hiding this comment

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

No line break at the end. Please add

Copy link
Member

@xDimon xDimon left a comment

Choose a reason for hiding this comment

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

Look at another solution: use

std::set<std::tuple<set_id, round_number, hash<Vote>, hash<Vote>>

instead LRU

if (cache.size() > threshold) {
  pop(begin());
}

@@ -295,6 +296,8 @@ namespace kagome::consensus::grandpa {
*/
void loadMissingBlocks(GrandpaContext &&grandpa_context);

const size_t kVotesCacheSize
Copy link
Member

Choose a reason for hiding this comment

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

Looks malformed

std::size_t operator()(
const kagome::consensus::grandpa::VotesCacheItem &item) const {
return std::hash<size_t>()(item.type)
^ std::hash<kagome::consensus::grandpa::Id>()(item.id)
Copy link
Member

Choose a reason for hiding this comment

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

Please, use boost::hash_combine instead xor

Id id;
primitives::BlockHash block_hash;

bool operator==(const VotesCacheItem &rhs) const {
Copy link
Member

Choose a reason for hiding this comment

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

auto operator<=>(const VotesCacheItem &rhs) const = default; would be enough

@kamilsa kamilsa closed this Oct 20, 2023
@kamilsa kamilsa force-pushed the feature/votes-cache branch from bdc508b to 800debc Compare October 20, 2023 14:05
@kamilsa kamilsa reopened this Oct 20, 2023
# Conflicts:
#	core/consensus/grandpa/impl/grandpa_impl.cpp
@kamilsa kamilsa enabled auto-merge (squash) October 25, 2023 11:01

void put(const VoteMessage &msg);

bool contains(VoteMessage msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems the argument could be const&.

[[relaychain.nodes]]
name = "two"

#[[parachains]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please either add a comment explaining when and how to use the disabled config or remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, sorry. Committed accidentally

@kamilsa kamilsa disabled auto-merge October 25, 2023 11:52
@kamilsa kamilsa force-pushed the feature/votes-cache branch from 9f9eb4b to 1e61de7 Compare October 25, 2023 11:57
Copy link
Contributor

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

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

Rejecting changes to prevent auto merge before confirming the changes in peer_manager_impl.cpp.

const auto &peer_id = peers_list.back().second;
disconnectFromPeer(peer_id);
}
// for (; !peers_list.empty()
Copy link
Contributor

Choose a reason for hiding this comment

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

Most likely this is unintended change.

@kamilsa kamilsa force-pushed the feature/votes-cache branch from 86f2dc5 to 1e61de7 Compare October 27, 2023 11:43
@kamilsa kamilsa merged commit 6696e5e into master Oct 27, 2023
@kamilsa kamilsa deleted the feature/votes-cache branch October 27, 2023 12:10
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.

3 participants