forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
traced_consensus.go
55 lines (42 loc) · 1.31 KB
/
traced_consensus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avalanche
import (
"context"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/trace"
"github.com/MetalBlockchain/metalgo/utils/bag"
"github.com/MetalBlockchain/metalgo/utils/set"
)
var _ Consensus = (*tracedConsensus)(nil)
type tracedConsensus struct {
Consensus
tracer trace.Tracer
}
func Trace(consensus Consensus, tracer trace.Tracer) Consensus {
return &tracedConsensus{
Consensus: consensus,
tracer: tracer,
}
}
func (c *tracedConsensus) Add(ctx context.Context, vtx Vertex) error {
ctx, span := c.tracer.Start(ctx, "tracedConsensus.Add", oteltrace.WithAttributes(
attribute.Stringer("vtxID", vtx.ID()),
))
defer span.End()
return c.Consensus.Add(ctx, vtx)
}
func (c *tracedConsensus) RecordPoll(ctx context.Context, votes bag.UniqueBag[ids.ID]) error {
var allVotes set.Bits64
for _, vote := range votes {
allVotes.Union(vote)
}
ctx, span := c.tracer.Start(ctx, "tracedConsensus.RecordPoll", oteltrace.WithAttributes(
attribute.Int("numVotes", allVotes.Len()),
attribute.Int("numVtxIDs", len(votes)),
))
defer span.End()
return c.Consensus.RecordPoll(ctx, votes)
}