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

chore (pkg/babe): Integrate scale into babe and transaction libraries #1661

Closed
wants to merge 249 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
249 commits
Select commit Hold shift + click to select a range
3af8732
scale encoding with optionality, struct tag field ordering, uint128
timwu20 Apr 29, 2021
65388ca
add indices caching
timwu20 Apr 30, 2021
d586e74
add mtx
timwu20 Apr 30, 2021
c1d0da1
add variable data type interface, test to compare old vs new encoding
timwu20 May 4, 2021
1ddf6af
fix width int decode and tests
timwu20 May 5, 2021
8787be5
wip
timwu20 May 6, 2021
751f020
[]byte, string decoding
timwu20 May 14, 2021
806b871
encodeBool and tests
timwu20 May 14, 2021
f13b8a1
refactor tests, include optionality tests
timwu20 May 20, 2021
094b90b
use shared tests in decode
timwu20 May 21, 2021
c510b64
struct decode tests, and unmarshal refactor
timwu20 May 26, 2021
10905ea
wip
timwu20 May 27, 2021
868b0e7
decode of VariantDataType, wip tests
timwu20 May 28, 2021
91e030b
add optionality testing
timwu20 May 28, 2021
8292794
fix struct tests and optionality tests
timwu20 May 31, 2021
2fc8515
test VaryingDataType
timwu20 Jun 1, 2021
5177229
wip decode refactor, use reflect.Value as passed param
timwu20 Jun 1, 2021
c854487
repurpose int and uint as compact length encoded integers, remove unn…
timwu20 Jun 1, 2021
bbc787a
cleanup, and all tests benchmark
timwu20 Jun 2, 2021
942ea32
add README
timwu20 Jun 2, 2021
62eb729
update README
timwu20 Jun 2, 2021
4c75bef
update readme
timwu20 Jun 2, 2021
60a74be
update readme
timwu20 Jun 2, 2021
5801f19
update README
timwu20 Jun 3, 2021
215cc10
update README
timwu20 Jun 3, 2021
2aae887
rResult encode/decode and RegisterResult
timwu20 Jun 3, 2021
40c2728
wip cr feedback
timwu20 Jun 4, 2021
3c836b6
add licenses
timwu20 Jun 7, 2021
416321e
add custom primitive encode/decode
timwu20 Jun 7, 2021
d6ba1fc
more cr feedback
timwu20 Jun 8, 2021
8a663d4
cr feedback
timwu20 Jun 9, 2021
159cc02
wip
timwu20 Jun 14, 2021
1d109d5
revise Result
timwu20 Jun 16, 2021
22d69ed
add readme
timwu20 Jun 17, 2021
7be9479
add usage example for Result
timwu20 Jun 17, 2021
594898c
wip VaryingDataType and VaryingDataTypeSlice
timwu20 Jun 19, 2021
1350668
refactor VaryingDataType and add VaryingDataTypeSlice
timwu20 Jun 21, 2021
6c5c755
update README
timwu20 Jun 21, 2021
c356f7f
fix lint
timwu20 Jun 21, 2021
8ba49eb
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
e7906bf
update examples
timwu20 Jun 21, 2021
20ffc98
fix deepsource
timwu20 Jun 21, 2021
15e8f5b
WIP/Integrate scale pkg into lib/babe
jimjbrettj Jun 22, 2021
28ea2d1
fixed error unmarshaling in errors.go
jimjbrettj Jun 22, 2021
4354f42
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
1da714d
WIP/Integrate scale pkg into lib/babe
jimjbrettj Jun 22, 2021
e83eda2
fixed error unmarshaling in errors.go
jimjbrettj Jun 22, 2021
6d23ad7
Merge branch 'jimmy/integrateScalePkg' of github.com:ChainSafe/gossam…
jimjbrettj Jun 22, 2021
310054c
check decoded in comparison_test
timwu20 Jun 22, 2021
deb8a1e
cr feedback
timwu20 Jun 22, 2021
4a81474
WIP/Integrate scale into lib/babe
jimjbrettj Jun 22, 2021
c1f86d6
integrate scale package into babe library
jimjbrettj Jun 22, 2021
a44dbe9
fix result.set with nil value
timwu20 Jun 22, 2021
9a29cf9
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
c188027
WIP/Integrate scale pkg into lib/babe
jimjbrettj Jun 22, 2021
b554419
fixed error unmarshaling in errors.go
jimjbrettj Jun 22, 2021
0692d43
WIP/Integrate scale into lib/babe
jimjbrettj Jun 22, 2021
37d8240
integrate scale package into babe library
jimjbrettj Jun 22, 2021
faabf36
WIP/refactor babe errors to utilize new scale pkg
jimjbrettj Jun 22, 2021
1cc38f4
Merge branch 'jimmy/integrateScalePkg' of github.com:ChainSafe/gossam…
jimjbrettj Jun 22, 2021
88a4e30
Integrate scale pkg into babe tests
jimjbrettj Jun 22, 2021
730a4e7
create init structs for dispatch outcome errors
jimjbrettj Jun 22, 2021
144ffa8
WIP/refactor babe error handling to utiliize new scale pkg features
jimjbrettj Jun 22, 2021
59b01e4
WIP scale/babe integration. Closer but still errors
jimjbrettj Jun 23, 2021
cc6a0f1
WIP/Fix type issues in babe refactor
jimjbrettj Jun 23, 2021
40d1964
Comments on issues to fix in for babe error handling
jimjbrettj Jun 23, 2021
4cc4021
WIP/refactor babe error handling with new scale pkg
jimjbrettj Jun 24, 2021
ae05c36
resolve type issue
jimjbrettj Jun 24, 2021
6919833
fixed unknown error data populating issue
jimjbrettj Jun 24, 2021
f195c16
WIP/Get module data to be populated when unmarshalling
jimjbrettj Jun 24, 2021
a0d51c7
resolved data population issue
jimjbrettj Jun 24, 2021
fc10100
add mtx
timwu20 Apr 30, 2021
5111bde
add variable data type interface, test to compare old vs new encoding
timwu20 May 4, 2021
33788df
wip
timwu20 May 6, 2021
60a680a
[]byte, string decoding
timwu20 May 14, 2021
ef092be
encodeBool and tests
timwu20 May 14, 2021
02cafa7
refactor tests, include optionality tests
timwu20 May 20, 2021
bb8acb9
use shared tests in decode
timwu20 May 21, 2021
62f686a
struct decode tests, and unmarshal refactor
timwu20 May 26, 2021
bba659d
wip
timwu20 May 27, 2021
9520ee0
decode of VariantDataType, wip tests
timwu20 May 28, 2021
144e103
add optionality testing
timwu20 May 28, 2021
d721a9b
fix struct tests and optionality tests
timwu20 May 31, 2021
5cc4be1
test VaryingDataType
timwu20 Jun 1, 2021
1e390c0
wip decode refactor, use reflect.Value as passed param
timwu20 Jun 1, 2021
5a6d63d
repurpose int and uint as compact length encoded integers, remove unn…
timwu20 Jun 1, 2021
4c5ab05
cleanup, and all tests benchmark
timwu20 Jun 2, 2021
615ee92
add README
timwu20 Jun 2, 2021
5e0e55c
rResult encode/decode and RegisterResult
timwu20 Jun 3, 2021
5edd132
wip cr feedback
timwu20 Jun 4, 2021
40feb5e
add licenses
timwu20 Jun 7, 2021
7120ebe
add custom primitive encode/decode
timwu20 Jun 7, 2021
3d35375
more cr feedback
timwu20 Jun 8, 2021
3b4fd36
wip
timwu20 Jun 14, 2021
a87135e
revise Result
timwu20 Jun 16, 2021
f8174cd
wip VaryingDataType and VaryingDataTypeSlice
timwu20 Jun 19, 2021
a94b297
refactor VaryingDataType and add VaryingDataTypeSlice
timwu20 Jun 21, 2021
e8b7652
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
4a65e58
WIP/Integrate scale pkg into lib/babe
jimjbrettj Jun 22, 2021
fd885c3
fixed error unmarshaling in errors.go
jimjbrettj Jun 22, 2021
847084e
WIP/Integrate scale into lib/babe
jimjbrettj Jun 22, 2021
0f8006b
integrate scale package into babe library
jimjbrettj Jun 22, 2021
d4bed00
fix result.set with nil value
timwu20 Jun 22, 2021
7f81d13
WIP/refactor babe errors to utilize new scale pkg
jimjbrettj Jun 22, 2021
6322ef6
Integrate scale pkg into babe tests
jimjbrettj Jun 22, 2021
3b679a2
create init structs for dispatch outcome errors
jimjbrettj Jun 22, 2021
6308a04
WIP/refactor babe error handling to utiliize new scale pkg features
jimjbrettj Jun 22, 2021
ce14097
WIP scale/babe integration. Closer but still errors
jimjbrettj Jun 23, 2021
090bf45
WIP/Fix type issues in babe refactor
jimjbrettj Jun 23, 2021
71d2b5e
Comments on issues to fix in for babe error handling
jimjbrettj Jun 23, 2021
1c74606
WIP/refactor babe error handling with new scale pkg
jimjbrettj Jun 24, 2021
694a8f4
resolve type issue
jimjbrettj Jun 24, 2021
f015dbf
fixed unknown error data populating issue
jimjbrettj Jun 24, 2021
245c5b1
WIP/Get module data to be populated when unmarshalling
jimjbrettj Jun 24, 2021
8426b31
resolved data population issue
jimjbrettj Jun 24, 2021
8240997
WIP/Finish babe error handling refactor
jimjbrettj Jun 25, 2021
4303908
rebase with development
jimjbrettj Jun 25, 2021
66d57e8
merge
jimjbrettj Jun 25, 2021
54067f9
final merge changes
jimjbrettj Jun 25, 2021
a38f458
added further testing for dispatch errors
jimjbrettj Jun 25, 2021
d7de542
refactor unknown transaction errors
jimjbrettj Jun 25, 2021
a09cf72
refactor error handling
jimjbrettj Jun 25, 2021
e57dc02
inital integration of scale pkg into babe
jimjbrettj Jun 25, 2021
ad794ab
remove changes in scale pkg
jimjbrettj Jun 25, 2021
bc72160
fix leftover comments
jimjbrettj Jun 28, 2021
6b13373
reorganize receivers
jimjbrettj Jun 28, 2021
52257ff
formatting
jimjbrettj Jun 28, 2021
ef42941
lint and tidy
jimjbrettj Jun 28, 2021
d1b9934
use marshal to encode block body
jimjbrettj Jun 28, 2021
bb281d4
chore: replace time.After with time.NewTicker (#1650)
edwardmack Jun 28, 2021
f7429ff
cr revisions
jimjbrettj Jun 29, 2021
a81844e
feat(dot/telemetry): implement telemetry message network_state (#1618)
edwardmack Jun 30, 2021
6797e77
WIP/use results for unmarshalling
jimjbrettj Jun 30, 2021
902d83d
fixed it
timwu20 Jun 30, 2021
94f3b2f
use result type for dispatch error
jimjbrettj Jun 30, 2021
7f37748
WIP/Finish result implementation
jimjbrettj Jun 30, 2021
baebb9c
WIP/Fix decoding custom VDT types
jimjbrettj Jun 30, 2021
67ef09d
use results for unmarshalling dispatchErrors
jimjbrettj Jul 1, 2021
ce86b82
cleanup
jimjbrettj Jul 1, 2021
cbbec0a
add mtx
timwu20 Apr 30, 2021
e08ebc9
add variable data type interface, test to compare old vs new encoding
timwu20 May 4, 2021
be12db4
wip
timwu20 May 6, 2021
e2cabfb
[]byte, string decoding
timwu20 May 14, 2021
d22fe73
encodeBool and tests
timwu20 May 14, 2021
907ad96
refactor tests, include optionality tests
timwu20 May 20, 2021
b975029
use shared tests in decode
timwu20 May 21, 2021
396bbfa
struct decode tests, and unmarshal refactor
timwu20 May 26, 2021
6909b26
wip
timwu20 May 27, 2021
a593a26
decode of VariantDataType, wip tests
timwu20 May 28, 2021
0fdb5c8
add optionality testing
timwu20 May 28, 2021
1392c04
fix struct tests and optionality tests
timwu20 May 31, 2021
e08acda
test VaryingDataType
timwu20 Jun 1, 2021
6f98539
wip decode refactor, use reflect.Value as passed param
timwu20 Jun 1, 2021
44ae538
repurpose int and uint as compact length encoded integers, remove unn…
timwu20 Jun 1, 2021
dc07d71
cleanup, and all tests benchmark
timwu20 Jun 2, 2021
9c199cf
add README
timwu20 Jun 2, 2021
30ff115
rResult encode/decode and RegisterResult
timwu20 Jun 3, 2021
aaf9e6a
wip cr feedback
timwu20 Jun 4, 2021
eb3eadd
add licenses
timwu20 Jun 7, 2021
7da8a9f
add custom primitive encode/decode
timwu20 Jun 7, 2021
5b0bf5c
more cr feedback
timwu20 Jun 8, 2021
d44f0ba
wip
timwu20 Jun 14, 2021
bee10b4
revise Result
timwu20 Jun 16, 2021
43f21af
wip VaryingDataType and VaryingDataTypeSlice
timwu20 Jun 19, 2021
d1bd74f
refactor VaryingDataType and add VaryingDataTypeSlice
timwu20 Jun 21, 2021
20f84c2
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
c1089fc
WIP/Integrate scale pkg into lib/babe
jimjbrettj Jun 22, 2021
e642765
fixed error unmarshaling in errors.go
jimjbrettj Jun 22, 2021
ca95468
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
5963e8a
WIP/Integrate scale into lib/babe
jimjbrettj Jun 22, 2021
44022be
integrate scale package into babe library
jimjbrettj Jun 22, 2021
7269cae
fix result.set with nil value
timwu20 Jun 22, 2021
ea9f3d7
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
6da0284
WIP/refactor babe errors to utilize new scale pkg
jimjbrettj Jun 22, 2021
8ea705e
Integrate scale pkg into babe tests
jimjbrettj Jun 22, 2021
51a81c3
create init structs for dispatch outcome errors
jimjbrettj Jun 22, 2021
f0d7d0d
WIP/refactor babe error handling to utiliize new scale pkg features
jimjbrettj Jun 22, 2021
0bad248
WIP scale/babe integration. Closer but still errors
jimjbrettj Jun 23, 2021
f99b1dd
WIP/Fix type issues in babe refactor
jimjbrettj Jun 23, 2021
261842a
Comments on issues to fix in for babe error handling
jimjbrettj Jun 23, 2021
fd28d2c
WIP/refactor babe error handling with new scale pkg
jimjbrettj Jun 24, 2021
1e1b020
resolve type issue
jimjbrettj Jun 24, 2021
b3e554e
fixed unknown error data populating issue
jimjbrettj Jun 24, 2021
a1611ae
WIP/Get module data to be populated when unmarshalling
jimjbrettj Jun 24, 2021
0052117
resolved data population issue
jimjbrettj Jun 24, 2021
c2a2cf3
add mtx
timwu20 Apr 30, 2021
a2b2ccb
add variable data type interface, test to compare old vs new encoding
timwu20 May 4, 2021
dc52cf9
wip
timwu20 May 6, 2021
23ace4a
[]byte, string decoding
timwu20 May 14, 2021
91731d3
encodeBool and tests
timwu20 May 14, 2021
a5dcf60
refactor tests, include optionality tests
timwu20 May 20, 2021
73172f6
use shared tests in decode
timwu20 May 21, 2021
681384a
struct decode tests, and unmarshal refactor
timwu20 May 26, 2021
0770139
wip
timwu20 May 27, 2021
9cb4d82
decode of VariantDataType, wip tests
timwu20 May 28, 2021
1b7bc6b
add optionality testing
timwu20 May 28, 2021
7c87050
fix struct tests and optionality tests
timwu20 May 31, 2021
1526f74
test VaryingDataType
timwu20 Jun 1, 2021
7cc203d
wip decode refactor, use reflect.Value as passed param
timwu20 Jun 1, 2021
bfbbe9a
repurpose int and uint as compact length encoded integers, remove unn…
timwu20 Jun 1, 2021
a468d7d
cleanup, and all tests benchmark
timwu20 Jun 2, 2021
8c76485
add README
timwu20 Jun 2, 2021
4bc40b2
rResult encode/decode and RegisterResult
timwu20 Jun 3, 2021
9c357c7
wip cr feedback
timwu20 Jun 4, 2021
2d3c8c8
add licenses
timwu20 Jun 7, 2021
56211c1
add custom primitive encode/decode
timwu20 Jun 7, 2021
536e60e
more cr feedback
timwu20 Jun 8, 2021
7c44925
wip
timwu20 Jun 14, 2021
8e3b243
revise Result
timwu20 Jun 16, 2021
aca7ffa
wip VaryingDataType and VaryingDataTypeSlice
timwu20 Jun 19, 2021
69f10de
refactor VaryingDataType and add VaryingDataTypeSlice
timwu20 Jun 21, 2021
8419c26
integrate scale pkg into lib/transaction
jimjbrettj Jun 21, 2021
473fc1f
WIP/Integrate scale into lib/babe
jimjbrettj Jun 22, 2021
63146c9
integrate scale package into babe library
jimjbrettj Jun 22, 2021
62e2d34
fix result.set with nil value
timwu20 Jun 22, 2021
8935590
WIP/refactor babe errors to utilize new scale pkg
jimjbrettj Jun 22, 2021
8cfcb12
Integrate scale pkg into babe tests
jimjbrettj Jun 22, 2021
30b14c5
create init structs for dispatch outcome errors
jimjbrettj Jun 22, 2021
e6b2918
WIP/refactor babe error handling to utiliize new scale pkg features
jimjbrettj Jun 22, 2021
961fb11
WIP scale/babe integration. Closer but still errors
jimjbrettj Jun 23, 2021
93929d1
WIP/Fix type issues in babe refactor
jimjbrettj Jun 23, 2021
849eaf5
resolve type issue
jimjbrettj Jun 24, 2021
1a614b6
fixed unknown error data populating issue
jimjbrettj Jun 24, 2021
097c3cf
WIP/Get module data to be populated when unmarshalling
jimjbrettj Jun 24, 2021
0bc78ef
resolved data population issue
jimjbrettj Jun 24, 2021
c333acc
WIP/Finish babe error handling refactor
jimjbrettj Jun 25, 2021
77387ad
rebase with development
jimjbrettj Jun 25, 2021
0c2d5e3
final merge changes
jimjbrettj Jun 25, 2021
0d23e32
added further testing for dispatch errors
jimjbrettj Jun 25, 2021
3d4463b
refactor unknown transaction errors
jimjbrettj Jun 25, 2021
25bd7e9
refactor error handling
jimjbrettj Jun 25, 2021
0b9baf7
inital integration of scale pkg into babe
jimjbrettj Jun 25, 2021
187f255
remove changes in scale pkg
jimjbrettj Jun 25, 2021
6968e58
fix leftover comments
jimjbrettj Jun 28, 2021
52e0a5d
reorganize receivers
jimjbrettj Jun 28, 2021
580af87
formatting
jimjbrettj Jun 28, 2021
b9b1133
lint and tidy
jimjbrettj Jun 28, 2021
a6358c4
use marshal to encode block body
jimjbrettj Jun 28, 2021
949aba0
cr revisions
jimjbrettj Jun 29, 2021
c7bfc64
WIP/use results for unmarshalling
jimjbrettj Jun 30, 2021
b64ffb9
fixed it
timwu20 Jun 30, 2021
e5eb888
use result type for dispatch error
jimjbrettj Jun 30, 2021
67cf81c
WIP/Finish result implementation
jimjbrettj Jun 30, 2021
7385b11
WIP/Fix decoding custom VDT types
jimjbrettj Jun 30, 2021
64001ee
use results for unmarshalling dispatchErrors
jimjbrettj Jul 1, 2021
580a392
cleanup
jimjbrettj Jul 1, 2021
f286e15
merge
jimjbrettj Jul 1, 2021
47f2050
Merge branch 'jimmy/integrateScalePkg' of github.com:ChainSafe/gossam…
jimjbrettj Jul 1, 2021
f1eff85
lint
jimjbrettj Jul 1, 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
9 changes: 7 additions & 2 deletions chain/dev/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"id": "dev",
"chainType": "Local",
"bootNodes": [],
"telemetryEndpoints": null,
"telemetryEndpoints": [
[
"wss://telemetry.polkadot.io/submit/",
0
]
],
"protocolId": "/gossamer/dev/0",
"genesis": {
"raw": {
Expand Down Expand Up @@ -32,4 +37,4 @@
"forkBlocks": null,
"badBlocks": null,
"consensusEngine": ""
}
}
8 changes: 7 additions & 1 deletion chain/gssmr/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"id": "gssmr",
"chainType": "Local",
"bootNodes": [],
"telemetryEndpoints": [
[
"wss://telemetry.polkadot.io/submit/",
0
]
],
"protocolId": "/gossamer/gssmr/0",
"genesis": {
"raw": {
Expand Down Expand Up @@ -40,4 +46,4 @@
"forkBlocks": null,
"badBlocks": null,
"consensusEngine": ""
}
}
5 changes: 5 additions & 0 deletions dot/core/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ func (s *Service) HandleTransactionMessage(msg *network.TransactionMessage) (boo

return len(msg.Extrinsics) > 0, nil
}

// TransactionsCount returns number for pending transactions in pool
func (s *Service) TransactionsCount() int {
return len(s.transactionState.PendingInPool())
}
6 changes: 3 additions & 3 deletions dot/core/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"
"time"

. "github.com/ChainSafe/gossamer/dot/core/mocks"
. "github.com/ChainSafe/gossamer/dot/core/mocks" // nolint
"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
Expand All @@ -38,7 +38,7 @@ import (

func TestService_ProcessBlockAnnounceMessage(t *testing.T) {
// TODO: move to sync package
net := new(MockNetwork)
net := new(MockNetwork) // nolint

cfg := &Config{
Network: net,
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestService_HandleTransactionMessage(t *testing.T) {
ks := keystore.NewGlobalKeystore()
ks.Acco.Insert(kp)

bp := new(MockBlockProducer)
bp := new(MockBlockProducer) // nolint
blockC := make(chan types.Block)
bp.On("GetBlockChannel", nil).Return(blockC)

Expand Down
8 changes: 6 additions & 2 deletions dot/network/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ func (d *discovery) start() error {
// get all currently connected peers and use them to bootstrap the DHT
peers := d.h.Network().Peers()

t := time.NewTicker(startDHTTimeout)
defer t.Stop()
for {
if len(peers) > 0 {
break
}

select {
case <-time.After(startDHTTimeout):
case <-t.C:
logger.Debug("no peers yet, waiting to start DHT...")
// wait for peers to connect before starting DHT, otherwise DHT bootstrap nodes
// will be empty and we will fail to fill the routing table
Expand Down Expand Up @@ -169,11 +171,13 @@ func (d *discovery) advertise() {
}

func (d *discovery) checkPeerCount() {
t := time.NewTicker(connectToPeersTimeout)
defer t.Stop()
for {
select {
case <-d.ctx.Done():
return
case <-time.After(connectToPeersTimeout):
case <-t.C:
if len(d.h.Network().Peers()) > d.minPeers {
continue
}
Expand Down
14 changes: 14 additions & 0 deletions dot/network/mock_transaction_handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"io"
"math/big"
"os"
"sync"
"time"
Expand Down Expand Up @@ -315,11 +316,12 @@ main:

case <-ticker.C:
o := s.host.bwc.GetBandwidthTotals()
err := telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage(
telemetry.NewKeyValue("bandwidth_download", o.RateIn),
telemetry.NewKeyValue("bandwidth_upload", o.RateOut),
telemetry.NewKeyValue("msg", "system.interval"),
telemetry.NewKeyValue("peers", s.host.peerCount())))
err := telemetry.GetInstance().SendMessage(telemetry.NewBandwidthTM(o.RateIn, o.RateOut, s.host.peerCount()))
if err != nil {
logger.Debug("problem sending system.interval telemetry message", "error", err)
}

err = telemetry.GetInstance().SendMessage(telemetry.NewNetworkStateTM(s.host.h, s.Peers()))
if err != nil {
logger.Debug("problem sending system.interval telemetry message", "error", err)
}
Expand All @@ -333,19 +335,22 @@ func (s *Service) sentBlockIntervalTelemetry() {
if err != nil {
continue
}
bestHash := best.Hash()

finalized, err := s.blockState.GetFinalizedHeader(0, 0) //nolint
if err != nil {
continue
}

err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage(
telemetry.NewKeyValue("best", best.Hash().String()),
telemetry.NewKeyValue("finalized_hash", finalized.Hash().String()), //nolint
telemetry.NewKeyValue("finalized_height", finalized.Number), //nolint
telemetry.NewKeyValue("height", best.Number),
telemetry.NewKeyValue("msg", "system.interval"),
telemetry.NewKeyValue("txcount", 0), // todo (ed) determine where to get tx count
telemetry.NewKeyValue("used_state_cache_size", 0))) // todo (ed) determine where to get used_state_cache_size
finalizedHash := finalized.Hash()

err = telemetry.GetInstance().SendMessage(telemetry.NewBlockIntervalTM(
&bestHash,
best.Number,
&finalizedHash,
finalized.Number,
big.NewInt(int64(s.transactionHandler.TransactionsCount())),
big.NewInt(0), // todo (ed) determine where to get used_state_cache_size
))
if err != nil {
logger.Debug("problem sending system.interval telemetry message", "error", err)
}
Expand Down
1 change: 1 addition & 0 deletions dot/network/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func createTestService(t *testing.T, cfg *Config) (srvc *Service) {
if cfg.TransactionHandler == nil {
mocktxhandler := &MockTransactionHandler{}
mocktxhandler.On("HandleTransactionMessage", mock.AnythingOfType("*TransactionMessage")).Return(nil)
mocktxhandler.On("TransactionsCount").Return(0)
cfg.TransactionHandler = mocktxhandler
}

Expand Down
1 change: 1 addition & 0 deletions dot/network/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ type Syncer interface {
// TransactionHandler is the interface used by the transactions sub-protocol
type TransactionHandler interface {
HandleTransactionMessage(*TransactionMessage) (bool, error)
TransactionsCount() int
}
48 changes: 30 additions & 18 deletions dot/network/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ const (
badPeerThreshold int = -2
protectedPeerThreshold int = 7

defaultSlotDuration = time.Second * 6
defaultSlotDuration = time.Second * 6
defaultHandleResponseQueueDuration = time.Second
defaultPrunePeersDuration = time.Second * 30
)

var (
Expand Down Expand Up @@ -132,26 +134,30 @@ type syncQueue struct {
goal int64 // goal block number we are trying to sync to
currStart, currEnd int64 // the start and end of the BlockResponse we are currently handling; 0 and 0 if we are not currently handling any

benchmarker *syncBenchmarker
benchmarker *syncBenchmarker
handleResponseQueueDuration time.Duration
prunePeersDuration time.Duration
}

func newSyncQueue(s *Service) *syncQueue {
ctx, cancel := context.WithCancel(s.ctx)

return &syncQueue{
s: s,
slotDuration: defaultSlotDuration,
ctx: ctx,
cancel: cancel,
peerScore: new(sync.Map),
requestData: new(sync.Map),
requestDataByHash: new(sync.Map),
justificationRequestData: new(sync.Map),
requestCh: make(chan *syncRequest, blockRequestBufferSize),
responses: []*types.BlockData{},
responseCh: make(chan []*types.BlockData, blockResponseBufferSize),
benchmarker: newSyncBenchmarker(),
buf: make([]byte, maxBlockResponseSize),
s: s,
slotDuration: defaultSlotDuration,
ctx: ctx,
cancel: cancel,
peerScore: new(sync.Map),
requestData: new(sync.Map),
requestDataByHash: new(sync.Map),
justificationRequestData: new(sync.Map),
requestCh: make(chan *syncRequest, blockRequestBufferSize),
responses: []*types.BlockData{},
responseCh: make(chan []*types.BlockData, blockResponseBufferSize),
benchmarker: newSyncBenchmarker(),
buf: make([]byte, maxBlockResponseSize),
handleResponseQueueDuration: defaultHandleResponseQueueDuration,
prunePeersDuration: defaultPrunePeersDuration,
}
}

Expand All @@ -176,10 +182,12 @@ func (q *syncQueue) syncAtHead() {
q.s.syncer.SetSyncing(true)
q.s.noGossip = true // don't gossip messages until we're at the head

t := time.NewTicker(q.slotDuration * 2)
defer t.Stop()
for {
select {
// sleep for average block time TODO: make this configurable from slot duration
case <-time.After(q.slotDuration * 2):
case <-t.C:
case <-q.ctx.Done():
return
}
Expand Down Expand Up @@ -214,9 +222,11 @@ func (q *syncQueue) syncAtHead() {
}

func (q *syncQueue) handleResponseQueue() {
t := time.NewTicker(q.handleResponseQueueDuration)
defer t.Stop()
for {
select {
case <-time.After(time.Second):
case <-t.C:
case <-q.ctx.Done():
return
}
Expand Down Expand Up @@ -260,9 +270,11 @@ func (q *syncQueue) handleResponseQueue() {

// prune peers with low score and connect to new peers
func (q *syncQueue) prunePeers() {
t := time.NewTicker(q.prunePeersDuration)
defer t.Stop()
for {
select {
case <-time.After(time.Second * 30):
case <-t.C:
case <-q.ctx.Done():
return
}
Expand Down
1 change: 1 addition & 0 deletions dot/network/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewMockSyncer() *MockSyncer {
func NewMockTransactionHandler() *MockTransactionHandler {
mocktxhandler := new(MockTransactionHandler)
mocktxhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(nil)
mocktxhandler.On("TransactionsCount").Return(0)
return mocktxhandler
}

Expand Down
1 change: 1 addition & 0 deletions dot/network/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestHandleTransactionMessage(t *testing.T) {
basePath := utils.NewTestBasePath(t, "nodeA")
mockhandler := &MockTransactionHandler{}
mockhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(true, nil)
mockhandler.On("TransactionsCount").Return(0)

config := &Config{
BasePath: basePath,
Expand Down
21 changes: 10 additions & 11 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,16 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node,
}

telemetry.GetInstance().AddConnections(gd.TelemetryEndpoints)

err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage(
telemetry.NewKeyValue("authority", cfg.Core.GrandpaAuthority),
telemetry.NewKeyValue("chain", sysSrvc.ChainName()),
telemetry.NewKeyValue("genesis_hash", stateSrvc.Block.GenesisHash().String()),
telemetry.NewKeyValue("implementation", sysSrvc.SystemName()),
telemetry.NewKeyValue("msg", "system.connected"),
telemetry.NewKeyValue("name", cfg.Global.Name),
telemetry.NewKeyValue("network_id", networkSrvc.NetworkState().PeerID),
telemetry.NewKeyValue("startup_time", strconv.FormatInt(time.Now().UnixNano(), 10)),
telemetry.NewKeyValue("version", sysSrvc.SystemVersion())))
genesisHash := stateSrvc.Block.GenesisHash()
err = telemetry.GetInstance().SendMessage(telemetry.NewSystemConnectedTM(
cfg.Core.GrandpaAuthority,
sysSrvc.ChainName(),
&genesisHash,
sysSrvc.SystemName(),
cfg.Global.Name,
networkSrvc.NetworkState().PeerID,
strconv.FormatInt(time.Now().UnixNano(), 10),
sysSrvc.SystemVersion()))
if err != nil {
logger.Debug("problem sending system.connected telemetry message", "err", err)
}
Expand Down
12 changes: 6 additions & 6 deletions dot/sync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ func (s *Service) handleBlock(block *types.Block) error {

logger.Debug("🔗 imported block", "number", block.Header.Number, "hash", block.Header.Hash())

err = telemetry.GetInstance().SendMessage(telemetry.NewTelemetryMessage( // nolint
telemetry.NewKeyValue("best", block.Header.Hash().String()),
telemetry.NewKeyValue("height", block.Header.Number.Uint64()),
telemetry.NewKeyValue("msg", "block.import"),
telemetry.NewKeyValue("origin", "NetworkInitialSync")))
blockHash := block.Header.Hash()
err = telemetry.GetInstance().SendMessage(telemetry.NewBlockImportTM(
&blockHash,
block.Header.Number,
"NetworkInitialSync"))
if err != nil {
logger.Trace("problem sending block.import telemetry message", "error", err)
logger.Debug("problem sending block.import telemetry message", "error", err)
}

return nil
Expand Down
Loading