Skip to content

Commit 2ddf410

Browse files
authored
Expose certs on the F3 API (#367)
* Expose certs on the F3 API Signed-off-by: Jakub Sztandera <[email protected]> * Remove unused ActorID param from F3 API Signed-off-by: Jakub Sztandera <[email protected]> --------- Signed-off-by: Jakub Sztandera <[email protected]>
1 parent f81cda2 commit 2ddf410

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

cmd/f3/run.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,13 @@ var runCmd = cli.Command{
7979

8080
ec := NewFakeEC(1, m)
8181

82-
module, err := f3.New(ctx, gpbft.ActorID(id), m, ds, h, ps,
82+
module, err := f3.New(ctx, m, ds, h, ps,
8383
signingBackend, ec, log, nil)
8484
if err != nil {
8585
return xerrors.Errorf("creating module: %w", err)
8686
}
8787

88-
actorID := gpbft.ActorID(c.Uint64("id"))
89-
90-
go runMessageSubscription(ctx, module, actorID, signingBackend)
88+
go runMessageSubscription(ctx, module, gpbft.ActorID(id), signingBackend)
9189

9290
return module.Run(ctx)
9391
},

f3.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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 {
3839
type 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.
245257
func (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
}

host.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type gpbftRunner struct {
2727
// gpbftHost is a newtype of gpbftRunner exposing APIs required by the gpbft.Participant
2828
type gpbftHost gpbftRunner
2929

30-
func newRunner(id gpbft.ActorID, m Manifest, client *client) (*gpbftRunner, error) {
30+
func newRunner(m Manifest, client *client) (*gpbftRunner, error) {
3131
runner := &gpbftRunner{
3232
client: client,
3333
manifest: m,
@@ -40,7 +40,7 @@ func newRunner(id gpbft.ActorID, m Manifest, client *client) (*gpbftRunner, erro
4040
<-runner.alertTimer.C
4141
}
4242

43-
runner.log.Infof("starting runner for P%d", id)
43+
runner.log.Infof("Starting gpbft runner")
4444
p, err := gpbft.NewParticipant((*gpbftHost)(runner), gpbft.WithTracer(client))
4545
if err != nil {
4646
return nil, xerrors.Errorf("creating participant: %w", err)

0 commit comments

Comments
 (0)