Skip to content
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

RoundChange message size logging #286

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions consensus/polybft/consensus_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/0xPolygon/go-ibft/messages/proto"
hcf "github.com/hashicorp/go-hclog"
bolt "go.etcd.io/bbolt"
protobuf "google.golang.org/protobuf/proto"

"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/consensus"
Expand All @@ -23,6 +24,7 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/forkmanager"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/types"
)

Expand Down Expand Up @@ -985,6 +987,8 @@ func (c *consensusRuntime) BuildPrepareMessage(proposalHash []byte, view *proto.
return nil
}

c.logger.Debug("Prepare message built", "blockNumber", view.Height, "round", view.Round)

return message
}

Expand Down Expand Up @@ -1063,6 +1067,8 @@ func (c *consensusRuntime) BuildRoundChangeMessage(
return nil
}

c.logRoundChangeMessage(view, proposal, certificate, &msg, signedMsg)

return signedMsg
}

Expand Down Expand Up @@ -1109,3 +1115,67 @@ func (c *consensusRuntime) getCurrentBlockTimeDrift() uint64 {

return c.epoch.CurrentClientConfig.BlockTimeDrift
}

// logRoundChangeMessage logs the size of the round change message
func (c *consensusRuntime) logRoundChangeMessage(
view *proto.View,
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
msg *proto.Message,
signedMsg *proto.Message) {
if !c.logger.IsDebug() {
return
}

var (
preparedMsgsLen = 0
isPreparedCertNil = certificate == nil

rawCertificate = make([]byte, 0)
rawCertificateProposalMsg = make([]byte, 0)
err error
)

if certificate != nil {
preparedMsgsLen = len(certificate.PrepareMessages)

rawCertificate, err = protobuf.Marshal(certificate)
if err != nil {
c.logger.Error("Cannot marshal prepared certificate", "error", err)
}

if certificate.ProposalMessage != nil {
rawCertificateProposalMsg, err = protobuf.Marshal(certificate.ProposalMessage)
if err != nil {
c.logger.Error("Cannot marshal prepared certificate proposal message", "error", err)
}
}
}

rawProposal := make([]byte, 0)

isProposalNil := proposal == nil
if !isProposalNil {
rawProposal = proposal.RawProposal
}

msgRaw, err := protobuf.Marshal(msg)
if err != nil {
c.logger.Error("Cannot marshal round change message", "error", err)
}

signedMsgRaw, err := protobuf.Marshal(signedMsg)
if err != nil {
c.logger.Error("Cannot marshal signed round change message", "error", err)
}

c.logger.Debug("RoundChange message built", "blockNumber", view.Height, "round", view.Round,
"totalRoundMsgSize", common.ToMB(msgRaw),
"signedRoundMsgSize", common.ToMB(signedMsgRaw),
"isProposalNil", isProposalNil,
"proposalSize", common.ToMB(rawProposal),
"isPreparedCertNil", isPreparedCertNil,
"numOfPrepareMsgs", preparedMsgsLen,
"certificateSize", common.ToMB(rawCertificate),
"certificateProposalSize", common.ToMB(rawCertificateProposalMsg))
}
8 changes: 8 additions & 0 deletions helper/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,11 @@ func GetFreePort() (port int, err error) {

return
}

// ToMB converts a byte slice size to a string representation in MB
func ToMB(data []byte) string {
sizeInBytes := len(data)
sizeInMB := float64(sizeInBytes) / (1024 * 1024)

return fmt.Sprintf("%.2f MB", sizeInMB)
}
3 changes: 2 additions & 1 deletion network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"sync/atomic"

"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/armon/go-metrics"
"github.com/hashicorp/go-hclog"
pubsub "github.com/libp2p/go-libp2p-pubsub"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (t *Topic) readLoop(sub *pubsub.Subscription, handler func(obj interface{},
}

go func() {
t.logger.Debug("gossip message", "size", len(msg.Data))
t.logger.Debug("gossip message", "size", common.ToMB(msg.Data))

obj := t.createObj()
if err := proto.Unmarshal(msg.Data, obj); err != nil {
Expand Down
Loading