Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into node-split-merge-d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
poszu committed Feb 4, 2025
2 parents e2eec61 + 19bd73d commit bb6c39f
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 207 deletions.
2 changes: 1 addition & 1 deletion blocks/certifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (c *Certifier) certifySingleSigner(
bid types.BlockID,
beacon types.Beacon,
) error {
proof := eligibility.GenVRF(context.Background(), s.VRFSigner(), beacon, lid, eligibility.CertifyRound)
proof := eligibility.GenVRF(s.VRFSigner(), beacon, lid, eligibility.CertifyRound)
eligibilityCount, err := c.oracle.CalcEligibility(
ctx,
lid,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/spacemeshos/post v0.12.11
github.com/spf13/afero v1.12.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,9 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
Expand Down
2 changes: 0 additions & 2 deletions hare3/eligibility/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/signing"
)

//go:generate mockgen -typed -package=eligibility -destination=./mocks.go -source=./interface.go
Expand All @@ -22,7 +21,6 @@ type vrfVerifier interface {
type Rolacle interface {
Validate(context.Context, types.LayerID, uint32, int, types.NodeID, types.VrfSignature, uint16) (bool, error)
CalcEligibility(context.Context, types.LayerID, uint32, int, types.NodeID, types.VrfSignature) (uint16, error)
Proof(context.Context, *signing.VRFSigner, types.LayerID, uint32) (types.VrfSignature, error)
}

type BeaconProvider interface {
Expand Down
40 changes: 0 additions & 40 deletions hare3/eligibility/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions hare3/eligibility/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,23 +396,8 @@ func (o *Oracle) CalcEligibility(
return uint16(n), nil
}

// Proof returns the role proof for the current Layer & Round.
func (o *Oracle) Proof(
ctx context.Context,
signer *signing.VRFSigner,
layer types.LayerID,
round uint32,
) (types.VrfSignature, error) {
beacon, err := o.beacons.Beacon(ctx, layer.GetEpoch())
if err != nil {
return types.EmptyVrfSignature, fmt.Errorf("get beacon: %w", err)
}
return GenVRF(ctx, signer, beacon, layer, round), nil
}

// GenVRF generates vrf for hare eligibility.
func GenVRF(
ctx context.Context,
signer *signing.VRFSigner,
beacon types.Beacon,
layer types.LayerID,
Expand Down Expand Up @@ -553,25 +538,6 @@ func (o *Oracle) activeSetFromRefBallots(ctx context.Context, epoch types.EpochI
return maps.Keys(activeMap), nil
}

// IsIdentityActiveOnConsensusView returns true if the provided identity is active on the consensus view derived
// from the specified layer, false otherwise.
func (o *Oracle) IsIdentityActiveOnConsensusView(
ctx context.Context,
edID types.NodeID,
layer types.LayerID,
) (bool, error) {
o.log.Debug("hare oracle checking for active identity", log.ZContext(ctx))
defer func() {
o.log.Debug("hare oracle active identity check complete", log.ZContext(ctx))
}()
actives, err := o.actives(ctx, layer)
if err != nil {
return false, err
}
_, exist := actives.set[edID]
return exist, nil
}

func (o *Oracle) UpdateActiveSet(epoch types.EpochID, activeSet []types.ATXID) {
o.log.Debug("received activeset update",
zap.Uint32("epoch", epoch.Uint32()),
Expand Down
46 changes: 1 addition & 45 deletions hare3/eligibility/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ func Test_VrfSignVerify(t *testing.T) {
// round is handpicked for vrf signature to pass
const round = 0

proof, err := o.Proof(context.Background(), signer.VRFSigner(), lid, round)
require.NoError(t, err)
proof := GenVRF(signer.VRFSigner(), types.Beacon{1, 0, 0, 0}, lid, round)

res, err := o.CalcEligibility(context.Background(), lid, round, 10, nid, proof)
require.NoError(t, err)
Expand All @@ -421,49 +420,6 @@ func Test_VrfSignVerify(t *testing.T) {
require.True(t, valid)
}

func Test_Proof_BeaconError(t *testing.T) {
o := defaultOracle(t)

signer, err := signing.NewEdSigner()
require.NoError(t, err)

layer := types.LayerID(2)
errUnknown := errors.New("unknown")
o.mBeacon.EXPECT().Beacon(gomock.Any(), layer.GetEpoch()).Return(types.EmptyBeacon, errUnknown).Times(1)

_, err = o.Proof(context.Background(), signer.VRFSigner(), layer, 3)
require.ErrorIs(t, err, errUnknown)
}

func Test_Proof(t *testing.T) {
o := defaultOracle(t)
layer := types.LayerID(2)
o.mBeacon.EXPECT().Beacon(gomock.Any(), layer.GetEpoch()).Return(types.Beacon{1, 0, 0, 0}, nil)

signer, err := signing.NewEdSigner()
require.NoError(t, err)

sig, err := o.Proof(context.Background(), signer.VRFSigner(), layer, 3)
require.NoError(t, err)
require.NotNil(t, sig)
}

func TestOracle_IsIdentityActive(t *testing.T) {
o := defaultOracle(t)
layer := types.LayerID(defLayersPerEpoch * 4)
numMiners := 2
o.mSyncer.EXPECT().IsSynced(context.Background()).Return(false).AnyTimes()
miners := o.createLayerData(layer.Sub(defLayersPerEpoch), numMiners)
for _, nodeID := range miners {
v, err := o.IsIdentityActiveOnConsensusView(context.Background(), nodeID, layer)
require.NoError(t, err)
require.True(t, v)
}
v, err := o.IsIdentityActiveOnConsensusView(context.Background(), types.NodeID{7, 7, 7}, layer)
require.NoError(t, err)
require.False(t, v)
}

func TestBuildVRFMessage_BeaconError(t *testing.T) {
o := defaultOracle(t)
errUnknown := errors.New("unknown")
Expand Down
2 changes: 1 addition & 1 deletion hare3/legacy_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (lg *legacyOracle) active(
layer types.LayerID,
ir IterRound,
) *types.HareEligibility {
vrf := eligibility.GenVRF(context.Background(), signer.VRFSigner(), beacon, layer, ir.Absolute())
vrf := eligibility.GenVRF(signer.VRFSigner(), beacon, layer, ir.Absolute())
committee := int(lg.config.CommitteeFor(layer))
if ir.Round == propose {
committee = int(lg.config.Leaders)
Expand Down
34 changes: 0 additions & 34 deletions hare4/eligibility/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,8 @@ func (o *Oracle) CalcEligibility(
return uint16(n), nil
}

// Proof returns the role proof for the current Layer & Round.
func (o *Oracle) Proof(
ctx context.Context,
signer *signing.VRFSigner,
layer types.LayerID,
round uint32,
) (types.VrfSignature, error) {
beacon, err := o.beacons.GetBeacon(layer.GetEpoch())
if err != nil {
return types.EmptyVrfSignature, fmt.Errorf("get beacon: %w", err)
}
return GenVRF(ctx, signer, beacon, layer, round), nil
}

// GenVRF generates vrf for hare eligibility.
func GenVRF(
ctx context.Context,
signer *signing.VRFSigner,
beacon types.Beacon,
layer types.LayerID,
Expand Down Expand Up @@ -538,25 +523,6 @@ func (o *Oracle) activeSetFromRefBallots(epoch types.EpochID) ([]types.ATXID, er
return maps.Keys(activeMap), nil
}

// IsIdentityActiveOnConsensusView returns true if the provided identity is active on the consensus view derived
// from the specified layer, false otherwise.
func (o *Oracle) IsIdentityActiveOnConsensusView(
ctx context.Context,
edID types.NodeID,
layer types.LayerID,
) (bool, error) {
o.log.Debug("hare oracle checking for active identity", log.ZContext(ctx))
defer func() {
o.log.Debug("hare oracle active identity check complete", log.ZContext(ctx))
}()
actives, err := o.actives(ctx, layer)
if err != nil {
return false, err
}
_, exist := actives.set[edID]
return exist, nil
}

func (o *Oracle) UpdateActiveSet(epoch types.EpochID, activeSet []types.ATXID) {
o.log.Info("received activeset update",
zap.Uint32("epoch", epoch.Uint32()),
Expand Down
46 changes: 1 addition & 45 deletions hare4/eligibility/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ func Test_VrfSignVerify(t *testing.T) {
// round is handpicked for vrf signature to pass
const round = 0

proof, err := o.Proof(context.Background(), signer.VRFSigner(), lid, round)
require.NoError(t, err)
proof := GenVRF(signer.VRFSigner(), types.Beacon{1, 0, 0, 0}, lid, round)

res, err := o.CalcEligibility(context.Background(), lid, round, 10, nid, proof)
require.NoError(t, err)
Expand All @@ -421,49 +420,6 @@ func Test_VrfSignVerify(t *testing.T) {
require.True(t, valid)
}

func Test_Proof_BeaconError(t *testing.T) {
o := defaultOracle(t)

signer, err := signing.NewEdSigner()
require.NoError(t, err)

layer := types.LayerID(2)
errUnknown := errors.New("unknown")
o.mBeacon.EXPECT().GetBeacon(layer.GetEpoch()).Return(types.EmptyBeacon, errUnknown).Times(1)

_, err = o.Proof(context.Background(), signer.VRFSigner(), layer, 3)
require.ErrorIs(t, err, errUnknown)
}

func Test_Proof(t *testing.T) {
o := defaultOracle(t)
layer := types.LayerID(2)
o.mBeacon.EXPECT().GetBeacon(layer.GetEpoch()).Return(types.Beacon{1, 0, 0, 0}, nil)

signer, err := signing.NewEdSigner()
require.NoError(t, err)

sig, err := o.Proof(context.Background(), signer.VRFSigner(), layer, 3)
require.NoError(t, err)
require.NotNil(t, sig)
}

func TestOracle_IsIdentityActive(t *testing.T) {
o := defaultOracle(t)
layer := types.LayerID(defLayersPerEpoch * 4)
numMiners := 2
o.mSyncer.EXPECT().IsSynced(context.Background()).Return(false).AnyTimes()
miners := o.createLayerData(layer.Sub(defLayersPerEpoch), numMiners)
for _, nodeID := range miners {
v, err := o.IsIdentityActiveOnConsensusView(context.Background(), nodeID, layer)
require.NoError(t, err)
require.True(t, v)
}
v, err := o.IsIdentityActiveOnConsensusView(context.Background(), types.NodeID{7, 7, 7}, layer)
require.NoError(t, err)
require.False(t, v)
}

func TestBuildVRFMessage_BeaconError(t *testing.T) {
o := defaultOracle(t)
errUnknown := errors.New("unknown")
Expand Down
4 changes: 2 additions & 2 deletions hare4/legacy_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"go.uber.org/zap"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
"github.com/spacemeshos/go-spacemesh/hare4/eligibility"
"github.com/spacemeshos/go-spacemesh/signing"
)

Expand Down Expand Up @@ -49,7 +49,7 @@ func (lg *legacyOracle) active(
layer types.LayerID,
ir IterRound,
) *types.HareEligibility {
vrf := eligibility.GenVRF(context.Background(), signer.VRFSigner(), beacon, layer, ir.Absolute())
vrf := eligibility.GenVRF(signer.VRFSigner(), beacon, layer, ir.Absolute())
committee := int(lg.config.CommitteeFor(layer))
if ir.Round == propose {
committee = int(lg.config.Leaders)
Expand Down
2 changes: 1 addition & 1 deletion sync2/multipeer/multipeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (mpr *MultiPeerReconciler) fullSync(ctx context.Context, syncPeers []p2p.Pe
default:
// failing to sync against a particular peer is not considered
// a fatal sync failure, so we just log the error
mpr.logger.Error("error syncing peer", zap.Stringer("peer", p), zap.Error(err))
mpr.logger.Debug("error syncing peer", zap.Stringer("peer", p), zap.Error(err))
}
return nil
})
Expand Down

0 comments on commit bb6c39f

Please sign in to comment.