Skip to content

Commit

Permalink
chore: remove ending dots in logging
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jul 26, 2023
1 parent 845074e commit e6e2017
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 50 deletions.
58 changes: 21 additions & 37 deletions pkg/app_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"main/pkg/tendermint"
"main/pkg/types"
"main/pkg/utils"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -121,48 +120,37 @@ 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).
Msg("Error updating historical validators")
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).
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -410,35 +394,35 @@ 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 {
blockRaw, found := blocks[height]
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
}

validators, found := allValidators[height]
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).
Msg("Error getting older block")
continue
}

block.SetValidators(validators)

a.mutex.Lock()

if err := a.StateManager.AddBlock(block); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporters/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporters/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/tendermint/http_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ func (manager *RPCManager) GetBlocksAndValidatorsAtHeights(heights []int64) (
}

wg.Wait()
return blocksMap, activeSetsMap, nil
return blocksMap, activeSetsMap, errors
}
11 changes: 9 additions & 2 deletions pkg/tendermint/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tendermint/websocket_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 1 addition & 7 deletions pkg/types/responses.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"fmt"
"strconv"
"time"
)
Expand All @@ -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"`
Expand All @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit e6e2017

Please sign in to comment.