Skip to content

Commit f81cda2

Browse files
authored
Move initial instance to manifest (#363)
* Move initial instance to manifest Resolves #360 Signed-off-by: Jakub Sztandera <[email protected]> * Switch urfave/cli to one used by lotus Signed-off-by: Jakub Sztandera <[email protected]> --------- Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 5c8a985 commit f81cda2

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

cmd/f3/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ var runCmd = cli.Command{
8989

9090
go runMessageSubscription(ctx, module, actorID, signingBackend)
9191

92-
initialInstance := c.Uint64("instance")
93-
return module.Run(initialInstance, ctx)
92+
return module.Run(ctx)
9493
},
9594
}
9695

f3.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (m *F3) teardownPubsub() error {
191191
)
192192
}
193193

194-
func (m *F3) boostrap(ctx context.Context, initialInstance uint64) error {
194+
func (m *F3) boostrap(ctx context.Context) error {
195195
head, err := m.ec.GetHead(ctx)
196196
if err != nil {
197197
return xerrors.Errorf("failed to get the head: %w", err)
@@ -233,7 +233,7 @@ func (m *F3) boostrap(ctx context.Context, initialInstance uint64) error {
233233
return xerrors.Errorf("getting initial power table: %w", err)
234234
}
235235

236-
cs, err := certstore.CreateStore(ctx, m.ds, initialInstance, initialPowerTable)
236+
cs, err := certstore.CreateStore(ctx, m.ds, m.Manifest.InitialInstance, initialPowerTable)
237237
if err != nil {
238238
return xerrors.Errorf("creating certstore: %w", err)
239239
}
@@ -242,15 +242,15 @@ func (m *F3) boostrap(ctx context.Context, initialInstance uint64) error {
242242
}
243243

244244
// Run start the module. It will exit when context is cancelled.
245-
func (m *F3) Run(initialInstance uint64, ctx context.Context) error {
245+
func (m *F3) Run(ctx context.Context) error {
246246
ctx, cancel := context.WithCancel(ctx)
247247
defer cancel()
248248

249249
cs, err := certstore.OpenStore(ctx, m.ds)
250250
if err == nil {
251251
m.setCertStore(cs)
252252
} else if errors.Is(err, certstore.ErrNotInitialized) {
253-
err := m.boostrap(ctx, initialInstance)
253+
err := m.boostrap(ctx)
254254
if err != nil {
255255
return xerrors.Errorf("failed to boostrap: %w", err)
256256
}
@@ -278,7 +278,12 @@ func (m *F3) Run(initialInstance uint64, ctx context.Context) error {
278278
runnerErrCh := make(chan error, 1)
279279

280280
go func() {
281-
err := runner.Run(initialInstance, ctx)
281+
latest := m.certStore.Latest()
282+
startInstance := uint64(m.Manifest.InitialInstance)
283+
if latest != nil {
284+
startInstance = latest.GPBFTInstance + 1
285+
}
286+
err := runner.Run(startInstance, ctx)
282287
m.log.Errorf("running host: %+v", err)
283288
runnerErrCh <- err
284289
}()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/libp2p/go-libp2p v0.35.0
1515
github.com/libp2p/go-libp2p-pubsub v0.11.0
1616
github.com/stretchr/testify v1.9.0
17-
github.com/urfave/cli/v2 v2.27.2
17+
github.com/urfave/cli/v2 v2.25.5
1818
github.com/whyrusleeping/cbor-gen v0.1.1
1919
go.uber.org/multierr v1.11.0
2020
golang.org/x/crypto v0.23.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd
396396
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
397397
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
398398
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
399-
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
400-
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
399+
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
400+
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
401401
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
402402
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
403403
github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=

host.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ func (h *gpbftHost) collectChain(base TipSet, head TipSet) ([]TipSet, error) {
102102
// TODO: optimize when head is way beyond base
103103
res := make([]TipSet, 0, 2*gpbft.CHAIN_MAX_LEN)
104104
res = append(res, head)
105+
105106
for !bytes.Equal(head.Key(), base.Key()) {
107+
if head.Epoch() < base.Epoch() {
108+
// we reorged away from base
109+
// scream and panic??
110+
// TODO make sure this is correct, re-boostrap/manifest swap code has to be able to
111+
// catch it
112+
panic("reorg-ed away from base, dunno what to do, reboostrap is the answer")
113+
}
106114
var err error
107115
head, err = h.client.ec.GetParent(h.runningCtx, head)
108116
if err != nil {
@@ -123,7 +131,7 @@ func (h *gpbftHost) collectChain(base TipSet, head TipSet) ([]TipSet, error) {
123131
// ReceiveDecision (or known to be final via some other channel).
124132
func (h *gpbftHost) GetProposalForInstance(instance uint64) (*gpbft.SupplementalData, gpbft.ECChain, error) {
125133
var baseTsk gpbft.TipSetKey
126-
if instance == 0 {
134+
if instance == h.manifest.InitialInstance {
127135
ts, err := h.client.ec.GetTipsetByEpoch(h.runningCtx,
128136
h.manifest.BootstrapEpoch-h.manifest.ECFinality)
129137
if err != nil {
@@ -203,7 +211,7 @@ func (h *gpbftHost) GetCommitteeForInstance(instance uint64) (*gpbft.PowerTable,
203211
var powerEntries gpbft.PowerEntries
204212
var err error
205213

206-
if instance < h.manifest.CommiteeLookback {
214+
if instance < h.manifest.InitialInstance+h.manifest.CommiteeLookback {
207215
//boostrap phase
208216
ts, err := h.client.ec.GetTipsetByEpoch(h.runningCtx, h.manifest.BootstrapEpoch-h.manifest.ECFinality)
209217
if err != nil {
@@ -223,8 +231,7 @@ func (h *gpbftHost) GetCommitteeForInstance(instance uint64) (*gpbft.PowerTable,
223231

224232
powerEntries, err = h.client.certStore.GetPowerTable(h.runningCtx, instance)
225233
if err != nil {
226-
// this fires every round, is this correct?
227-
h.log.Infof("failed getting power table from certstore: %v, falling back to EC", err)
234+
h.log.Debugf("failed getting power table from certstore: %v, falling back to EC", err)
228235

229236
powerEntries, err = h.client.ec.GetPowerTable(h.runningCtx, powerTsk)
230237
if err != nil {
@@ -318,7 +325,7 @@ func (h *gpbftHost) saveDecision(decision *gpbft.Justification) error {
318325
if err != nil {
319326
return xerrors.Errorf("forming certificate out of decision: %w", err)
320327
}
321-
_, _, _, err = certs.ValidateFinalityCertificates(h, h.NetworkName(), current.Entries, decision.Vote.Instance, cert.ECChain.Base())
328+
_, _, _, err = certs.ValidateFinalityCertificates(h, h.NetworkName(), current.Entries, decision.Vote.Instance, nil, *cert)
322329
if err != nil {
323330
return xerrors.Errorf("certificate is invalid: %w", err)
324331
}
@@ -327,6 +334,7 @@ func (h *gpbftHost) saveDecision(decision *gpbft.Justification) error {
327334
if err != nil {
328335
return xerrors.Errorf("saving ceritifcate in a store: %w", err)
329336
}
337+
330338
return nil
331339
}
332340

manifest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
type Manifest struct {
1212
NetworkName gpbft.NetworkName
13+
InitialInstance uint64
1314
InitialPowerTable gpbft.PowerEntries
1415
BootstrapEpoch int64
1516

0 commit comments

Comments
 (0)