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

Additional logs and cleanup. #4656

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion consensus/consensus_msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (sender *MessageSender) Retry(msgRetry *MessageRetry) {

msgRetry.retryCount++
if err := sender.host.SendMessageToGroups(msgRetry.groups, msgRetry.p2pMsg); err != nil {
utils.Logger().Warn().Str("groupID[0]", msgRetry.groups[0].String()).Uint64("blockNum", msgRetry.blockNum).Str("MsgType", msgRetry.msgType.String()).Int("RetryCount", msgRetry.retryCount).Msg("[Retry] Failed re-sending consensus message")
utils.Logger().Warn().Str("groupID[0]", msgRetry.groups[0].String()).Uint64("blockNum", msgRetry.blockNum).Str("MsgType", msgRetry.msgType.String()).Int("RetryCount", msgRetry.retryCount).Err(err).Msg("[Retry] Failed re-sending consensus message")
} else {
utils.Logger().Info().Str("groupID[0]", msgRetry.groups[0].String()).Uint64("blockNum", msgRetry.blockNum).Str("MsgType", msgRetry.msgType.String()).Int("RetryCount", msgRetry.retryCount).Msg("[Retry] Successfully resent consensus message")
}
Expand Down
5 changes: 3 additions & 2 deletions consensus/consensus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (consensus *Consensus) updateConsensusInformation() Mode {
} else {
consensus.getLogger().Info().
Str("leaderPubKey", leaderPubKey.Bytes.Hex()).
Msg("[UpdateConsensusInformation] Most Recent LeaderPubKey Updated Based on BlockChain")
Msgf("[UpdateConsensusInformation] Most Recent LeaderPubKey Updated Based on BlockChain, blocknum: %d", curHeader.NumberU64())
consensus.LeaderPubKey = leaderPubKey
}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func (consensus *Consensus) updateConsensusInformation() Mode {
}
}
consensus.getLogger().Info().
Msg("[UpdateConsensusInformation] not in committee, Listening")
Msgf("[UpdateConsensusInformation] not in committee, keys len %d Listening", len(pubKeys))

