1- package ec
1+ package consensus
22
33import (
44 "context"
@@ -7,14 +7,18 @@ import (
77 "sync"
88 "time"
99
10+ "github.com/filecoin-project/go-f3/ec"
1011 "golang.org/x/crypto/blake2b"
1112
1213 "github.com/filecoin-project/go-f3/gpbft"
1314 "github.com/filecoin-project/go-f3/internal/clock"
1415 mbase "github.com/multiformats/go-multibase"
1516)
1617
17- var _ Backend = (* FakeEC )(nil )
18+ var (
19+ _ ec.Backend = (* FakeEC )(nil )
20+ _ ec.TipSet = (* tipset )(nil )
21+ )
1822
1923type FakeEC struct {
2024 clock clock.Clock
@@ -28,20 +32,20 @@ type FakeEC struct {
2832 pausedAt * time.Time
2933}
3034
31- type Tipset struct {
35+ type tipset struct {
3236 tsk []byte
3337 epoch int64
3438 timestamp time.Time
3539}
3640
37- func (ts * Tipset ) Key () gpbft.TipSetKey {
41+ func (ts * tipset ) Key () gpbft.TipSetKey {
3842 return ts .tsk
3943}
4044
41- func (ts * Tipset ) Epoch () int64 {
45+ func (ts * tipset ) Epoch () int64 {
4246 return ts .epoch
4347}
44- func (ts * Tipset ) Beacon () []byte {
48+ func (ts * tipset ) Beacon () []byte {
4549 h , err := blake2b .New256 ([]byte ("beacon" ))
4650 if err != nil {
4751 panic (err )
@@ -50,11 +54,11 @@ func (ts *Tipset) Beacon() []byte {
5054 return h .Sum (nil )
5155}
5256
53- func (ts * Tipset ) Timestamp () time.Time {
57+ func (ts * tipset ) Timestamp () time.Time {
5458 return ts .timestamp
5559}
5660
57- func (ts * Tipset ) String () string {
61+ func (ts * tipset ) String () string {
5862 res , _ := mbase .Encode (mbase .Base32 , ts .tsk [:gpbft .CidMaxLen ])
5963 for i := 1 ; i * gpbft .CidMaxLen < len (ts .tsk ); i ++ {
6064 enc , _ := mbase .Encode (mbase .Base32 , ts .tsk [gpbft .CidMaxLen * i :gpbft .CidMaxLen * (i + 1 )])
@@ -77,7 +81,7 @@ func NewFakeEC(ctx context.Context, seed uint64, bootstrapEpoch int64, ecPeriod
7781
7882var cidPrefixBytes = gpbft .CidPrefix .Bytes ()
7983
80- func (ec * FakeEC ) genTipset (epoch int64 ) * Tipset {
84+ func (ec * FakeEC ) genTipset (epoch int64 ) * tipset {
8185 h , err := blake2b .New256 (ec .seed )
8286 if err != nil {
8387 panic (err )
@@ -107,15 +111,15 @@ func (ec *FakeEC) genTipset(epoch int64) *Tipset {
107111 tsk = append (tsk , cidPrefixBytes ... )
108112 tsk = append (tsk , digest ... )
109113 }
110- return & Tipset {
114+ return & tipset {
111115 tsk : tsk ,
112116 epoch : epoch ,
113117 timestamp : ec .ecStart .Add (time .Duration (epoch ) * ec .ecPeriod ),
114118 }
115119}
116120
117121// GetTipsetByHeight should return a tipset or nil/empty byte array if it does not exists
118- func (ec * FakeEC ) GetTipsetByEpoch (ctx context.Context , epoch int64 ) (TipSet , error ) {
122+ func (ec * FakeEC ) GetTipsetByEpoch (ctx context.Context , epoch int64 ) (ec. TipSet , error ) {
119123 if ec .GetCurrentHead () < epoch {
120124 return nil , fmt .Errorf ("does not yet exist" )
121125 }
@@ -127,8 +131,7 @@ func (ec *FakeEC) GetTipsetByEpoch(ctx context.Context, epoch int64) (TipSet, er
127131 return ts , nil
128132}
129133
130- func (ec * FakeEC ) GetParent (ctx context.Context , ts TipSet ) (TipSet , error ) {
131-
134+ func (ec * FakeEC ) GetParent (ctx context.Context , ts ec.TipSet ) (ec.TipSet , error ) {
132135 for epoch := ts .Epoch () - 1 ; epoch > 0 ; epoch -- {
133136 ts , err := ec .GetTipsetByEpoch (ctx , epoch )
134137 if err != nil {
@@ -168,15 +171,15 @@ func (ec *FakeEC) Resume() {
168171 ec .pausedAt = nil
169172}
170173
171- func (ec * FakeEC ) GetHead (ctx context.Context ) (TipSet , error ) {
174+ func (ec * FakeEC ) GetHead (ctx context.Context ) (ec. TipSet , error ) {
172175 return ec .GetTipsetByEpoch (ctx , ec .GetCurrentHead ())
173176}
174177
175- func (ec * FakeEC ) GetPowerTable (ctx context.Context , tsk gpbft.TipSetKey ) (gpbft.PowerEntries , error ) {
178+ func (ec * FakeEC ) GetPowerTable (context.Context , gpbft.TipSetKey ) (gpbft.PowerEntries , error ) {
176179 return ec .initialPowerTable , nil
177180}
178181
179- func (ec * FakeEC ) GetTipset (ctx context.Context , tsk gpbft.TipSetKey ) (TipSet , error ) {
182+ func (ec * FakeEC ) GetTipset (_ context.Context , tsk gpbft.TipSetKey ) (ec. TipSet , error ) {
180183 epoch := binary .BigEndian .Uint64 (tsk [6 + 32 - 8 : 6 + 32 ])
181184 return ec .genTipset (int64 (epoch )), nil
182185}
0 commit comments