Skip to content

Commit

Permalink
Merge pull request #30 from ethpandaops/feat/add-attestation-bit
Browse files Browse the repository at this point in the history
feat: add attestation bit position
  • Loading branch information
guillaumemichel authored May 28, 2024
2 parents 2c3f62a + c4398d8 commit 90aecd7
Showing 1 changed file with 22 additions and 12 deletions.
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

0 comments on commit 90aecd7

Please sign in to comment.