// not in committee
return Listening
Expand Down Expand Up @@ -652,6 +652,7 @@ func (consensus *Consensus) GetLogger() *zerolog.Logger {
// getLogger returns logger for consensus contexts added
func (consensus *Consensus) getLogger() *zerolog.Logger {
logger := utils.Logger().With().
Uint32("shardID", consensus.ShardID).
Uint64("myBlock", consensus.blockNum).
Uint64("myViewID", consensus.getCurBlockViewID()).
Str("phase", consensus.phase.String()).
Expand Down
4 changes: 2 additions & 2 deletions consensus/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func (consensus *Consensus) announce(block *types.Block) {
Str("groupID", string(nodeconfig.NewGroupIDByShardID(
nodeconfig.ShardID(consensus.ShardID),
))).
Msg("[Announce] Cannot send announce message")
Msgf("[Announce] Cannot send announce message with message signer %s", key.Pub.Hex())
} else {
consensus.getLogger().Info().
Str("blockHash", block.Hash().Hex()).
Uint64("blockNum", block.NumberU64()).
Msg("[Announce] Sent Announce Message!!")
Msgf("[Announce] Sent Announce Message with message signer %s", key.Pub.Hex())
}

consensus.switchPhase("Announce", FBFTPrepare)
Expand Down
19 changes: 15 additions & 4 deletions consensus/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ func (consensus *Consensus) prepare() {
return
}

priKeys := consensus.getPriKeysInCommittee()
priKeys, err := consensus.getPriKeysInCommittee()
if err != nil {
consensus.getLogger().Warn().Err(err).Msg("[OnAnnounce] Cannot get priKey in committee")
return
}

p2pMsgs := consensus.constructP2pMessages(msg_pb.MessageType_PREPARE, nil, priKeys)

Expand All @@ -156,7 +160,11 @@ func (consensus *Consensus) sendCommitMessages(blockObj *types.Block) {
return
}

priKeys := consensus.getPriKeysInCommittee()
priKeys, err := consensus.getPriKeysInCommittee()
if err != nil {
consensus.getLogger().Warn().Err(err).Msg("[sendCommitMessages] Cannot get priKey in committee")
return
}

// Sign commit signature on the received block and construct the p2p messages
commitPayload := signature.ConstructCommitPayload(consensus.Blockchain().Config(),
Expand Down Expand Up @@ -392,15 +400,18 @@ func (consensus *Consensus) onCommitted(recvMsg *FBFTMessage) {

// Collect private keys that are part of the current committee.
// TODO: cache valid private keys and only update when keys change.
func (consensus *Consensus) getPriKeysInCommittee() []*bls.PrivateKeyWrapper {
func (consensus *Consensus) getPriKeysInCommittee() ([]*bls.PrivateKeyWrapper, error) {
if len(consensus.priKey) == 0 {
return nil, errors.New("no private keys in the committee")
}
priKeys := []*bls.PrivateKeyWrapper{}
for i, key := range consensus.priKey {
if !consensus.isValidatorInCommittee(key.Pub.Bytes) {
continue
}
priKeys = append(priKeys, &consensus.priKey[i])
}
return priKeys
return priKeys, nil
}

func (consensus *Consensus) constructP2pMessages(msgType msg_pb.MessageType, payloadForSign []byte, priKeys []*bls.PrivateKeyWrapper) []*NetworkMessage {
Expand Down
26 changes: 11 additions & 15 deletions consensus/votepower/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,16 @@ func (v AccommodateHarmonyVote) String() string {
return string(s)
}

type topLevelRegistry struct {
OurVotingPowerTotalPercentage numeric.Dec
TheirVotingPowerTotalPercentage numeric.Dec
TotalEffectiveStake numeric.Dec
HMYSlotCount int64
}

// Roster ..
type Roster struct {
Voters map[bls.SerializedPublicKey]*AccommodateHarmonyVote
topLevelRegistry
Voters map[bls.SerializedPublicKey]*AccommodateHarmonyVote
ShardID uint32
OrderedSlots []bls.SerializedPublicKey

OurVotingPowerTotalPercentage numeric.Dec
TheirVotingPowerTotalPercentage numeric.Dec
TotalEffectiveStake numeric.Dec
HMYSlotCount int64
}

func (r Roster) String() string {
Expand Down Expand Up @@ -244,13 +241,12 @@ func Compute(subComm *shard.Committee, epoch *big.Int) (*Roster, error) {
func NewRoster(shardID uint32) *Roster {
m := map[bls.SerializedPublicKey]*AccommodateHarmonyVote{}
return &Roster{
Voters: m,
topLevelRegistry: topLevelRegistry{
OurVotingPowerTotalPercentage: numeric.ZeroDec(),
TheirVotingPowerTotalPercentage: numeric.ZeroDec(),
TotalEffectiveStake: numeric.ZeroDec(),
},
Voters: m,
ShardID: shardID,

OurVotingPowerTotalPercentage: numeric.ZeroDec(),
TheirVotingPowerTotalPercentage: numeric.ZeroDec(),
TotalEffectiveStake: numeric.ZeroDec(),
}
}

Expand Down
5 changes: 5 additions & 0 deletions crypto/bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type PublicKeyWrapper struct {
Object *bls.PublicKey
}

// Hex returns the hex string of the public key
func (pk *PublicKeyWrapper) Hex() string {
return pk.Bytes.Hex()
}

// WrapperFromPrivateKey makes a PrivateKeyWrapper from bls secret key
func WrapperFromPrivateKey(pri *bls.SecretKey) PrivateKeyWrapper {
pub := pri.GetPublicKey()
Expand Down
3 changes: 1 addition & 2 deletions internal/chain/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB
subComm := shard.Committee{ShardID: shard.BeaconChainShardID, Slots: members}

if err := availability.IncrementValidatorSigningCounts(
beaconChain,
subComm.StakedValidators(),
state,
payable,
Expand Down Expand Up @@ -599,7 +598,7 @@ func processOneCrossLink(bc engine.ChainReader, state *state.DB, cxLink types.Cr
staked := subComm.StakedValidators()
startTimeLocal = time.Now()
if err := availability.IncrementValidatorSigningCounts(
bc, staked, state, payableSigners, missing,
staked, state, payableSigners, missing,
); err != nil {
return nil, nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions staking/availability/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ type signerKind struct {
}

func bumpCount(
bc Reader,
state ValidatorState,
signers []signerKind,
stakedAddrSet map[common.Address]struct{},
Expand Down Expand Up @@ -129,13 +128,12 @@ func bumpCount(

// IncrementValidatorSigningCounts ..
func IncrementValidatorSigningCounts(
bc Reader,
staked *shard.StakedSlots,
state ValidatorState,
signers, missing shard.SlotList,
) error {
return bumpCount(
bc, state, []signerKind{{false, missing}, {true, signers}},
state, []signerKind{{false, missing}, {true, signers}},
staked.LookupSet,
)
}
Expand Down
2 changes: 1 addition & 1 deletion staking/availability/measure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestIncrementValidatorSigningCounts(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := IncrementValidatorSigningCounts(nil, ctx.staked, ctx.state, ctx.signers,
if err := IncrementValidatorSigningCounts(ctx.staked, ctx.state, ctx.signers,
ctx.missings); err != nil {

t.Fatal(err)
Expand Down