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

refactor: model finalised notifier channel after imported notifier channel #1816

Merged
merged 7 commits into from
Oct 6, 2021

Conversation

edwardmack
Copy link
Member

Changes

Tests

make test

Issues

Primary Reviewer

@codecov
Copy link

codecov bot commented Sep 29, 2021

Codecov Report

Merging #1816 (d9be71b) into development (2b1276d) will decrease coverage by 0.03%.
The diff coverage is 95.65%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #1816      +/-   ##
===============================================
- Coverage        59.66%   59.62%   -0.04%     
===============================================
  Files              189      188       -1     
  Lines            19673    19621      -52     
===============================================
- Hits             11738    11700      -38     
+ Misses            5960     5952       -8     
+ Partials          1975     1969       -6     
Flag Coverage Δ
unit-tests 59.62% <95.65%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/grandpa/grandpa.go 61.04% <50.00%> (+0.63%) ⬆️
dot/digest/digest.go 66.32% <100.00%> (-0.84%) ⬇️
dot/rpc/modules/api_mocks.go 100.00% <100.00%> (ø)
dot/rpc/subscription/listeners.go 73.29% <100.00%> (-0.28%) ⬇️
dot/rpc/subscription/websocket.go 63.63% <100.00%> (+0.38%) ⬆️
dot/state/block.go 41.17% <100.00%> (-0.39%) ⬇️
dot/state/block_notify.go 78.37% <100.00%> (+3.06%) ⬆️
dot/core/service.go 52.87% <0.00%> (-0.77%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b1276d...d9be71b. Read the comment docs.

@@ -218,7 +217,7 @@ func TestWSConn_HandleComm(t *testing.T) {
require.NoError(t, err)
require.Equal(t, `{"jsonrpc":"2.0","method":"author_extrinsicUpdate","params":{"result":"ready","subscription":8}}`+"\n", string(msg))

var fCh chan<- *types.FinalisationInfo
//var fCh chan *types.FinalisationInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Member Author

Choose a reason for hiding this comment

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

removed.

Copy link
Contributor

@noot noot left a comment

Choose a reason for hiding this comment

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

looks good :D


bs.finalisedLock.RUnlock()
ch := make(chan *types.FinalisationInfo, DEFAULT_BUFFER_SIZE)
Copy link
Contributor

Choose a reason for hiding this comment

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

DEFAULT_BUFFER_SIZE make this camelcase.

@@ -74,7 +73,7 @@ func NewBlockState(db chaindb.Database, bt *blocktree.BlockTree) (*BlockState, e
baseState: NewBaseState(db),
db: chaindb.NewTable(db, blockPrefix),
imported: make(map[chan *types.Block]struct{}),
finalised: make(map[byte]chan<- *types.FinalisationInfo),
finalised: make(map[chan *types.FinalisationInfo]struct{}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. I didn't know we could create a map with channels as key.

for _, ch := range bs.finalised {
go func(ch chan<- *types.FinalisationInfo) {
for ch := range bs.finalised {
go func(ch chan *types.FinalisationInfo) {
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
go func(ch chan *types.FinalisationInfo) {
go func(ch chan<- *types.FinalisationInfo) {

if err != nil {
logger.Error("failed to unregister finalised channel", "error", err)
}
delete(bs.finalised, ch)
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly close the channel

close(ch)

Copy link
Contributor

Choose a reason for hiding this comment

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

// FreeImportedBlockNotifierChannel to free imported block notifier channel
func (bs *BlockState) FreeImportedBlockNotifierChannel(ch chan *types.Block) {
	bs.importedLock.Lock()
	defer bs.importedLock.Unlock()
	delete(bs.imported, ch)
	close(ch)
}

// FreeFinalisedNotifierChannel to free finalized notifier channel
func (bs *BlockState) FreeFinalisedNotifierChannel(ch chan *types.FinalisationInfo) {
	bs.finalisedLock.Lock()
	defer bs.finalisedLock.Unlock()

	delete(bs.finalised, ch)
	close(ch)
}

@noot noot merged commit cf04c2d into development Oct 6, 2021
@noot noot deleted the ed/fix_finalised_channel_close branch October 6, 2021 10:11
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

🎉 This PR is included in version 0.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

timwu20 pushed a commit to timwu20/gossamer that referenced this pull request Dec 6, 2021
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.

None yet

3 participants