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

fix: confirm block import notifier is closed properly #1736

Merged
merged 40 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0a59cb3
add TODOs to identify where block imported channel is handled
edwardmack Aug 17, 2021
a8cffd8
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Aug 18, 2021
30338f7
added comments for imported channels
edwardmack Aug 18, 2021
6ed9d63
create constructor for listeners
edwardmack Aug 19, 2021
0bc1f97
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Aug 23, 2021
2ae9572
added close channel to defer in listen
edwardmack Aug 23, 2021
0f95d68
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Aug 25, 2021
2b16fa6
move imported chan to block_notify
edwardmack Aug 26, 2021
7f10eec
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Aug 26, 2021
5f1c2a6
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Aug 30, 2021
2b512b2
remove comments, lint
edwardmack Aug 30, 2021
e3bd220
handle lint issues
edwardmack Aug 30, 2021
fd6d7cc
replace imported channel map with sync.Map
edwardmack Aug 30, 2021
125b68a
fix mocks in listeners test
edwardmack Aug 30, 2021
ee0fc7b
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Aug 31, 2021
6ca1a8b
fix mock functions for new imported notification channel
edwardmack Aug 31, 2021
d3eaa06
fix deep source issues
edwardmack Aug 31, 2021
41bb429
add debugging printf
edwardmack Sep 1, 2021
f0f76f1
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Sep 1, 2021
0164305
remove sync.Pool, and sync.Map
edwardmack Sep 2, 2021
b7f658f
handle channel closing
edwardmack Sep 3, 2021
74f094d
add sleep before close
edwardmack Sep 3, 2021
8a49ae7
remove channel close
edwardmack Sep 3, 2021
35180df
run go imported
edwardmack Sep 3, 2021
faf2664
defer importedLock unlock
edwardmack Sep 7, 2021
db397cd
wrap notifier channel in struct
edwardmack Sep 8, 2021
4b7d341
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Sep 9, 2021
d5d0d57
store channel by interface{} key
edwardmack Sep 9, 2021
f72e744
Merge branch 'ed/fix_send_on_closed_channel' of https://github.com/Ch…
edwardmack Sep 9, 2021
a478d5c
update storage key for imported block listeners
edwardmack Sep 9, 2021
d5754d9
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Sep 9, 2021
8b8066c
refacter GetImportedBlockNotifierChannel arugments
edwardmack Sep 10, 2021
1acfba7
GetImportedBlockNotifierChannel doesn't return error, fixed related test
edwardmack Sep 10, 2021
ce706cc
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Sep 20, 2021
515391d
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Sep 21, 2021
8ad895c
remove un-needed comments
edwardmack Sep 21, 2021
6b46fcd
Merge branch 'development' into ed/fix_send_on_closed_channel
edwardmack Sep 23, 2021
6bfb77d
remove close for FinalisedChannel listener
edwardmack Sep 23, 2021
48f6db0
added test for free imported channel
edwardmack Sep 23, 2021
8b30110
add mocks paths to .deepsource exclude_patterns
edwardmack Sep 24, 2021
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
2 changes: 1 addition & 1 deletion dot/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func newGrandpaChange(raw []types.GrandpaAuthoritiesRaw, delay uint32, currBlock
}, nil
}

func (*Handler) handleBABEOnDisabled(_ *types.ConsensusDigest, _ *types.Header) error {
func (h *Handler) handleBABEOnDisabled(d types.BABEOnDisabled, _ *types.Header) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this function do? looks like it just logs some struct and returns nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why this is here...

od := &types.BABEOnDisabled{}
logger.Debug("handling BABEOnDisabled", "data", od)
return nil
Expand Down
5 changes: 5 additions & 0 deletions dot/rpc/subscription/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ func TestSubscribeAllHeads(t *testing.T) {
_, msg, err = c.ReadMessage()
require.NoError(t, err)
require.Equal(t, expected+"\n", string(msg))

digest = types.NewDigest()
err = digest.Add(*types.NewBABEPreRuntimeDigest([]byte{0xff}))
require.NoError(t, err)

iCh <- &types.Block{
Header: types.Header{
ParentHash: common.EmptyHash,
Expand Down
24 changes: 1 addition & 23 deletions dot/state/block_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package state

import (
"errors"
"fmt"
"sync"

"github.com/ChainSafe/gossamer/dot/types"
Expand All @@ -40,19 +39,6 @@ func (bs *BlockState) GetImportedBlockNotifierChannel() chan *types.Block {
return ch
}

//func (bs *BlockState) GetImportedBlockNotifierChannel() (*ImportNotifier, error) {
// bs.importedLock.Lock()
// defer bs.importedLock.Unlock()
//
// in := &ImportNotifier{
// ch: make(chan *types.Block, DEFAULT_BUFFER_SIZE),
// }
// //ch := make(chan *types.Block, DEFAULT_BUFFER_SIZE)
// bs.imported[in] = struct{}{}
//
// return in, nil
//}

// RegisterFinalizedChannel registers a channel for block notification upon block finalisation.
// It returns the channel ID (used for unregistering the channel)
func (bs *BlockState) RegisterFinalizedChannel(ch chan<- *types.FinalisationInfo) (byte, error) {
Expand All @@ -71,21 +57,13 @@ func (bs *BlockState) RegisterFinalizedChannel(ch chan<- *types.FinalisationInfo
return id, nil
}

// FreeImportedBlockNotifierChannel to free and close imported block notifier channel
// FreeImportedBlockNotifierChannel to free imported block notifier channel
func (bs *BlockState) FreeImportedBlockNotifierChannel(ch chan *types.Block) {
noot marked this conversation as resolved.
Show resolved Hide resolved
bs.importedLock.Lock()
defer bs.importedLock.Unlock()
fmt.Printf("delete chan %v\n", ch)
delete(bs.imported, ch)
}

//func (bs *BlockState) FreeImportedBlockNotifierChannel(ch *ImportNotifier) {
// bs.importedLock.Lock()
// defer bs.importedLock.Unlock()
// // todo (ed) add test to confirm this is deleting
// delete(bs.imported, ch)
//}

// UnregisterFinalisedChannel removes the block finalisation notification channel with the given ID.
// A channel must be unregistered before closing it.
func (bs *BlockState) UnregisterFinalisedChannel(id byte) {
Expand Down