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

blockchain: subscriptions API refactoring #3281

Closed
wants to merge 1 commit into from

Conversation

AliceInHunterland
Copy link
Contributor

@AliceInHunterland AliceInHunterland commented Dec 28, 2023

make (Blockchain).SubscribeFor arguments chan<- as a send-only channel. Originally #2884

Copy link

codecov bot commented Dec 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d901697) 85.14% compared to head (e337a2f) 85.22%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3281      +/-   ##
==========================================
+ Coverage   85.14%   85.22%   +0.07%     
==========================================
  Files         327      327              
  Lines       44437    44412      -25     
==========================================
+ Hits        37836    37850      +14     
+ Misses       5098     5057      -41     
- Partials     1503     1505       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

Good, we also have notary request subscriptions with the same problem.

Let's move this PR and issue to 0.106.0, it's not critical.

pkg/core/blockchain.go Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
internal/fakechain/fakechain.go Show resolved Hide resolved
pkg/core/blockchain.go Show resolved Hide resolved
pkg/services/stateroot/service.go Show resolved Hide resolved
There is no need to accept rw channel. Strengthening the type to
send-only will allow the caller to ensure control of reading from the
provided channel.

Closes #2885

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
Comment on lines -2337 to +2338
func (bc *Blockchain) UnsubscribeFromBlocks(ch chan *block.Block) {
unsubloop:
for {
select {
case <-ch:
case bc.unsubCh <- ch:
break unsubloop
}
}
func (bc *Blockchain) UnsubscribeFromBlocks(ch chan<- *block.Block) {
bc.unsubCh <- ch
Copy link
Member

Choose a reason for hiding this comment

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

OK, that's the case @roman-khimov told about in #2884 (comment). We can't remove this unsubloop code, because starting from the unsubscription moment all data sent to this channel should be discarded.

@AnnaShaleva
Copy link
Member

AnnaShaleva commented Jan 11, 2024

Since unsubscription interface doesn't allow send-only channel to be passed as an argument (UnsubscribeFrom* needs to discard all possible data sent to this channel after unsubscription, see #2884 (comment)), I don't see any point in changing only SubscribeFor* arguments to send-only channels. Thus, closing this PR and related #2885 as not planned.

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