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

RPC response fix #1626

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions core/blockchain/impl/block_tree_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,15 @@ namespace kagome::blockchain {
auto hash = p.hasher_->blake2b_256(ext.data);
SL_DEBUG(log_, "Adding extrinsic with hash {}", hash);
if (auto key = p.extrinsic_event_key_repo_->get(hash)) {
notifyExtrinsicEventsEngine(
key.value(),
primitives::events::ExtrinsicLifecycleEvent::InBlock(
key.value(), block_hash));
main_thread_.execute(
[wself{weak_from_this()}, key{key.value()}, block_hash]() {
if (auto self = wself.lock()) {
self->extrinsic_events_engine_->notify(
key,
primitives::events::ExtrinsicLifecycleEvent::InBlock(
key, block_hash));
}
});
}
}

Expand All @@ -521,17 +526,6 @@ namespace kagome::blockchain {
});
}

void BlockTreeImpl::notifyExtrinsicEventsEngine(
subscription::ExtrinsicEventKeyRepository::ExtrinsicKey event,
const primitives::events::ExtrinsicLifecycleEvent &data) {
main_thread_.execute([wself{weak_from_this()}, event, data]() mutable {
if (auto self = wself.lock()) {
self->extrinsic_events_engine_->notify(std::move(event),
std::move(data));
}
});
}

outcome::result<void> BlockTreeImpl::removeLeaf(
const primitives::BlockHash &block_hash) {
return block_tree_data_.exclusiveAccess(
Expand Down Expand Up @@ -768,10 +762,16 @@ namespace kagome::blockchain {
for (auto &ext : body.value()) {
if (auto key = p.extrinsic_event_key_repo_->get(
p.hasher_->blake2b_256(ext.data))) {
notifyExtrinsicEventsEngine(
key.value(),
primitives::events::ExtrinsicLifecycleEvent::Finalized(
key.value(), block_hash));
main_thread_.execute([wself{weak_from_this()},
key{key.value()},
block_hash]() {
if (auto self = wself.lock()) {
self->extrinsic_events_engine_->notify(
key,
primitives::events::ExtrinsicLifecycleEvent::Finalized(
key, block_hash));
}
});
}
}
}
Expand Down Expand Up @@ -1336,10 +1336,16 @@ namespace kagome::blockchain {
for (auto &ext : block_body_res.value()) {
if (auto key = p.extrinsic_event_key_repo_->get(
p.hasher_->blake2b_256(ext.data))) {
notifyExtrinsicEventsEngine(
key.value(),
primitives::events::ExtrinsicLifecycleEvent::Retracted(
key.value(), node->block_hash));
main_thread_.execute([wself{weak_from_this()},
key{key.value()},
block_hash{node->block_hash}]() {
if (auto self = wself.lock()) {
self->extrinsic_events_engine_->notify(
key,
primitives::events::ExtrinsicLifecycleEvent::Retracted(
key, block_hash));
}
});
}
extrinsics.emplace_back(std::move(ext));
}
Expand Down
3 changes: 0 additions & 3 deletions core/blockchain/impl/block_tree_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ namespace kagome::blockchain {

void notifyChainEventsEngine(primitives::events::ChainEventType event,
const primitives::BlockHeader &header);
void notifyExtrinsicEventsEngine(
subscription::ExtrinsicEventKeyRepository::ExtrinsicKey event,
const primitives::events::ExtrinsicLifecycleEvent &data);

SafeObject<BlockTreeData> block_tree_data_;
primitives::events::ExtrinsicSubscriptionEnginePtr
Expand Down