From e6e20177380f3d6c7593908e9390f1f34e11ad12 Mon Sep 17 00:00:00 2001 From: Techno Freak Date: Wed, 26 Jul 2023 14:05:34 +0300 Subject: [PATCH] chore: remove ending dots in logging --- pkg/app_manager.go | 58 +++++++++++------------------ pkg/reporters/discord/discord.go | 2 +- pkg/reporters/telegram/telegram.go | 2 +- pkg/tendermint/http_manager.go | 2 +- pkg/tendermint/websocket.go | 11 +++++- pkg/tendermint/websocket_manager.go | 2 +- pkg/types/block.go | 4 ++ pkg/types/responses.go | 8 +--- 8 files changed, 39 insertions(+), 50 deletions(-) diff --git a/pkg/app_manager.go b/pkg/app_manager.go index 1f100b0..fb392b8 100644 --- a/pkg/app_manager.go +++ b/pkg/app_manager.go @@ -16,7 +16,6 @@ import ( "main/pkg/tendermint" "main/pkg/types" "main/pkg/utils" - "strconv" "sync" "time" @@ -121,33 +120,27 @@ func (a *AppManager) ProcessEvent(emittable types.WebsocketEmittable) { a.mutex.Lock() defer a.mutex.Unlock() - blockRaw, ok := emittable.(types.TendermintBlock) + block, ok := emittable.(*types.Block) if !ok { a.Logger.Warn().Msg("Event is not a block!") return } - height, err := strconv.ParseInt(blockRaw.Header.Height, 10, 64) - if err != nil { - a.Logger.Warn().Msg("Error converting block height!") - return - } - - if a.StateManager.HasBlockAtHeight(height) { + if a.StateManager.HasBlockAtHeight(block.Height) { a.Logger.Info(). - Int64("height", height). - Msg("Already have block at this height, not generating report.") + Int64("height", block.Height). + Msg("Already have block at this height, not generating report") return } - if err := a.UpdateValidators(height - 1); err != nil { + if err := a.UpdateValidators(block.Height - 1); err != nil { a.Logger.Error(). Err(err). Msg("Error updating validators") return } - validators, err := a.RPCManager.GetActiveSetAtBlock(height) + validators, err := a.RPCManager.GetActiveSetAtBlock(block.Height) if err != nil { a.Logger.Error(). Err(err). @@ -155,14 +148,9 @@ func (a *AppManager) ProcessEvent(emittable types.WebsocketEmittable) { return } - block, err := blockRaw.ToBlock(validators) - if err != nil { - a.Logger.Error(). - Err(err). - Msg("Error converting block") - } + block.SetValidators(validators) - a.Logger.Debug().Int64("height", height).Msg("Got new block from Tendermint") + a.Logger.Debug().Int64("height", block.Height).Msg("Got new block from Tendermint") if err := a.StateManager.AddBlock(block); err != nil { a.Logger.Error(). Err(err). @@ -183,7 +171,7 @@ func (a *AppManager) ProcessEvent(emittable types.WebsocketEmittable) { a.Logger.Info(). Int64("blocks_count", blocksCount). Int64("expected", a.Config.BlocksWindow). - Msg("Not enough data for producing a snapshot, skipping.") + Msg("Not enough data for producing a snapshot, skipping") return } @@ -232,7 +220,7 @@ func (a *AppManager) ProcessEvent(emittable types.WebsocketEmittable) { } if report.Empty() { - a.Logger.Info().Msg("Report is empty, no events to send.") + a.Logger.Info().Msg("Report is empty, no events to send") return } @@ -344,30 +332,26 @@ func (a *AppManager) PopulateLatestBlock() { return } - height, err := strconv.ParseInt(blockRaw.Result.Block.Header.Height, 10, 64) + block, err := blockRaw.Result.Block.ToBlock() if err != nil { - a.Logger.Warn().Msg("Error converting block height!") + a.Logger.Warn().Msg("Error parsing block") return } - validators, err := a.RPCManager.GetActiveSetAtBlock(height) + validators, err := a.RPCManager.GetActiveSetAtBlock(block.Height) if err != nil { a.Logger.Error(). Err(err). Msg("Error updating historical validators") } - blockParsed, err := blockRaw.Result.Block.ToBlock(validators) - if err != nil { - a.Logger.Error().Err(err).Msg("Error fetching last block") - return - } + block.SetValidators(validators) a.Logger.Info(). - Int64("height", blockParsed.Height). + Int64("height", block.Height). Msg("Last block height") - if err := a.StateManager.AddBlock(blockParsed); err != nil { + if err := a.StateManager.AddBlock(block); err != nil { a.Logger.Error(). Err(err). Msg("Error inserting last block") @@ -410,8 +394,6 @@ func (a *AppManager) PopulateBlocks() { if len(errs) > 0 { a.Logger.Error().Errs("errors", errs).Msg("Error querying for blocks") - a.IsPopulatingBlocks = false - return } for _, height := range chunk { @@ -419,7 +401,7 @@ func (a *AppManager) PopulateBlocks() { if !found { a.Logger.Error(). Int64("height", height). - Msg("Could not find block at height, which should never happen.") + Msg("Could not find block at height") continue } @@ -427,11 +409,11 @@ func (a *AppManager) PopulateBlocks() { if !found { a.Logger.Error(). Int64("height", height). - Msg("Could not find historical validators at height, which should never happen.") + Msg("Could not find historical validators at height") continue } - block, err := blockRaw.Result.Block.ToBlock(validators) + block, err := blockRaw.Result.Block.ToBlock() if err != nil { a.Logger.Error(). Err(err). @@ -439,6 +421,8 @@ func (a *AppManager) PopulateBlocks() { continue } + block.SetValidators(validators) + a.mutex.Lock() if err := a.StateManager.AddBlock(block); err != nil { diff --git a/pkg/reporters/discord/discord.go b/pkg/reporters/discord/discord.go index f8da0be..7640e31 100644 --- a/pkg/reporters/discord/discord.go +++ b/pkg/reporters/discord/discord.go @@ -53,7 +53,7 @@ func NewReporter( func (reporter *Reporter) Init() { if !reporter.Enabled() { - reporter.Logger.Debug().Msg("Discord credentials not set, not creating Discord reporter.") + reporter.Logger.Debug().Msg("Discord credentials not set, not creating Discord reporter") return } session, err := discordgo.New("Bot " + reporter.Token) diff --git a/pkg/reporters/telegram/telegram.go b/pkg/reporters/telegram/telegram.go index 4018a7c..e84f7c2 100644 --- a/pkg/reporters/telegram/telegram.go +++ b/pkg/reporters/telegram/telegram.go @@ -60,7 +60,7 @@ func NewReporter( func (reporter *Reporter) Init() { if reporter.Token == "" || reporter.Chat == 0 { - reporter.Logger.Debug().Msg("Telegram credentials not set, not creating Telegram reporter.") + reporter.Logger.Debug().Msg("Telegram credentials not set, not creating Telegram reporter") return } diff --git a/pkg/tendermint/http_manager.go b/pkg/tendermint/http_manager.go index 16625d9..1099398 100644 --- a/pkg/tendermint/http_manager.go +++ b/pkg/tendermint/http_manager.go @@ -99,5 +99,5 @@ func (manager *RPCManager) GetBlocksAndValidatorsAtHeights(heights []int64) ( } wg.Wait() - return blocksMap, activeSetsMap, nil + return blocksMap, activeSetsMap, errors } diff --git a/pkg/tendermint/websocket.go b/pkg/tendermint/websocket.go index 1b5fe74..f3acb0a 100644 --- a/pkg/tendermint/websocket.go +++ b/pkg/tendermint/websocket.go @@ -196,7 +196,7 @@ func (t *WebsocketClient) ProcessEvent(event rpcTypes.RPCResponse) { } if resultEvent.Query == "" { - t.logger.Debug().Msg("Event is empty, skipping.") + t.logger.Debug().Msg("Event is empty, skipping") return } @@ -214,9 +214,16 @@ func (t *WebsocketClient) ProcessEvent(event rpcTypes.RPCResponse) { var blockData types.SingleBlockResult if err := json.Unmarshal(blockDataStr, &blockData); err != nil { t.logger.Error().Err(err).Msg("Failed to unmarshall event") + return + } + + block, err := blockData.Block.ToBlock() + if err != nil { + t.logger.Error().Err(err).Msg("Failed to parse block") + return } - t.Channel <- blockData.Block + t.Channel <- block } func (t *WebsocketClient) SubscribeToUpdates() { diff --git a/pkg/tendermint/websocket_manager.go b/pkg/tendermint/websocket_manager.go index a41f57f..c1dc53a 100644 --- a/pkg/tendermint/websocket_manager.go +++ b/pkg/tendermint/websocket_manager.go @@ -84,7 +84,7 @@ func (m *WebsocketManager) Listen() { if m.queue.Has(msg) { m.logger.Trace(). Str("hash", msg.Hash()). - Msg("Message already received, not sending again.") + Msg("Message already received, not sending again") m.mutex.Unlock() continue } diff --git a/pkg/types/block.go b/pkg/types/block.go index 5ba16c2..40b48d2 100644 --- a/pkg/types/block.go +++ b/pkg/types/block.go @@ -16,3 +16,7 @@ type Block struct { func (b *Block) Hash() string { return fmt.Sprintf("block_%d", b.Height) } + +func (b *Block) SetValidators(validators map[string]bool) { + b.Validators = validators +} diff --git a/pkg/types/responses.go b/pkg/types/responses.go index c102632..dd20287 100644 --- a/pkg/types/responses.go +++ b/pkg/types/responses.go @@ -1,7 +1,6 @@ package types import ( - "fmt" "strconv" "time" ) @@ -24,10 +23,6 @@ type TendermintBlock struct { LastCommit BlockLastCommit `json:"last_commit"` } -func (b TendermintBlock) Hash() string { - return fmt.Sprintf("block_%s", b.Header.Height) -} - type BlockHeader struct { Height string `json:"height"` Time time.Time `json:"time"` @@ -43,7 +38,7 @@ type BlockSignature struct { ValidatorAddress string `json:"validator_address"` } -func (b *TendermintBlock) ToBlock(validators map[string]bool) (*Block, error) { +func (b *TendermintBlock) ToBlock() (*Block, error) { height, err := strconv.ParseInt(b.Header.Height, 10, 64) if err != nil { return nil, err @@ -60,7 +55,6 @@ func (b *TendermintBlock) ToBlock(validators map[string]bool) (*Block, error) { Time: b.Header.Time, Proposer: b.Header.Proposer, Signatures: signatures, - Validators: validators, }, nil }