Skip to content

Commit 656fd8d

Browse files
authored
maintainence(lib/babe): refactor code to use epochHandler for control of epoch logic (#2151)
1 parent 9e360a5 commit 656fd8d

18 files changed

+1011
-635
lines changed

dot/types/authority.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package types
55

66
import (
77
"encoding/binary"
8+
"fmt"
89
"io"
910

1011
"github.com/ChainSafe/gossamer/lib/common"
@@ -74,6 +75,16 @@ func (a *Authority) ToRaw() *AuthorityRaw {
7475
return raw
7576
}
7677

78+
// DeepCopy creates a deep copy of the Authority
79+
func (a *Authority) DeepCopy() *Authority {
80+
pk := a.Key.Encode()
81+
pkCopy, _ := sr25519.NewPublicKey(pk[:])
82+
return &Authority{
83+
Key: pkCopy,
84+
Weight: a.Weight,
85+
}
86+
}
87+
7788
// FromRawSr25519 sets the Authority given AuthorityRaw. It converts the byte representations of
7889
// the authority public keys into a sr25519.PublicKey.
7990
func (a *Authority) FromRawSr25519(raw *AuthorityRaw) error {
@@ -93,6 +104,10 @@ type AuthorityRaw struct {
93104
Weight uint64
94105
}
95106

107+
func (a *AuthorityRaw) String() string {
108+
return fmt.Sprintf("AuthorityRaw Key=0x%x Weight=%d", a.Key, a.Weight)
109+
}
110+
96111
// AuthoritiesToRaw converts an array of Authority in an array of AuthorityRaw
97112
func AuthoritiesToRaw(auths []Authority) []AuthorityRaw {
98113
raw := make([]AuthorityRaw, len(auths))

dot/types/consensus_digest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package types
55

66
import (
7+
"fmt"
8+
79
"github.com/ChainSafe/gossamer/pkg/scale"
810
)
911

@@ -70,6 +72,10 @@ type NextEpochData struct {
7072
// Index Returns VDT index
7173
func (d NextEpochData) Index() uint { return 1 }
7274

75+
func (d NextEpochData) String() string {
76+
return fmt.Sprintf("NextEpochData Authorities=%v Randomness=%v", d.Authorities, d.Randomness)
77+
}
78+
7379
// ToEpochData returns the NextEpochData as EpochData
7480
func (d *NextEpochData) ToEpochData() (*EpochData, error) {
7581
auths, err := BABEAuthorityRawToAuthority(d.Authorities)

0 commit comments

Comments
 (0)