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

feat: add attestation bit position #30

Merged
merged 5 commits into from
May 28, 2024
Merged
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
34 changes: 22 additions & 12 deletions eth/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,33 @@ func (p *PubSub) handleAttestation(ctx context.Context, msg *pubsub.Message) err
return fmt.Errorf("decode attestation gossip message: %w", err)
}

payload := map[string]any{
"PeerID": msg.ReceivedFrom.String(),
"MsgID": hex.EncodeToString([]byte(msg.ID)),
"MsgSize": len(msg.Data),
"Topic": msg.GetTopic(),
"Seq": msg.GetSeqno(),
"CommIdx": attestation.GetData().GetCommitteeIndex(),
"Slot": attestation.GetData().GetSlot(),
"BeaconBlockRoot": attestation.GetData().GetBeaconBlockRoot(),
"Source": attestation.GetData().GetSource(),
"Target": attestation.GetData().GetTarget(),
}

// If the attestation only has one aggregation bit set, we can add an additional field to the payload
// that denotes _which_ aggregation bit is set. This is required to determine which validator created the attestation.
// In the pursuit of reducing the amount of data stored in the data stream we omit this field if the attestation is
// aggregated.
if attestation.GetAggregationBits().Count() == 1 {
payload["AggregatePos"] = attestation.AggregationBits.BitIndices()[0]
}

now := time.Now()
evt := &host.TraceEvent{
Type: eventTypeHandleMessage,
PeerID: p.host.ID(),
Timestamp: now,
Payload: map[string]any{
"PeerID": msg.ReceivedFrom.String(),
"MsgID": hex.EncodeToString([]byte(msg.ID)),
"MsgSize": len(msg.Data),
"Topic": msg.GetTopic(),
"Seq": msg.GetSeqno(),
"CommIdx": attestation.GetData().GetCommitteeIndex(),
"Slot": attestation.GetData().GetSlot(),
"BeaconBlockRoot": attestation.GetData().GetBeaconBlockRoot(),
"Source": attestation.GetData().GetSource(),
"Target": attestation.GetData().GetTarget(),
},
Payload: payload,
}

if err := p.cfg.DataStream.PutRecord(ctx, evt); err != nil {
Expand Down
Loading