77 "time"
88
99 "github.com/Kubuxu/go-broadcast"
10+ "github.com/filecoin-project/go-f3/certs"
1011 "github.com/filecoin-project/go-f3/certstore"
1112 "github.com/filecoin-project/go-f3/gpbft"
1213 "github.com/ipfs/go-datastore"
@@ -38,7 +39,6 @@ type F3 struct {
3839type client struct {
3940 // certStore is nil until Run is called on the F3
4041 certStore * certstore.Store
41- id gpbft.ActorID
4242 networkName gpbft.NetworkName
4343 ec ECBackend
4444
@@ -80,7 +80,7 @@ func (mc *client) Logger() Logger {
8080// New creates and setups f3 with libp2p
8181// The context is used for initialization not runtime.
8282// signingMarshaller can be nil for default SigningMarshaler
83- func New (ctx context.Context , id gpbft. ActorID , manifest Manifest , ds datastore.Datastore , h host.Host ,
83+ func New (ctx context.Context , manifest Manifest , ds datastore.Datastore , h host.Host ,
8484 ps * pubsub.PubSub , verif gpbft.Verifier , ec ECBackend , log Logger , signingMarshaller gpbft.SigningMarshaler ) (* F3 , error ) {
8585 ds = namespace .Wrap (ds , manifest .NetworkName .DatastorePrefix ())
8686 loggerWithSkip := log
@@ -103,7 +103,6 @@ func New(ctx context.Context, id gpbft.ActorID, manifest Manifest, ds datastore.
103103 client : & client {
104104 ec : ec ,
105105 networkName : manifest .NetworkName ,
106- id : id ,
107106 Verifier : verif ,
108107 logger : log ,
109108 loggerWithSkip : loggerWithSkip ,
@@ -241,6 +240,19 @@ func (m *F3) boostrap(ctx context.Context) error {
241240 return nil
242241}
243242
243+ func (m * F3 ) GetLatestCert (ctx context.Context ) (* certs.FinalityCertificate , error ) {
244+ if m .certStore == nil {
245+ return nil , xerrors .Errorf ("F3 is not running" )
246+ }
247+ return m .certStore .Latest (), nil
248+ }
249+ func (m * F3 ) GetCert (ctx context.Context , instance uint64 ) (* certs.FinalityCertificate , error ) {
250+ if m .certStore == nil {
251+ return nil , xerrors .Errorf ("F3 is not running" )
252+ }
253+ return m .certStore .Get (ctx , instance )
254+ }
255+
244256// Run start the module. It will exit when context is cancelled.
245257func (m * F3 ) Run (ctx context.Context ) error {
246258 ctx , cancel := context .WithCancel (ctx )
@@ -258,7 +270,7 @@ func (m *F3) Run(ctx context.Context) error {
258270 return xerrors .Errorf ("opening certstore: %w" , err )
259271 }
260272
261- runner , err := newRunner (m .client . id , m . Manifest , m .client )
273+ runner , err := newRunner (m .Manifest , m .client )
262274 if err != nil {
263275 return xerrors .Errorf ("creating gpbft host: %w" , err )
264276 }
0 commit comments