diff --git a/dot/telemetry/afg_authority_set.go b/dot/telemetry/afg_authority_set.go index c064bed6ae..9a73584e4f 100644 --- a/dot/telemetry/afg_authority_set.go +++ b/dot/telemetry/afg_authority_set.go @@ -31,7 +31,6 @@ func NewAfgAuthoritySet(authorityID, authoritySetID, authorities string) *AfgAut } } -// MarshalJSON ... func (afg AfgAuthoritySet) MarshalJSON() ([]byte, error) { telemetryData := struct { afgAuthoritySetTM diff --git a/dot/telemetry/mailer_test.go b/dot/telemetry/mailer_test.go index 7aff974024..3276ec17e8 100644 --- a/dot/telemetry/mailer_test.go +++ b/dot/telemetry/mailer_test.go @@ -58,61 +58,39 @@ func newTestMailer(t *testing.T, handler http.HandlerFunc) (mailer *Mailer) { func TestHandler_SendMulti(t *testing.T) { t.Parallel() + firstHash := common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6") + secondHash := common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c") + expected := [][]byte{ - []byte(`{"authority":false,"chain":"chain","genesis_hash":"0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3","implementation":"systemName","name":"nodeName","network_id":"netID","startup_time":"startTime","version":"0.1","msg":"system.connected","ts":`), //nolint:lll + []byte(`{"authority":false,"chain":"chain","genesis_hash":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","implementation":"systemName","name":"nodeName","network_id":"netID","startup_time":"startTime","version":"0.1","msg":"system.connected","ts":`), //nolint:lll []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":2,"origin":"NetworkInitialSync","msg":"block.import","ts":`), //nolint:lll []byte(`{"bandwidth_download":2,"bandwidth_upload":3,"peers":1,"msg":"system.interval","ts":`), - []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":32375,"finalized_hash":"0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2","finalized_height":32256,"txcount":0,"used_state_cache_size":1234,"msg":"system.interval","ts":`), //nolint:lll - []byte(`{"best":[7,183,73,182,226,15,213,241,21,145,83,162,231,144,35,80,24,98,29,208,96,114,166,43,205,37,232,87,111,111,245,230],"height":"32375","msg":"notify.finalized","ts":`), //nolint:lll - []byte(`{"hash":[88,20,174,195,226,133,39,248,31,101,132,30,3,72,114,243,163,3,55,207,108,51,178,210,88,187,166,7,30,55,226,124],"number":"1","msg":"prepared_block_for_proposing","ts":`), //nolint:lll + []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":32375,"finalized_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","finalized_height":32256,"txcount":0,"used_state_cache_size":1234,"msg":"system.interval","ts":`), //nolint:lll + []byte(`{"best":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","height":"32375","msg":"notify.finalized","ts":`), //nolint:lll + []byte(`{"hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","number":"1","msg":"prepared_block_for_proposing","ts":`), //nolint:lll []byte(`{"ready":1,"future":2,"msg":"txpool.import","ts":`), - []byte(`{"authority_id":"authority_id","authority_set_id":"authority_set_id","authorities":"json-stringified-ids-of-authorities","msg":"afg.authority_set","ts`), //nolint:lll - []byte(`{"hash":[7,183,73,182,226,15,213,241,21,145,83,162,231,144,35,80,24,98,29,208,96,114,166,43,205,37,232,87,111,111,245,230],"number":"1","msg":"afg.finalized_blocks_up_to","ts":`), //nolint:lll - []byte(`{"target_hash":[88,20,174,195,226,133,39,248,31,101,132,30,3,72,114,243,163,3,55,207,108,51,178,210,88,187,166,7,30,55,226,124],"target_number":"1","contains_precommits_signed_by":[],"msg":"afg.received_commit","ts":`), //nolint:lll - []byte(`{"target_hash":[88,20,174,195,226,133,39,248,31,101,132,30,3,72,114,243,163,3,55,207,108,51,178,210,88,187,166,7,30,55,226,124],"target_number":"1","voter":"","msg":"afg.received_precommit","ts":`), //nolint:lll - []byte(`{"target_hash":[88,20,174,195,226,133,39,248,31,101,132,30,3,72,114,243,163,3,55,207,108,51,178,210,88,187,166,7,30,55,226,124],"target_number":"1","voter":"","msg":"afg.received_prevote","ts":`), //nolint:lll + []byte(`{"authority_id":"authority_id","authority_set_id":"authority_set_id","authorities":"json-stringified-ids-of-authorities","msg":"afg.authority_set","ts`), //nolint:lll + []byte(`{"hash":"0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6","number":"1","msg":"afg.finalized_blocks_up_to","ts":`), //nolint:lll + []byte(`{"target_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","target_number":"1","contains_precommits_signed_by":[],"msg":"afg.received_commit","ts":`), //nolint:lll + []byte(`{"target_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","target_number":"1","voter":"","msg":"afg.received_precommit","ts":`), //nolint:lll + []byte(`{"target_hash":"0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c","target_number":"1","voter":"","msg":"afg.received_prevote","ts":`), //nolint:lll } messages := []Message{ NewBandwidth(2, 3, 1), NewTxpoolImport(1, 2), - - func(genesisHash common.Hash) Message { - return NewSystemConnected(false, "chain", &genesisHash, - "systemName", "nodeName", "netID", "startTime", "0.1") - }(common.MustHexToHash("0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3")), - - func(bh common.Hash) Message { - return NewBlockImport(&bh, big.NewInt(2), "NetworkInitialSync") - }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6")), - - func(bestHash, finalisedHash common.Hash) Message { - return NewBlockInterval(&bestHash, big.NewInt(32375), &finalisedHash, - big.NewInt(32256), big.NewInt(0), big.NewInt(1234)) - }( - common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), - common.MustHexToHash("0x687197c11b4cf95374159843e7f46fbcd63558db981aaef01a8bac2a44a1d6b2"), - ), - + NewSystemConnected(false, "chain", &firstHash, + "systemName", "nodeName", "netID", "startTime", "0.1"), + NewBlockImport(&firstHash, big.NewInt(2), "NetworkInitialSync"), + NewBlockInterval(&firstHash, big.NewInt(32375), &secondHash, + big.NewInt(32256), big.NewInt(0), big.NewInt(1234)), NewAfgAuthoritySet("authority_id", "authority_set_id", "json-stringified-ids-of-authorities"), - NewAfgFinalizedBlocksUpTo( - common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), - NewAfgReceivedCommit( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1", []string{}), - NewAfgReceivedPrecommit( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1", ""), - NewAfgReceivedPrevote( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1", ""), - - NewNotifyFinalized( - common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), - "32375"), - NewPreparedBlockForProposing( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1"), + NewAfgFinalizedBlocksUpTo(firstHash, "1"), + NewAfgReceivedCommit(secondHash, "1", []string{}), + NewAfgReceivedPrecommit(secondHash, "1", ""), + NewAfgReceivedPrevote(secondHash, "1", ""), + NewNotifyFinalized(firstHash, "32375"), + NewPreparedBlockForProposing(secondHash, "1"), } upgrader := websocket.Upgrader{ @@ -262,8 +240,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { Hash: common.Hash{}, Number: "0", }, - expected: regexp.MustCompile(`^{"hash":\[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,` + - `0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\],"number":"0",` + + expected: regexp.MustCompile(`^{"hash":"0x[0]{64}","number":"0",` + `"msg":"afg.finalized_blocks_up_to","ts":"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:` + `[0-9]{2}.[0-9]+Z|([+-][0-9]{2}:[0-9]{2})"}$`), }, @@ -273,8 +250,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { TargetNumber: "0", Voter: "0x0", }, - expected: regexp.MustCompile(`^{"target_hash":\[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,` + - `0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\],"target_number":"0","voter":"0x0",` + + expected: regexp.MustCompile(`^{"target_hash":"0x[0]{64}","target_number":"0","voter":"0x0",` + `"msg":"afg.received_precommit","ts":"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:` + `[0-9]{2}.[0-9]+Z|([+-][0-9]{2}:[0-9]{2})"}$`), }, @@ -284,8 +260,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { TargetNumber: "0", Voter: "0x0", }, - expected: regexp.MustCompile(`^{"target_hash":\[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,` + - `0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\],"target_number":"0","voter":"0x0",` + + expected: regexp.MustCompile(`^{"target_hash":"0x[0]{64}","target_number":"0","voter":"0x0",` + `"msg":"afg.received_prevote","ts":"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:` + `[0-9]{2}.[0-9]+Z|([+-][0-9]{2}:[0-9]{2})"}$`), }, @@ -295,8 +270,8 @@ func TestTelemetryMarshalMessage(t *testing.T) { TargetNumber: "0", ContainsPrecommitsSignedBy: []string{"0x0", "0x1"}, }, - expected: regexp.MustCompile(`^{"target_hash":\[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,` + - `0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\],"target_number":"0","contains_precommits_signed_by":\["0x0","0x1"\],` + + expected: regexp.MustCompile(`^{"target_hash":"0x[0]{64}","target_number":"0",` + + `"contains_precommits_signed_by":\["0x0","0x1"\],` + `"msg":"afg.received_commit","ts":"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:` + `[0-9]{2}.[0-9]+Z|([+-][0-9]{2}:[0-9]{2})"}$`), }, @@ -315,8 +290,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { Best: common.Hash{}, Height: "0", }, - expected: regexp.MustCompile(`^{"best":\[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,` + - `0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\],"height":"0",` + + expected: regexp.MustCompile(`^{"best":"0x[0]{64}","height":"0",` + `"msg":"notify.finalized","ts":"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:` + `[0-9]{2}.[0-9]+Z|([+-][0-9]{2}:[0-9]{2})"}$`), }, @@ -325,8 +299,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { Hash: common.Hash{}, Number: "0", }, - expected: regexp.MustCompile(`^{"hash":\[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,` + - `0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\],"number":"0",` + + expected: regexp.MustCompile(`^{"hash":"0x[0]{64}","number":"0",` + `"msg":"prepared_block_for_proposing","ts":"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:` + `[0-9]{2}.[0-9]+Z|([+-][0-9]{2}:[0-9]{2})"}$`), }, diff --git a/lib/common/hash.go b/lib/common/hash.go index bcc3905047..6ca442e829 100644 --- a/lib/common/hash.go +++ b/lib/common/hash.go @@ -109,7 +109,7 @@ func (h *Hash) UnmarshalJSON(data []byte) error { } // MarshalJSON converts hash to hex data -func (h *Hash) MarshalJSON() ([]byte, error) { +func (h Hash) MarshalJSON() ([]byte, error) { return json.Marshal(h.String()) }