-
Notifications
You must be signed in to change notification settings - Fork 129
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(rpc/subscription): subscribe runtime version notify when version changes #1686
Changes from 45 commits
7325277
2d324de
9394d38
cfe9117
37c8878
fb75b48
feb5f4d
a31474d
3017ed3
fd83528
432d604
0dcc08f
d7c5d59
8c16176
de0c40b
5512348
09c9b2e
cf0e477
6c3ea54
ade2a82
c0eb904
8031b82
d6f6cea
2f6c7e2
98fb9d9
42f436e
125a5d1
0e2fcd7
7e7e9bd
66bd9e2
ff35489
70d6c27
cecc811
c8d8d92
4747f96
c0cbdc0
b70b82c
fcac2b5
a41d0af
568ed88
4fd52d8
5e7fba5
6038b6c
ea37d63
dc78e71
0de3c60
739f8aa
e3e5cef
39f4a88
cb364a9
84f89d3
1a877ac
6270ede
9be6179
a22fca9
154061f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2019 ChainSafe Systems (ON) Corp. | ||
// This file is part of gossamer. | ||
// | ||
// The gossamer library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The gossamer library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package modules | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewMockStorageAPI(t *testing.T) { | ||
m := NewMockStorageAPI() | ||
require.NotNil(t, m) | ||
} | ||
|
||
func TestNewMockBlockAPI(t *testing.T) { | ||
m := NewMockBlockAPI() | ||
require.NotNil(t, m) | ||
} | ||
|
||
func TestNewMockCoreAPI(t *testing.T) { | ||
m := NewMockCoreAPI() | ||
require.NotNil(t, m) | ||
} | ||
|
||
func TestNewMockVersion(t *testing.T) { | ||
m := NewMockVersion() | ||
require.NotNil(t, m) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |||||||||||||||
"github.com/ChainSafe/gossamer/dot/state" | ||||||||||||||||
"github.com/ChainSafe/gossamer/dot/types" | ||||||||||||||||
"github.com/ChainSafe/gossamer/lib/common" | ||||||||||||||||
"github.com/ChainSafe/gossamer/lib/runtime" | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
// Listener interface for functions that define Listener related functions | ||||||||||||||||
|
@@ -258,20 +259,26 @@ func (l *ExtrinsicSubmitListener) Stop() { l.cancel() } | |||||||||||||||
|
||||||||||||||||
// RuntimeVersionListener to handle listening for Runtime Version | ||||||||||||||||
type RuntimeVersionListener struct { | ||||||||||||||||
wsconn *WSConn | ||||||||||||||||
subID uint | ||||||||||||||||
wsconn WSConnAPI | ||||||||||||||||
subID uint | ||||||||||||||||
runtimeUpdate chan runtime.Version | ||||||||||||||||
channelID uint32 | ||||||||||||||||
coreAPI modules.CoreAPI | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// VersionListener interface defining methods that version listener must implement | ||||||||||||||||
type VersionListener interface { | ||||||||||||||||
GetChannelID() uint32 | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Listen implementation of Listen interface to listen for runtime version changes | ||||||||||||||||
func (l *RuntimeVersionListener) Listen() { | ||||||||||||||||
// This sends current runtime version once when subscription is created | ||||||||||||||||
// TODO (ed) add logic to send updates when runtime version changes | ||||||||||||||||
rtVersion, err := l.wsconn.CoreAPI.GetRuntimeVersion(nil) | ||||||||||||||||
rtVersion, err := l.coreAPI.GetRuntimeVersion(nil) | ||||||||||||||||
if err != nil { | ||||||||||||||||
return | ||||||||||||||||
} | ||||||||||||||||
ver := modules.StateRuntimeVersionResponse{} | ||||||||||||||||
|
||||||||||||||||
ver.SpecName = string(rtVersion.SpecName()) | ||||||||||||||||
ver.ImplName = string(rtVersion.ImplName()) | ||||||||||||||||
ver.AuthoringVersion = rtVersion.AuthoringVersion() | ||||||||||||||||
|
@@ -280,9 +287,31 @@ func (l *RuntimeVersionListener) Listen() { | |||||||||||||||
ver.TransactionVersion = rtVersion.TransactionVersion() | ||||||||||||||||
ver.Apis = modules.ConvertAPIs(rtVersion.APIItems()) | ||||||||||||||||
|
||||||||||||||||
l.wsconn.safeSend(newSubscriptionResponse("state_runtimeVersion", l.subID, ver)) | ||||||||||||||||
go l.wsconn.safeSend(newSubscriptionResponse("state_runtimeVersion", l.subID, ver)) | ||||||||||||||||
|
||||||||||||||||
// listen for runtime updates | ||||||||||||||||
go func() { | ||||||||||||||||
for info := range l.runtimeUpdate { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
add closed channel check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I try to add ok assignment as above, I get compile error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh nvm I missed that this is a range, you'd have to change it to read from the channel in a for loop
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just pinging on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||||||||||||||||
ver := modules.StateRuntimeVersionResponse{} | ||||||||||||||||
|
||||||||||||||||
ver.SpecName = string(info.SpecName()) | ||||||||||||||||
ver.ImplName = string(info.ImplName()) | ||||||||||||||||
ver.AuthoringVersion = info.AuthoringVersion() | ||||||||||||||||
ver.SpecVersion = info.SpecVersion() | ||||||||||||||||
ver.ImplVersion = info.ImplVersion() | ||||||||||||||||
ver.TransactionVersion = info.TransactionVersion() | ||||||||||||||||
ver.Apis = modules.ConvertAPIs(info.APIItems()) | ||||||||||||||||
|
||||||||||||||||
l.wsconn.safeSend(newSubscriptionResponse("state_runtimeVersion", l.subID, ver)) | ||||||||||||||||
} | ||||||||||||||||
}() | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Stop to runtimeVersionListener not implemented yet because the listener | ||||||||||||||||
// does not need to be stoped | ||||||||||||||||
// does not need to be stopped | ||||||||||||||||
func (l *RuntimeVersionListener) Stop() {} | ||||||||||||||||
|
||||||||||||||||
// GetChannelID function that returns listener's channel ID | ||||||||||||||||
func (l *RuntimeVersionListener) GetChannelID() uint32 { | ||||||||||||||||
return l.channelID | ||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.