-
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
feat(telemetry): send txpool.import telemetry msg #1966
Changes from 8 commits
fdf634d
fc230f6
2c3d283
949d91d
14deefc
0d76874
291ea45
58bcbd5
291fad3
455bd85
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 |
---|---|---|
|
@@ -42,75 +42,66 @@ func TestMain(m *testing.M) { | |
} | ||
|
||
func TestHandler_SendMulti(t *testing.T) { | ||
var wg sync.WaitGroup | ||
wg.Add(6) | ||
|
||
resultCh = make(chan []byte) | ||
|
||
go func() { | ||
genesisHash := common.MustHexToHash("0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3") | ||
|
||
GetInstance().SendMessage(NewSystemConnectedTM(false, "chain", &genesisHash, | ||
"systemName", "nodeName", "netID", "startTime", "0.1")) | ||
|
||
wg.Done() | ||
}() | ||
|
||
go func() { | ||
bh := common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6") | ||
GetInstance().SendMessage(NewBlockImportTM(&bh, big.NewInt(2), "NetworkInitialSync")) | ||
|
||
wg.Done() | ||
}() | ||
|
||
go func() { | ||
GetInstance().SendMessage(NewBandwidthTM(2, 3, 1)) | ||
|
||
wg.Done() | ||
}() | ||
|
||
go func() { | ||
bestHash := common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6") | ||
finalisedHash := common.MustHexToHash("0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2") | ||
GetInstance().SendMessage(NewBlockIntervalTM(&bestHash, big.NewInt(32375), &finalisedHash, | ||
big.NewInt(32256), big.NewInt(0), big.NewInt(1234))) | ||
|
||
wg.Done() | ||
}() | ||
|
||
go func() { | ||
bestHash := common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6") | ||
GetInstance().SendMessage(NewNotifyFinalizedTM(bestHash, "32375")) | ||
expected := [][]byte{ | ||
[]byte(`{"authority":false,"chain":"chain","genesis_hash":"0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3","implementation":"systemName","msg":"system.connected","name":"nodeName","network_id":"netID","startup_time":"startTime","ts":`), | ||
[]byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":2,"msg":"block.import","origin":"NetworkInitialSync","ts":`), | ||
[]byte(`{"bandwidth_download":2,"bandwidth_upload":3,"msg":"system.interval","peers":1,"ts":`), | ||
[]byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","finalized_hash":"0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2","finalized_height":32256,"height":32375,"msg":"system.interval","ts":`), //nolint | ||
[]byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":"32375","msg":"notify.finalized","ts":`), | ||
[]byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","msg":"prepared_block_for_proposing","number":"1","ts":`), | ||
[]byte(`{"future":2,"msg":"txpool.import","ready":1,"ts":`), | ||
} | ||
|
||
wg.Done() | ||
}() | ||
messages := []Message{ | ||
NewBandwidthTM(2, 3, 1), | ||
NewTxpoolImportTM(1, 2), | ||
|
||
func(genesisHash common.Hash) Message { | ||
return NewSystemConnectedTM(false, "chain", &genesisHash, | ||
"systemName", "nodeName", "netID", "startTime", "0.1") | ||
}(common.MustHexToHash("0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3")), | ||
Comment on lines
+59
to
+62
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. Why the wrapping function? That's quite complex, maybe put pre-defining arguments above |
||
|
||
func(bh common.Hash) Message { | ||
return NewBlockImportTM(&bh, big.NewInt(2), "NetworkInitialSync") | ||
}(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6")), | ||
|
||
func(bestHash, finalisedHash common.Hash) Message { | ||
return NewBlockIntervalTM(&bestHash, big.NewInt(32375), &finalisedHash, | ||
big.NewInt(32256), big.NewInt(0), big.NewInt(1234)) | ||
}( | ||
common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), | ||
common.MustHexToHash("0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2"), | ||
), | ||
|
||
NewNotifyFinalizedTM(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "32375"), | ||
NewPreparedBlockForProposingTM(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1"), | ||
} | ||
|
||
go func() { | ||
bestHash := common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c") | ||
GetInstance().SendMessage(NewPreparedBlockForProposingTM(bestHash, "1")) | ||
resultCh = make(chan []byte) | ||
|
||
wg.Done() | ||
}() | ||
var wg sync.WaitGroup | ||
for _, message := range messages { | ||
wg.Add(1) | ||
go func(msg Message) { | ||
GetInstance().SendMessage(msg) | ||
wg.Done() | ||
}(message) | ||
} | ||
|
||
wg.Wait() | ||
|
||
expected1 := []byte(`{"authority":false,"chain":"chain","genesis_hash":"0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3","implementation":"systemName","msg":"system.connected","name":"nodeName","network_id":"netID","startup_time":"startTime","ts":`) | ||
expected2 := []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":2,"msg":"block.import","origin":"NetworkInitialSync","ts":`) | ||
expected3 := []byte(`{"bandwidth_download":2,"bandwidth_upload":3,"msg":"system.interval","peers":1,"ts":`) | ||
expected4 := []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","finalized_hash":"0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2","finalized_height":32256,"height":32375,"msg":"system.interval","ts":`) // nolint | ||
expected5 := []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":"32375","msg":"notify.finalized","ts":`) | ||
expected6 := []byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","msg":"prepared_block_for_proposing","number":"1","ts":`) | ||
|
||
expected := [][]byte{expected1, expected3, expected4, expected5, expected2, expected6} | ||
|
||
var actual [][]byte | ||
for data := range resultCh { | ||
actual = append(actual, data) | ||
if len(actual) == 6 { | ||
if len(actual) == len(expected) { | ||
break | ||
} | ||
} | ||
|
||
sort.Slice(expected, func(i, j int) bool { | ||
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. I believe you can just use |
||
return bytes.Compare(expected[i], expected[j]) < 0 | ||
}) | ||
|
||
sort.Slice(actual, func(i, j int) bool { | ||
return bytes.Compare(actual[i], actual[j]) < 0 | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021 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 telemetry | ||
|
||
// txpoolImportTM holds `txpool.import` telemetry message, which is supposed to be | ||
// sent when a new transaction gets imported in the transaction pool. | ||
type txpoolImportTM struct { | ||
Ready uint `json:"ready"` | ||
Future uint `json:"future"` | ||
} | ||
kishansagathiya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// NewTxpoolImportTM creates a new txpoolImportTM struct | ||
func NewTxpoolImportTM(ready, future uint) Message { | ||
return &txpoolImportTM{ | ||
Ready: ready, | ||
Future: future, | ||
} | ||
} | ||
|
||
func (txpoolImportTM) messageType() string { | ||
return txPoolImportMsg | ||
} |
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.
nit please split this long line