From 79c8b955bdfec68205a7b0b357ee3839e99ec286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20J=C3=BAnior?= Date: Thu, 13 Jan 2022 21:13:36 -0400 Subject: [PATCH 1/6] fix: telemetry hashes must to be in hexadecimal format --- dot/node_test.go | 3 +- dot/state/block_finalisation.go | 2 +- dot/state/storage_test.go | 3 +- dot/telemetry/afg_finalized_blocks_up_to.go | 6 +- dot/telemetry/afg_received.go | 18 ++--- dot/telemetry/mailer_test.go | 79 ++++++++++--------- dot/telemetry/notify_finalized.go | 4 +- dot/telemetry/prepared_block_for_proposing.go | 4 +- lib/babe/babe.go | 3 +- lib/grandpa/grandpa.go | 3 +- lib/grandpa/message_handler.go | 2 +- lib/grandpa/vote_message.go | 4 +- 12 files changed, 70 insertions(+), 61 deletions(-) diff --git a/dot/node_test.go b/dot/node_test.go index a32bd51f33..ec1690d85c 100644 --- a/dot/node_test.go +++ b/dot/node_test.go @@ -201,8 +201,9 @@ func TestInitNode_LoadGenesisData(t *testing.T) { ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) + bestHash := common.MustHexToHash("0x336743aadf42654d4ef91294b61a167c9ed8a42f7f327d08d1e3c99541047392") expectedArg := &telemetry.NotifyFinalized{ - Best: common.MustHexToHash("0x336743aadf42654d4ef91294b61a167c9ed8a42f7f327d08d1e3c99541047392"), + Best: &bestHash, Height: "0", } diff --git a/dot/state/block_finalisation.go b/dot/state/block_finalisation.go index 8557bf4721..d117dd16aa 100644 --- a/dot/state/block_finalisation.go +++ b/dot/state/block_finalisation.go @@ -173,7 +173,7 @@ func (bs *BlockState) SetFinalisedHash(hash common.Hash, round, setID uint64) er bs.telemetry.SendMessage( telemetry.NewNotifyFinalized( - header.Hash(), + &hash, header.Number.String(), ), ) diff --git a/dot/state/storage_test.go b/dot/state/storage_test.go index 8e61eefd1d..8893e7381d 100644 --- a/dot/state/storage_test.go +++ b/dot/state/storage_test.go @@ -196,11 +196,12 @@ func TestGetStorageChildAndGetStorageFromChild(t *testing.T) { require.NoError(t, err) _, genTrie, genHeader := genesis.NewTestGenesisWithTrieAndHeader(t) + genHash := genHeader.Hash() ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) telemetryMock.EXPECT().SendMessage(telemetry.NewNotifyFinalized( - genHeader.Hash(), + &genHash, "0", )) diff --git a/dot/telemetry/afg_finalized_blocks_up_to.go b/dot/telemetry/afg_finalized_blocks_up_to.go index a29d2fbd11..a204df9664 100644 --- a/dot/telemetry/afg_finalized_blocks_up_to.go +++ b/dot/telemetry/afg_finalized_blocks_up_to.go @@ -17,12 +17,12 @@ var _ Message = (*AfgFinalizedBlocksUpTo)(nil) // AfgFinalizedBlocksUpTo holds telemetry message of type `afg.finalized_blocks_up_to`, // which is supposed to be sent when GRANDPA client finalises new blocks. type AfgFinalizedBlocksUpTo struct { - Hash common.Hash `json:"hash"` - Number string `json:"number"` + Hash *common.Hash `json:"hash"` + Number string `json:"number"` } // NewAfgFinalizedBlocksUpTo creates a new AfgFinalizedBlocksUpToTM struct. -func NewAfgFinalizedBlocksUpTo(hash common.Hash, number string) *AfgFinalizedBlocksUpTo { +func NewAfgFinalizedBlocksUpTo(hash *common.Hash, number string) *AfgFinalizedBlocksUpTo { return &AfgFinalizedBlocksUpTo{ Hash: hash, Number: number, diff --git a/dot/telemetry/afg_received.go b/dot/telemetry/afg_received.go index a1df631503..d94b4d268e 100644 --- a/dot/telemetry/afg_received.go +++ b/dot/telemetry/afg_received.go @@ -19,9 +19,9 @@ var ( ) type afgReceived struct { - TargetHash common.Hash `json:"target_hash"` - TargetNumber string `json:"target_number"` - Voter string `json:"voter"` + TargetHash *common.Hash `json:"target_hash"` + TargetNumber string `json:"target_number"` + Voter string `json:"voter"` } // AfgReceivedPrecommit holds `afg.received_precommit` telemetry message which is @@ -29,7 +29,7 @@ type afgReceived struct { type AfgReceivedPrecommit afgReceived // NewAfgReceivedPrecommit gets a new AfgReceivedPrecommitTM struct. -func NewAfgReceivedPrecommit(targetHash common.Hash, targetNumber, voter string) *AfgReceivedPrecommit { +func NewAfgReceivedPrecommit(targetHash *common.Hash, targetNumber, voter string) *AfgReceivedPrecommit { return &AfgReceivedPrecommit{ TargetHash: targetHash, TargetNumber: targetNumber, @@ -56,7 +56,7 @@ func (afg AfgReceivedPrecommit) MarshalJSON() ([]byte, error) { type AfgReceivedPrevote afgReceived // NewAfgReceivedPrevote gets a new AfgReceivedPrevote* struct. -func NewAfgReceivedPrevote(targetHash common.Hash, targetNumber, voter string) *AfgReceivedPrevote { +func NewAfgReceivedPrevote(targetHash *common.Hash, targetNumber, voter string) *AfgReceivedPrevote { return &AfgReceivedPrevote{ TargetHash: targetHash, TargetNumber: targetNumber, @@ -83,13 +83,13 @@ type afgReceivedCommitTM AfgReceivedCommit // AfgReceivedCommit holds `afg.received_commit` telemetry message which is // supposed to be sent when grandpa client receives a commit. type AfgReceivedCommit struct { - TargetHash common.Hash `json:"target_hash"` - TargetNumber string `json:"target_number"` - ContainsPrecommitsSignedBy []string `json:"contains_precommits_signed_by"` + TargetHash *common.Hash `json:"target_hash"` + TargetNumber string `json:"target_number"` + ContainsPrecommitsSignedBy []string `json:"contains_precommits_signed_by"` } // NewAfgReceivedCommit gets a new AfgReceivedCommit* struct. -func NewAfgReceivedCommit(targetHash common.Hash, targetNumber string, +func NewAfgReceivedCommit(targetHash *common.Hash, targetNumber string, containsPrecommitsSignedBy []string) *AfgReceivedCommit { return &AfgReceivedCommit{ TargetHash: targetHash, diff --git a/dot/telemetry/mailer_test.go b/dot/telemetry/mailer_test.go index 7aff974024..4e2ec2c71d 100644 --- a/dot/telemetry/mailer_test.go +++ b/dot/telemetry/mailer_test.go @@ -63,14 +63,14 @@ func TestHandler_SendMulti(t *testing.T) { []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","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{ @@ -95,23 +95,34 @@ func TestHandler_SendMulti(t *testing.T) { ), NewAfgAuthoritySet("authority_id", "authority_set_id", "json-stringified-ids-of-authorities"), - NewAfgFinalizedBlocksUpTo( - common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), - NewAfgReceivedCommit( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), + + func(hash common.Hash, number string) Message { + return NewAfgFinalizedBlocksUpTo(&hash, number) + }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), + + func(targetHash common.Hash, targetNumber string, containsPrecommitsSignedBy []string) Message { + return NewAfgReceivedCommit(&targetHash, targetNumber, containsPrecommitsSignedBy) + }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1", []string{}), - NewAfgReceivedPrecommit( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), + + func(targetHash common.Hash, targetNumber string, voter string) Message { + return NewAfgReceivedPrecommit(&targetHash, targetNumber, voter) + }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1", ""), - NewAfgReceivedPrevote( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), + + func(targetHash common.Hash, targetNumber string, voter string) Message { + return NewAfgReceivedPrevote(&targetHash, targetNumber, voter) + }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1", ""), - NewNotifyFinalized( - common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), + func(best common.Hash, height string) Message { + return NewNotifyFinalized(&best, height) + }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "32375"), - NewPreparedBlockForProposing( - common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), + + func(hash common.Hash, number string) Message { + return NewPreparedBlockForProposing(&hash, number) + }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1"), } @@ -259,44 +270,40 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "AfgFinalizedBlocksUpTo_marshal": { message: &AfgFinalizedBlocksUpTo{ - Hash: common.Hash{}, + 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})"}$`), }, "AfgReceivedPrecommit_marshal": { message: &AfgReceivedPrecommit{ - TargetHash: common.Hash{}, + TargetHash: &common.Hash{}, 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})"}$`), }, "AfgReceivedPrevoteTM_marshal": { message: &AfgReceivedPrevote{ - TargetHash: common.Hash{}, + TargetHash: &common.Hash{}, 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})"}$`), }, "AfgReceivedCommit_marshal": { message: &AfgReceivedCommit{ - TargetHash: common.Hash{}, + TargetHash: &common.Hash{}, 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})"}$`), }, @@ -312,21 +319,19 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "NotifyFinalized_marshal": { message: &NotifyFinalized{ - Best: common.Hash{}, + 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})"}$`), }, "PreparedBlockForProposing_marshal": { message: &PreparedBlockForProposing{ - Hash: common.Hash{}, + 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/dot/telemetry/notify_finalized.go b/dot/telemetry/notify_finalized.go index 72e7258b51..af05959bd3 100644 --- a/dot/telemetry/notify_finalized.go +++ b/dot/telemetry/notify_finalized.go @@ -17,13 +17,13 @@ var _ Message = (*NotifyFinalized)(nil) // NotifyFinalized holds `notify.finalized` telemetry message, which is // supposed to be send when a new block gets finalised. type NotifyFinalized struct { - Best common.Hash `json:"best"` + Best *common.Hash `json:"best"` // Height is same as block.Header.Number Height string `json:"height"` } // NewNotifyFinalized gets a new NotifyFinalizedTM struct. -func NewNotifyFinalized(best common.Hash, height string) *NotifyFinalized { +func NewNotifyFinalized(best *common.Hash, height string) *NotifyFinalized { return &NotifyFinalized{ Best: best, Height: height, diff --git a/dot/telemetry/prepared_block_for_proposing.go b/dot/telemetry/prepared_block_for_proposing.go index 7d90ffbaa1..c6d005c9c1 100644 --- a/dot/telemetry/prepared_block_for_proposing.go +++ b/dot/telemetry/prepared_block_for_proposing.go @@ -17,13 +17,13 @@ var _ Message = (*PreparedBlockForProposing)(nil) // PreparedBlockForProposing holds a 'prepared_block_for_proposing' telemetry // message, which is supposed to be sent when a new block is built. type PreparedBlockForProposing struct { - Hash common.Hash `json:"hash"` + Hash *common.Hash `json:"hash"` // Height of the chain, Block.Header.Number Number string `json:"number"` } // NewPreparedBlockForProposing gets a new PreparedBlockForProposingTM struct. -func NewPreparedBlockForProposing(hash common.Hash, number string) *PreparedBlockForProposing { +func NewPreparedBlockForProposing(hash *common.Hash, number string) *PreparedBlockForProposing { return &PreparedBlockForProposing{ Hash: hash, Number: number, diff --git a/lib/babe/babe.go b/lib/babe/babe.go index 548bf18e9d..1ddb71caf1 100644 --- a/lib/babe/babe.go +++ b/lib/babe/babe.go @@ -543,9 +543,10 @@ func (b *Service) handleSlot(epoch, slotNum uint64) error { "built block with parent hash %s, header %s and body %s", parent.Hash(), block.Header.String(), block.Body) + blockHash := block.Header.Hash() b.telemetry.SendMessage( telemetry.NewPreparedBlockForProposing( - block.Header.Hash(), + &blockHash, block.Header.Number.String(), ), ) diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index 4f80c62323..e20b093960 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -646,8 +646,9 @@ func (s *Service) attemptToFinalize() error { logger.Debugf("sending CommitMessage: %v", cm) s.network.GossipMessage(msg) + hash := s.head.Hash() s.telemetry.SendMessage(telemetry.NewAfgFinalizedBlocksUpTo( - s.head.Hash(), + &hash, s.head.Number.String(), )) diff --git a/lib/grandpa/message_handler.go b/lib/grandpa/message_handler.go index 0f9db8da71..4d73d5af9e 100644 --- a/lib/grandpa/message_handler.go +++ b/lib/grandpa/message_handler.go @@ -112,7 +112,7 @@ func (h *MessageHandler) handleCommitMessage(msg *CommitMessage) error { h.telemetry.SendMessage( telemetry.NewAfgReceivedCommit( - msg.Vote.Hash, + &msg.Vote.Hash, fmt.Sprint(msg.Vote.Number), containsPrecommitsSignedBy, ), diff --git a/lib/grandpa/vote_message.go b/lib/grandpa/vote_message.go index 827d400cf2..6f3fd3928c 100644 --- a/lib/grandpa/vote_message.go +++ b/lib/grandpa/vote_message.go @@ -42,7 +42,7 @@ func (s *Service) receiveVoteMessages(ctx context.Context) { case prevote, primaryProposal: s.telemetry.SendMessage( telemetry.NewAfgReceivedPrevote( - vm.Message.Hash, + &vm.Message.Hash, fmt.Sprint(vm.Message.Number), vm.Message.AuthorityID.String(), ), @@ -50,7 +50,7 @@ func (s *Service) receiveVoteMessages(ctx context.Context) { case precommit: s.telemetry.SendMessage( telemetry.NewAfgReceivedPrecommit( - vm.Message.Hash, + &vm.Message.Hash, fmt.Sprint(vm.Message.Number), vm.Message.AuthorityID.String(), ), From 2dd9160d16093866354bfcacf03cb448c9833c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20J=C3=BAnior?= Date: Thu, 13 Jan 2022 21:36:52 -0400 Subject: [PATCH 2/6] chore: fix `lll` lint warn --- dot/telemetry/mailer_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dot/telemetry/mailer_test.go b/dot/telemetry/mailer_test.go index 4e2ec2c71d..9c1a47c300 100644 --- a/dot/telemetry/mailer_test.go +++ b/dot/telemetry/mailer_test.go @@ -303,7 +303,8 @@ func TestTelemetryMarshalMessage(t *testing.T) { TargetNumber: "0", ContainsPrecommitsSignedBy: []string{"0x0", "0x1"}, }, - expected: regexp.MustCompile(`^{"target_hash":"0x[0]{64}","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})"}$`), }, From d9addfdef82a03d71e69c1d1756ace798568fb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20J=C3=BAnior?= Date: Fri, 14 Jan 2022 11:31:23 -0400 Subject: [PATCH 3/6] chore: use strict type in `common.Hash.MarshaJSON()` --- dot/telemetry/afg_authority_set.go | 1 - dot/telemetry/afg_finalized_blocks_up_to.go | 6 +++--- dot/telemetry/afg_received.go | 18 +++++++++--------- dot/telemetry/mailer_test.go | 16 ++++++++-------- lib/common/hash.go | 2 +- 5 files changed, 21 insertions(+), 22 deletions(-) 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/afg_finalized_blocks_up_to.go b/dot/telemetry/afg_finalized_blocks_up_to.go index a204df9664..a29d2fbd11 100644 --- a/dot/telemetry/afg_finalized_blocks_up_to.go +++ b/dot/telemetry/afg_finalized_blocks_up_to.go @@ -17,12 +17,12 @@ var _ Message = (*AfgFinalizedBlocksUpTo)(nil) // AfgFinalizedBlocksUpTo holds telemetry message of type `afg.finalized_blocks_up_to`, // which is supposed to be sent when GRANDPA client finalises new blocks. type AfgFinalizedBlocksUpTo struct { - Hash *common.Hash `json:"hash"` - Number string `json:"number"` + Hash common.Hash `json:"hash"` + Number string `json:"number"` } // NewAfgFinalizedBlocksUpTo creates a new AfgFinalizedBlocksUpToTM struct. -func NewAfgFinalizedBlocksUpTo(hash *common.Hash, number string) *AfgFinalizedBlocksUpTo { +func NewAfgFinalizedBlocksUpTo(hash common.Hash, number string) *AfgFinalizedBlocksUpTo { return &AfgFinalizedBlocksUpTo{ Hash: hash, Number: number, diff --git a/dot/telemetry/afg_received.go b/dot/telemetry/afg_received.go index d94b4d268e..a1df631503 100644 --- a/dot/telemetry/afg_received.go +++ b/dot/telemetry/afg_received.go @@ -19,9 +19,9 @@ var ( ) type afgReceived struct { - TargetHash *common.Hash `json:"target_hash"` - TargetNumber string `json:"target_number"` - Voter string `json:"voter"` + TargetHash common.Hash `json:"target_hash"` + TargetNumber string `json:"target_number"` + Voter string `json:"voter"` } // AfgReceivedPrecommit holds `afg.received_precommit` telemetry message which is @@ -29,7 +29,7 @@ type afgReceived struct { type AfgReceivedPrecommit afgReceived // NewAfgReceivedPrecommit gets a new AfgReceivedPrecommitTM struct. -func NewAfgReceivedPrecommit(targetHash *common.Hash, targetNumber, voter string) *AfgReceivedPrecommit { +func NewAfgReceivedPrecommit(targetHash common.Hash, targetNumber, voter string) *AfgReceivedPrecommit { return &AfgReceivedPrecommit{ TargetHash: targetHash, TargetNumber: targetNumber, @@ -56,7 +56,7 @@ func (afg AfgReceivedPrecommit) MarshalJSON() ([]byte, error) { type AfgReceivedPrevote afgReceived // NewAfgReceivedPrevote gets a new AfgReceivedPrevote* struct. -func NewAfgReceivedPrevote(targetHash *common.Hash, targetNumber, voter string) *AfgReceivedPrevote { +func NewAfgReceivedPrevote(targetHash common.Hash, targetNumber, voter string) *AfgReceivedPrevote { return &AfgReceivedPrevote{ TargetHash: targetHash, TargetNumber: targetNumber, @@ -83,13 +83,13 @@ type afgReceivedCommitTM AfgReceivedCommit // AfgReceivedCommit holds `afg.received_commit` telemetry message which is // supposed to be sent when grandpa client receives a commit. type AfgReceivedCommit struct { - TargetHash *common.Hash `json:"target_hash"` - TargetNumber string `json:"target_number"` - ContainsPrecommitsSignedBy []string `json:"contains_precommits_signed_by"` + TargetHash common.Hash `json:"target_hash"` + TargetNumber string `json:"target_number"` + ContainsPrecommitsSignedBy []string `json:"contains_precommits_signed_by"` } // NewAfgReceivedCommit gets a new AfgReceivedCommit* struct. -func NewAfgReceivedCommit(targetHash *common.Hash, targetNumber string, +func NewAfgReceivedCommit(targetHash common.Hash, targetNumber string, containsPrecommitsSignedBy []string) *AfgReceivedCommit { return &AfgReceivedCommit{ TargetHash: targetHash, diff --git a/dot/telemetry/mailer_test.go b/dot/telemetry/mailer_test.go index 9c1a47c300..1d808dc693 100644 --- a/dot/telemetry/mailer_test.go +++ b/dot/telemetry/mailer_test.go @@ -97,21 +97,21 @@ func TestHandler_SendMulti(t *testing.T) { NewAfgAuthoritySet("authority_id", "authority_set_id", "json-stringified-ids-of-authorities"), func(hash common.Hash, number string) Message { - return NewAfgFinalizedBlocksUpTo(&hash, number) + return NewAfgFinalizedBlocksUpTo(hash, number) }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), func(targetHash common.Hash, targetNumber string, containsPrecommitsSignedBy []string) Message { - return NewAfgReceivedCommit(&targetHash, targetNumber, containsPrecommitsSignedBy) + return NewAfgReceivedCommit(targetHash, targetNumber, containsPrecommitsSignedBy) }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1", []string{}), func(targetHash common.Hash, targetNumber string, voter string) Message { - return NewAfgReceivedPrecommit(&targetHash, targetNumber, voter) + return NewAfgReceivedPrecommit(targetHash, targetNumber, voter) }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1", ""), func(targetHash common.Hash, targetNumber string, voter string) Message { - return NewAfgReceivedPrevote(&targetHash, targetNumber, voter) + return NewAfgReceivedPrevote(targetHash, targetNumber, voter) }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1", ""), @@ -270,7 +270,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "AfgFinalizedBlocksUpTo_marshal": { message: &AfgFinalizedBlocksUpTo{ - Hash: &common.Hash{}, + Hash: common.Hash{}, Number: "0", }, expected: regexp.MustCompile(`^{"hash":"0x[0]{64}","number":"0",` + @@ -279,7 +279,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "AfgReceivedPrecommit_marshal": { message: &AfgReceivedPrecommit{ - TargetHash: &common.Hash{}, + TargetHash: common.Hash{}, TargetNumber: "0", Voter: "0x0", }, @@ -289,7 +289,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "AfgReceivedPrevoteTM_marshal": { message: &AfgReceivedPrevote{ - TargetHash: &common.Hash{}, + TargetHash: common.Hash{}, TargetNumber: "0", Voter: "0x0", }, @@ -299,7 +299,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "AfgReceivedCommit_marshal": { message: &AfgReceivedCommit{ - TargetHash: &common.Hash{}, + TargetHash: common.Hash{}, TargetNumber: "0", ContainsPrecommitsSignedBy: []string{"0x0", "0x1"}, }, 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()) } From a73a4dd434b4c882134c6003d33cecf7b93866e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20J=C3=BAnior?= Date: Fri, 14 Jan 2022 11:32:29 -0400 Subject: [PATCH 4/6] chore: use right defined type --- lib/grandpa/grandpa.go | 3 +-- lib/grandpa/message_handler.go | 2 +- lib/grandpa/vote_message.go | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index e20b093960..4f80c62323 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -646,9 +646,8 @@ func (s *Service) attemptToFinalize() error { logger.Debugf("sending CommitMessage: %v", cm) s.network.GossipMessage(msg) - hash := s.head.Hash() s.telemetry.SendMessage(telemetry.NewAfgFinalizedBlocksUpTo( - &hash, + s.head.Hash(), s.head.Number.String(), )) diff --git a/lib/grandpa/message_handler.go b/lib/grandpa/message_handler.go index 4d73d5af9e..0f9db8da71 100644 --- a/lib/grandpa/message_handler.go +++ b/lib/grandpa/message_handler.go @@ -112,7 +112,7 @@ func (h *MessageHandler) handleCommitMessage(msg *CommitMessage) error { h.telemetry.SendMessage( telemetry.NewAfgReceivedCommit( - &msg.Vote.Hash, + msg.Vote.Hash, fmt.Sprint(msg.Vote.Number), containsPrecommitsSignedBy, ), diff --git a/lib/grandpa/vote_message.go b/lib/grandpa/vote_message.go index 6f3fd3928c..827d400cf2 100644 --- a/lib/grandpa/vote_message.go +++ b/lib/grandpa/vote_message.go @@ -42,7 +42,7 @@ func (s *Service) receiveVoteMessages(ctx context.Context) { case prevote, primaryProposal: s.telemetry.SendMessage( telemetry.NewAfgReceivedPrevote( - &vm.Message.Hash, + vm.Message.Hash, fmt.Sprint(vm.Message.Number), vm.Message.AuthorityID.String(), ), @@ -50,7 +50,7 @@ func (s *Service) receiveVoteMessages(ctx context.Context) { case precommit: s.telemetry.SendMessage( telemetry.NewAfgReceivedPrecommit( - &vm.Message.Hash, + vm.Message.Hash, fmt.Sprint(vm.Message.Number), vm.Message.AuthorityID.String(), ), From 2b98e9ff34250aaf9702868105b7f0fd6b3002b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20J=C3=BAnior?= Date: Fri, 14 Jan 2022 11:35:36 -0400 Subject: [PATCH 5/6] chore: using strict type --- dot/node_test.go | 3 +-- dot/state/block_finalisation.go | 2 +- dot/state/storage_test.go | 3 +-- dot/telemetry/mailer_test.go | 8 ++++---- dot/telemetry/notify_finalized.go | 4 ++-- dot/telemetry/prepared_block_for_proposing.go | 4 ++-- lib/babe/babe.go | 3 +-- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/dot/node_test.go b/dot/node_test.go index ec1690d85c..a32bd51f33 100644 --- a/dot/node_test.go +++ b/dot/node_test.go @@ -201,9 +201,8 @@ func TestInitNode_LoadGenesisData(t *testing.T) { ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) - bestHash := common.MustHexToHash("0x336743aadf42654d4ef91294b61a167c9ed8a42f7f327d08d1e3c99541047392") expectedArg := &telemetry.NotifyFinalized{ - Best: &bestHash, + Best: common.MustHexToHash("0x336743aadf42654d4ef91294b61a167c9ed8a42f7f327d08d1e3c99541047392"), Height: "0", } diff --git a/dot/state/block_finalisation.go b/dot/state/block_finalisation.go index d117dd16aa..8557bf4721 100644 --- a/dot/state/block_finalisation.go +++ b/dot/state/block_finalisation.go @@ -173,7 +173,7 @@ func (bs *BlockState) SetFinalisedHash(hash common.Hash, round, setID uint64) er bs.telemetry.SendMessage( telemetry.NewNotifyFinalized( - &hash, + header.Hash(), header.Number.String(), ), ) diff --git a/dot/state/storage_test.go b/dot/state/storage_test.go index 8893e7381d..8e61eefd1d 100644 --- a/dot/state/storage_test.go +++ b/dot/state/storage_test.go @@ -196,12 +196,11 @@ func TestGetStorageChildAndGetStorageFromChild(t *testing.T) { require.NoError(t, err) _, genTrie, genHeader := genesis.NewTestGenesisWithTrieAndHeader(t) - genHash := genHeader.Hash() ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) telemetryMock.EXPECT().SendMessage(telemetry.NewNotifyFinalized( - &genHash, + genHeader.Hash(), "0", )) diff --git a/dot/telemetry/mailer_test.go b/dot/telemetry/mailer_test.go index 1d808dc693..adeeb0833c 100644 --- a/dot/telemetry/mailer_test.go +++ b/dot/telemetry/mailer_test.go @@ -116,12 +116,12 @@ func TestHandler_SendMulti(t *testing.T) { "1", ""), func(best common.Hash, height string) Message { - return NewNotifyFinalized(&best, height) + return NewNotifyFinalized(best, height) }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "32375"), func(hash common.Hash, number string) Message { - return NewPreparedBlockForProposing(&hash, number) + return NewPreparedBlockForProposing(hash, number) }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), "1"), } @@ -320,7 +320,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "NotifyFinalized_marshal": { message: &NotifyFinalized{ - Best: &common.Hash{}, + Best: common.Hash{}, Height: "0", }, expected: regexp.MustCompile(`^{"best":"0x[0]{64}","height":"0",` + @@ -329,7 +329,7 @@ func TestTelemetryMarshalMessage(t *testing.T) { }, "PreparedBlockForProposing_marshal": { message: &PreparedBlockForProposing{ - Hash: &common.Hash{}, + Hash: common.Hash{}, Number: "0", }, expected: regexp.MustCompile(`^{"hash":"0x[0]{64}","number":"0",` + diff --git a/dot/telemetry/notify_finalized.go b/dot/telemetry/notify_finalized.go index af05959bd3..72e7258b51 100644 --- a/dot/telemetry/notify_finalized.go +++ b/dot/telemetry/notify_finalized.go @@ -17,13 +17,13 @@ var _ Message = (*NotifyFinalized)(nil) // NotifyFinalized holds `notify.finalized` telemetry message, which is // supposed to be send when a new block gets finalised. type NotifyFinalized struct { - Best *common.Hash `json:"best"` + Best common.Hash `json:"best"` // Height is same as block.Header.Number Height string `json:"height"` } // NewNotifyFinalized gets a new NotifyFinalizedTM struct. -func NewNotifyFinalized(best *common.Hash, height string) *NotifyFinalized { +func NewNotifyFinalized(best common.Hash, height string) *NotifyFinalized { return &NotifyFinalized{ Best: best, Height: height, diff --git a/dot/telemetry/prepared_block_for_proposing.go b/dot/telemetry/prepared_block_for_proposing.go index c6d005c9c1..7d90ffbaa1 100644 --- a/dot/telemetry/prepared_block_for_proposing.go +++ b/dot/telemetry/prepared_block_for_proposing.go @@ -17,13 +17,13 @@ var _ Message = (*PreparedBlockForProposing)(nil) // PreparedBlockForProposing holds a 'prepared_block_for_proposing' telemetry // message, which is supposed to be sent when a new block is built. type PreparedBlockForProposing struct { - Hash *common.Hash `json:"hash"` + Hash common.Hash `json:"hash"` // Height of the chain, Block.Header.Number Number string `json:"number"` } // NewPreparedBlockForProposing gets a new PreparedBlockForProposingTM struct. -func NewPreparedBlockForProposing(hash *common.Hash, number string) *PreparedBlockForProposing { +func NewPreparedBlockForProposing(hash common.Hash, number string) *PreparedBlockForProposing { return &PreparedBlockForProposing{ Hash: hash, Number: number, diff --git a/lib/babe/babe.go b/lib/babe/babe.go index 1ddb71caf1..548bf18e9d 100644 --- a/lib/babe/babe.go +++ b/lib/babe/babe.go @@ -543,10 +543,9 @@ func (b *Service) handleSlot(epoch, slotNum uint64) error { "built block with parent hash %s, header %s and body %s", parent.Hash(), block.Header.String(), block.Body) - blockHash := block.Header.Hash() b.telemetry.SendMessage( telemetry.NewPreparedBlockForProposing( - &blockHash, + block.Header.Hash(), block.Header.Number.String(), ), ) From 9056f43ffd61d410ef259952e5d2e3f767a327b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20J=C3=BAnior?= Date: Mon, 17 Jan 2022 13:12:23 -0400 Subject: [PATCH 6/6] chore: remove complex anon functions at telemetry `SendMulti` test --- dot/telemetry/mailer_test.go | 65 +++++++++--------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/dot/telemetry/mailer_test.go b/dot/telemetry/mailer_test.go index adeeb0833c..3276ec17e8 100644 --- a/dot/telemetry/mailer_test.go +++ b/dot/telemetry/mailer_test.go @@ -58,11 +58,14 @@ 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":"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":`), @@ -76,54 +79,18 @@ func TestHandler_SendMulti(t *testing.T) { 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"), - - func(hash common.Hash, number string) Message { - return NewAfgFinalizedBlocksUpTo(hash, number) - }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), "1"), - - func(targetHash common.Hash, targetNumber string, containsPrecommitsSignedBy []string) Message { - return NewAfgReceivedCommit(targetHash, targetNumber, containsPrecommitsSignedBy) - }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1", []string{}), - - func(targetHash common.Hash, targetNumber string, voter string) Message { - return NewAfgReceivedPrecommit(targetHash, targetNumber, voter) - }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1", ""), - - func(targetHash common.Hash, targetNumber string, voter string) Message { - return NewAfgReceivedPrevote(targetHash, targetNumber, voter) - }(common.MustHexToHash("0x5814aec3e28527f81f65841e034872f3a30337cf6c33b2d258bba6071e37e27c"), - "1", ""), - - func(best common.Hash, height string) Message { - return NewNotifyFinalized(best, height) - }(common.MustHexToHash("0x07b749b6e20fd5f1159153a2e790235018621dd06072a62bcd25e8576f6ff5e6"), - "32375"), - - func(hash common.Hash, number string) Message { - return NewPreparedBlockForProposing(hash, number) - }(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{