hare: use beacon as is in the vrf message
## Motivation
make hare encodes beacon consistently as other vrf messages.
MODIFY
beacon/beacon.go
beacon/beacon.go
@@ -386,7 +386,6 @@ func (pd *ProtocolDriver) GetBeacon(targetEpoch types.EpochID) (types.Beacon, er
}
if errors.Is(err, sql.ErrNotFound) {
- pd.logger.With().Warning("beacon not available", targetEpoch)
return types.EmptyBeacon, errBeaconNotCalculated
}
pd.logger.With().Error("failed to get beacon from db", targetEpoch, log.Err(err))

MODIFY
hare/eligibility/oracle.go
hare/eligibility/oracle.go
@@ -2,7 +2,6 @@ package eligibility
import (
"context"
- "encoding/binary"
"errors"
"fmt"
"math"
@@ -157,38 +156,19 @@ func New(
type VrfMessage struct {
Type types.EligibilityType
Nonce types.VRFPostIndex
- Beacon uint32
+ Beacon types.Beacon
Round uint32
Layer types.LayerID
}
-func encodeBeacon(beacon types.Beacon) uint32 {
- return binary.LittleEndian.Uint32(beacon.Bytes())
-}
-
-func (o *Oracle) getBeaconValue(ctx context.Context, epochID types.EpochID) (uint32, error) {
- beacon, err := o.beacons.GetBeacon(epochID)
- if err != nil {
- return 0, fmt.Errorf("get beacon: %w", err)
- }
-
- value := encodeBeacon(beacon)
- o.WithContext(ctx).With().Info("eligibility: beacon value for epoch",
- epochID,
- beacon,
- log.Uint32("beacon_val", value),
- )
- return value, nil
-}
-
// buildVRFMessage builds the VRF message used as input for the BLS (msg=Beacon##Layer##Round).
func (o *Oracle) buildVRFMessage(ctx context.Context, nonce types.VRFPostIndex, layer types.LayerID, round uint32) ([]byte, error) {
- v, err := o.getBeaconValue(ctx, layer.GetEpoch())
+ beacon, err := o.beacons.GetBeacon(layer.GetEpoch())
if err != nil {
return nil, fmt.Errorf("get beacon: %w", err)
}
- msg := VrfMessage{Type: types.EligibilityHare, Nonce: nonce, Beacon: v, Round: round, Layer: layer}
+ msg := VrfMessage{Type: types.EligibilityHare, Nonce: nonce, Beacon: beacon, Round: round, Layer: layer}
buf, err := codec.Encode(&msg)
if err != nil {
o.WithContext(ctx).With().Fatal("failed to encode", log.Err(err))
@@ -234,7 +214,7 @@ func calcVrfFrac(vrfSig []byte) fixed.Fixed {
func (o *Oracle) prepareEligibilityCheck(ctx context.Context, layer types.LayerID, round uint32, committeeSize int, id types.NodeID, nonce types.VRFPostIndex, vrfSig []byte) (n int, p, vrfFrac fixed.Fixed, done bool, err error) {
logger := o.WithContext(ctx).WithFields(
layer,
- log.FieldNamed("message_node_id", id),
+ log.Stringer("sender_id", id),
log.Uint32("round", round),
log.Int("committee_size", committeeSize),
)
@@ -253,7 +233,6 @@ func (o *Oracle) prepareEligibilityCheck(ctx context.Context, layer types.LayerI
// validate message
if !o.vrfVerifier.Verify(id, msg, vrfSig) {
logger.With().Info("eligibility: a node did not pass vrf signature verification",
- log.FieldNamed("sender_id", id),
log.FieldNamed("sender_vrf_nonce", nonce),
)
return 0, fixed.Fixed{}, fixed.Fixed{}, true, nil

MODIFY
hare/eligibility/oracle_scale.go
hare/eligibility/oracle_scale.go
@@ -24,7 +24,7 @@ func (t *VrfMessage) EncodeScale(enc *scale.Encoder) (total int, err error) {
total += n
}
{
- n, err := scale.EncodeCompact32(enc, uint32(t.Beacon))
+ n, err := scale.EncodeByteArray(enc, t.Beacon[:])
if err != nil {
return total, err
}
@@ -65,12 +65,11 @@ func (t *VrfMessage) DecodeScale(dec *scale.Decoder) (total int, err error) {
t.Nonce = types.VRFPostIndex(field)
}
{
- field, n, err := scale.DecodeCompact32(dec)
+ n, err := scale.DecodeByteArray(dec, t.Beacon[:])
if err != nil {
return total, err
}
total += n
- t.Beacon = uint32(field)
}
{
field, n, err := scale.DecodeCompact32(dec)

MODIFY
hare/eligibility/oracle_test.go
hare/eligibility/oracle_test.go
@@ -869,13 +869,6 @@ func TestMaxSupportedN(t *testing.T) {
})
}
-func TestEncodeBeacon(t *testing.T) {
- beacon := types.HexToBeacon("0xaeebad4a796fcc2e15dc4c6061b45ed9b373f26adfc798ca7d2d8cc58182718e")
- require.Len(t, beacon, 4)
- expected := uint32(0x4aadebae)
- require.Equal(t, expected, encodeBeacon(beacon))
-}
-
func FuzzVrfMessageConsistency(f *testing.F) {
tester.FuzzConsistency[VrfMessage](f)
}

hare: use beacon as is in the vrf message (#4022)

## Motivation
make hare encodes beacon consistently as other vrf messages.