Skip to content

Commit

Permalink
core/types: add duty type for DutyAggregator (#1114)
Browse files Browse the repository at this point in the history
Add duty type for `DutyAggregator`.

category: feature
ticket: #1075
  • Loading branch information
xenowits committed Sep 12, 2022
1 parent 8220126 commit 68e01b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
17 changes: 16 additions & 1 deletion core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ const (
DutyBuilderRegistration DutyType = 6
DutyRandao DutyType = 7
DutyPrepareAggregator DutyType = 8
DutyAggregator DutyType = 9
// Only ever append new types here...

dutySentinel DutyType = 9 // Must always be last
dutySentinel DutyType = 10 // Must always be last
)

func (d DutyType) Valid() bool {
Expand All @@ -61,6 +62,7 @@ func (d DutyType) String() string {
DutyBuilderRegistration: "builder_registration",
DutyRandao: "randao",
DutyPrepareAggregator: "prepare_aggregator",
DutyAggregator: "aggregator",
}[d]
}

Expand Down Expand Up @@ -190,6 +192,19 @@ func NewPrepareAggregatorDuty(slot int64) Duty {
}
}

// NewAggregatorDuty returns a new aggregator duty. It is a convenience function that is
// slightly more readable and concise than the struct literal equivalent:
//
// core.Duty{Slot: slot, Type: core.DutyAggregator}
// vs
// core.NewAggregatorDuty(slot)
func NewAggregatorDuty(slot int64) Duty {
return Duty{
Slot: slot,
Type: DutyAggregator,
}
}

const (
pkLen = 98 // "0x" + hex.Encode([48]byte) = 2+2*48
sigLen = 96
Expand Down
3 changes: 2 additions & 1 deletion core/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func TestBackwardsCompatability(t *testing.T) {
require.EqualValues(t, 6, core.DutyBuilderRegistration)
require.EqualValues(t, 7, core.DutyRandao)
require.EqualValues(t, 8, core.DutyPrepareAggregator)
require.EqualValues(t, 9, core.DutyAggregator)
// Add more types here.

const sentinel = core.DutyType(9)
const sentinel = core.DutyType(10)
for i := core.DutyUnknown; i <= sentinel; i++ {
if i == core.DutyUnknown {
require.False(t, i.Valid())
Expand Down
2 changes: 1 addition & 1 deletion dkg/exchanger.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newExchanger(tcpNode host.Host, peerIdx int, peers []peer.ID, vals int) *ex
// signatures of the group according to public key of each DV.
func (e *exchanger) exchange(ctx context.Context, sigType sigType, set core.ParSignedDataSet) (map[core.PubKey][]core.ParSignedData, error) {
// Start the process by storing current peer's ParSignedDataSet
duty := core.Duty{Type: core.DutySignature, Slot: int64(sigType)}
duty := core.NewSignatureDuty(int64(sigType))
err := e.sigdb.StoreInternal(ctx, duty, set)
if err != nil {
return nil, err
Expand Down

0 comments on commit 68e01b6

Please sign in to comment.