Skip to content

Commit

Permalink
external bv error log err->debug
Browse files Browse the repository at this point in the history
  • Loading branch information
GrePod committed Dec 16, 2024
1 parent 23d9939 commit 78b38a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/attestation/bitVotes/bitvote.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
)

type BitVote struct {
Length uint16 //number of attestations
Length uint16 // number of attestations
BitVector *big.Int
}

Expand Down
18 changes: 11 additions & 7 deletions client/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func (m *Manager) Run(ctx context.Context) {

case bitVotesForRound := <-m.bitVotes:
for i := range bitVotesForRound.Messages {
err := m.OnBitVote(bitVotesForRound.Messages[i])
bitVoteErr, err := m.OnBitVote(bitVotesForRound.Messages[i])

if bitVoteErr != nil {
logger.Debug("bad bitVote: %s", bitVoteErr)
}
if err != nil {
logger.Errorf("bit vote error: %s", err)
}
Expand Down Expand Up @@ -157,26 +161,26 @@ func (m *Manager) GetOrCreateRound(roundID uint32) (*round.Round, error) {
}

// OnBitVote processes payload message that is assumed to be a bitVote and adds it to the correct round.
func (m *Manager) OnBitVote(message payload.Message) error {
func (m *Manager) OnBitVote(message payload.Message) (error, error) {
if message.Timestamp < timing.ChooseStartTimestamp(message.VotingRound) {
return fmt.Errorf("bitVote from %s for voting round %d too soon", message.From, message.VotingRound)
return fmt.Errorf("bitVote from %s for voting round %d too soon", message.From, message.VotingRound), nil
}

if message.Timestamp >= timing.ChooseEndTimestamp(message.VotingRound) {
return fmt.Errorf("bitVote from %s for voting round %d too late", message.From, message.VotingRound)
return fmt.Errorf("bitVote from %s for voting round %d too late", message.From, message.VotingRound), nil
}

round, err := m.GetOrCreateRound(message.VotingRound)
if err != nil {
return err
return nil, err
}

err = round.ProcessBitVote(message)
if err != nil {
return fmt.Errorf("error processing bitVote from %s for voting round %d: %s", message.From, message.VotingRound, err)
return fmt.Errorf("error processing bitVote from %s for voting round %d: %s", message.From, message.VotingRound, err), nil
}

return nil
return nil, nil
}

// OnRequest processes the attestation request.
Expand Down
9 changes: 6 additions & 3 deletions client/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ func TestManagerMethods(t *testing.T) {
bitVoteMessageBadVoter,
bitVoteMessageWrongLength,
} {
err = mngr.OnBitVote(badBitVote)
require.Error(t, err, fmt.Sprintf("error in bad bitVote %d", i))
bverr, err := mngr.OnBitVote(badBitVote)
require.Error(t, bverr, fmt.Sprintf("error in bad bitVote %d", i))
require.NoError(t, err)

}
bitVoteMessageCorrect := bitVoteMessage
bitVoteMessageCorrect.Payload = []byte{0, 0}
err = mngr.OnBitVote(bitVoteMessageCorrect)
bverr, err := mngr.OnBitVote(bitVoteMessageCorrect)
require.NoError(t, bverr)
require.NoError(t, err)

_, ok := mngr.Rounds.Get(664111)
Expand Down

0 comments on commit 78b38a4

Please sign in to comment.