Skip to content

Commit

Permalink
WIP: Tweak tortoise vote calculation for testnet (#2337)
Browse files Browse the repository at this point in the history
Make linter happy

Count abstain on zero pattern as explicit support

Whitespace

Revert "Calculate net not absolute tortoise support"

This reverts commit 2a33fd1.

Bugfix in sendMessage

Bugfix

Bugfix

Fix test
  • Loading branch information
lrettig committed Mar 31, 2021
1 parent e45462d commit 8acf005
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
12 changes: 6 additions & 6 deletions hare/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ func (proc *consensusProcess) processMsg(ctx context.Context, m *Msg) {
// sends a message to the network.
// Returns true if the message is assumed to be sent, false otherwise.
func (proc *consensusProcess) sendMessage(ctx context.Context, msg *Msg) bool {
// invalid msg
if msg == nil {
proc.WithContext(ctx).Error("sendMessage was called with nil")
return false
}

// generate a new requestID for this message
ctx = log.WithNewRequestID(ctx,
log.String("current_set", proc.s.String()),
Expand All @@ -492,12 +498,6 @@ func (proc *consensusProcess) sendMessage(ctx context.Context, msg *Msg) bool {
types.LayerID(proc.instanceID))
logger := proc.WithContext(ctx)

// invalid msg
if msg == nil {
logger.Error("sendMessage was called with nil")
return false
}

if err := proc.network.Broadcast(ctx, protoName, msg.Bytes()); err != nil {
logger.With().Error("could not broadcast round message", log.Err(err))
return false
Expand Down
2 changes: 1 addition & 1 deletion p2p/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ func TestSwarm_SendMessage(t *testing.T) {
}

err = p.SendMessage(context.TODO(), someky, proto, []byte("LOL"))
require.Equal(t, err, errors.New("this peer isn't a neighbor or connection lost"))
require.Contains(t, err.Error(), "peer not a neighbor or connection lost")

cp.fExists = func(pk p2pcrypto.PublicKey) (connection net.Connection, err error) {
return net.NewConnectionMock(pk), nil
Expand Down
2 changes: 1 addition & 1 deletion sync/fetch_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func newAtxQueue(ctx context.Context, s *Syncer, fetchPoetProof fetchPoetProofFu

//we could get rid of this if we had a unified id type
func (atx atxQueue) HandleAtxs(ctx context.Context, atxids []types.ATXID) ([]*types.ActivationTx, error) {
atxFields := make([]log.LoggableField, len(atxids))
atxFields := make([]log.LoggableField, 0, len(atxids))
atxItems := make([]types.Hash32, 0, len(atxids))
for _, atxid := range atxids {
atxFields = append(atxFields, atxid.Field())
Expand Down
4 changes: 2 additions & 2 deletions sync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ func (s *Syncer) syncEpochActivations(ctx context.Context, epoch types.EpochID)
}

atxFields := make([]log.LoggableField, len(atxIds))
for _, atxid := range atxIds {
atxFields = append(atxFields, atxid.Field())
for i := range atxIds {
atxFields[i] = atxIds[i]
}
logger.With().Info("fetched atxs for epoch", log.Int("count", len(atxIds)))
logger.With().Debug("fetched atxs for epoch", atxFields...)
Expand Down
27 changes: 21 additions & 6 deletions tortoise/ninja_tortoise.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,31 @@ func (ni *ninjaTortoise) handleIncomingLayer(newlyr *types.Layer) {
ni.TVote[p] = make(map[blockIDLayerTuple]vec)
}

ni.logger.With().Debug("block voting based on global opinion of pattern",
p,
blt)
if vote := ni.globalOpinion(ni.TTally[p][blt], ni.AvgLayerSize, float64(p.LayerID-idx)); vote != abstain {
ni.TVote[p][blt] = vote
ni.logger.With().Debug("block voting based on global opinion of pattern", p, blt)
vote := ni.globalOpinion(ni.TTally[p][blt], ni.AvgLayerSize, float64(p.LayerID-idx))
ni.TVote[p][blt] = vote

if vote != abstain {
// Count explicit (non-abstain) votes
ni.logger.With().Debug("counting explicit vote",
p,
bid,
idx,
vote)
if vote == support {
bids = append(bids, bid)
}
} else if p == zeroPattern && vote == abstain {
// In the special case of the zero pattern, we consider an abstain an explicit vote in favor
ni.logger.With().Debug("counting abstain on zero pattern as explicit support vote",
p,
bid,
idx,
vote)
bids = append(bids, bid)
} else {
ni.TVote[p][blt] = vote
// In all cases other than the zero pattern, abstain does not count and causes the layer not
// to advance
ni.logger.With().Debug(
"block support below threshold, block abstains from vote on pattern, "+
"pattern is incomplete and will not be promoted",
Expand Down

0 comments on commit 8acf005

Please sign in to comment.