Skip to content

Commit ca469f8

Browse files
committed
feat: support for api ChainExport v2 snapshot
1 parent cbed4c2 commit ca469f8

File tree

9 files changed

+48
-14
lines changed

9 files changed

+48
-14
lines changed

api/api_full.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ type FullNode interface {
207207
// back to genesis, the entire genesis state, and the most recent 'nroots'
208208
// state trees.
209209
// If oldmsgskip is set, messages from before the requested roots are also not included.
210-
ChainExport(ctx context.Context, nroots abi.ChainEpoch, oldmsgskip bool, tsk types.TipSetKey) (<-chan []byte, error) //perm:read
210+
//
211+
ChainExport(ctx context.Context, nroots abi.ChainEpoch, oldmsgskip bool, tsk types.TipSetKey, version uint64) (<-chan []byte, error) //perm:read
211212

212213
// ChainExportRangeInternal triggers the export of a chain
213214
// CAR-snapshot directly to disk. It is similar to ChainExport,

api/mocks/mock_full.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proxy_gen.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v0api/v1_wrapper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,8 @@ func (w *WrapperV1Full) BeaconGetEntry(ctx context.Context, epoch abi.ChainEpoch
213213
return w.StateGetBeaconEntry(ctx, epoch)
214214
}
215215

216+
func (w *WrapperV1Full) ChainExport(ctx context.Context, nroots abi.ChainEpoch, oldmsgskip bool, tsk types.TipSetKey) (<-chan []byte, error) {
217+
return w.FullNode.ChainExport(ctx, nroots, oldmsgskip, tsk, 1)
218+
}
219+
216220
var _ FullNode = &WrapperV1Full{}

chain/lf3/f3.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/filecoin-project/go-f3"
2222
"github.com/filecoin-project/go-f3/blssig"
2323
"github.com/filecoin-project/go-f3/certs"
24+
"github.com/filecoin-project/go-f3/certstore"
2425
"github.com/filecoin-project/go-f3/gpbft"
2526
"github.com/filecoin-project/go-f3/manifest"
2627

@@ -41,6 +42,7 @@ type F3Backend interface {
4142
Participate(_ context.Context, ticket api.F3ParticipationTicket) (api.F3ParticipationLease, error)
4243
ListParticipants() []api.F3Participant
4344
GetManifest(ctx context.Context) (*manifest.Manifest, error)
45+
GetCertStore() (*certstore.Store, error)
4446
GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error)
4547
GetLatestCert(ctx context.Context) (*certs.FinalityCertificate, error)
4648
GetPowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error)
@@ -286,6 +288,10 @@ func (fff *F3) Participate(_ context.Context, ticket api.F3ParticipationTicket)
286288
return fff.leaser.participate(ticket)
287289
}
288290

291+
func (fff *F3) GetCertStore() (*certstore.Store, error) {
292+
return fff.inner.GetCertStore()
293+
}
294+
289295
func (fff *F3) GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error) {
290296
return fff.inner.GetCert(ctx, instance)
291297
}

cli/chain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func TestChainExport(t *testing.T) {
495495

496496
gomock.InOrder(
497497
mockApi.EXPECT().ChainHead(ctx).Return(ts, nil),
498-
mockApi.EXPECT().ChainExport(ctx, abi.ChainEpoch(0), false, ts.Key()).Return(export, nil),
498+
mockApi.EXPECT().ChainExport(ctx, abi.ChainEpoch(0), false, ts.Key(), 1).Return(export, nil),
499499
)
500500

501501
err := app.Run([]string{"chain", "export", "whatever.car"})

documentation/en/api-methods-v1-stable.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

itests/kit/f3.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/filecoin-project/go-f3"
88
"github.com/filecoin-project/go-f3/certs"
9+
"github.com/filecoin-project/go-f3/certstore"
910
"github.com/filecoin-project/go-f3/gpbft"
1011
"github.com/filecoin-project/go-f3/manifest"
1112

@@ -69,6 +70,10 @@ func (t *MockF3Backend) GetManifest(context.Context) (*manifest.Manifest, error)
6970
}, nil
7071
}
7172

73+
func (t *MockF3Backend) GetCertStore() (*certstore.Store, error) {
74+
return nil, nil
75+
}
76+
7277
func (t *MockF3Backend) GetCert(_ context.Context, instance uint64) (*certs.FinalityCertificate, error) {
7378
if !t.Running {
7479
return nil, f3.ErrF3NotRunning

node/impl/full/chain.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/filecoin-project/go-address"
3232
amt4 "github.com/filecoin-project/go-amt-ipld/v4"
3333
"github.com/filecoin-project/go-f3/certs"
34+
"github.com/filecoin-project/go-f3/certstore"
3435
"github.com/filecoin-project/go-state-types/abi"
3536
"github.com/filecoin-project/specs-actors/actors/util/adt"
3637

@@ -62,6 +63,7 @@ type ChainModuleAPI interface {
6263
ChainGetTipSetAfterHeight(ctx context.Context, h abi.ChainEpoch, tsk types.TipSetKey) (*types.TipSet, error)
6364
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
6465
ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error)
66+
ChainExport(ctx context.Context, nroots abi.ChainEpoch, skipoldmsgs bool, tsk types.TipSetKey, version uint64) (<-chan []byte, error)
6567
}
6668

6769
var _ ChainModuleAPI = *new(api.FullNode)
@@ -703,17 +705,32 @@ func (a ChainAPI) ChainExportRangeInternal(ctx context.Context, head, tail types
703705
return nil
704706
}
705707

706-
func (a *ChainAPI) ChainExport(ctx context.Context, nroots abi.ChainEpoch, skipoldmsgs bool, tsk types.TipSetKey) (<-chan []byte, error) {
707-
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
708+
func (m *ChainModule) ChainExport(ctx context.Context, nroots abi.ChainEpoch, skipoldmsgs bool, tsk types.TipSetKey, version uint64) (<-chan []byte, error) {
709+
ts, err := m.Chain.GetTipSetFromKey(ctx, tsk)
708710
if err != nil {
709711
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
710712
}
713+
714+
var certstore *certstore.Store
715+
if version == 2 {
716+
certstore, err = m.F3.GetCertStore()
717+
if err != nil {
718+
return nil, xerrors.Errorf("getting certstore: %w", err)
719+
}
720+
}
721+
711722
r, w := io.Pipe()
712723
out := make(chan []byte)
713724
go func() {
714725
bw := bufio.NewWriterSize(w, 1<<20)
715726

716-
err = a.Chain.ExportV1(ctx, ts, nroots, skipoldmsgs, bw)
727+
// export v1 snapshot if not certstore or version is SnapshotVersion1
728+
if certstore == nil || version == 1 {
729+
err = m.Chain.ExportV1(ctx, ts, nroots, skipoldmsgs, bw)
730+
} else {
731+
err = m.Chain.ExportV2(ctx, ts, nroots, skipoldmsgs, certstore, bw)
732+
}
733+
717734
_ = bw.Flush() // it is a write to a pipe
718735
_ = w.CloseWithError(err) // it is a pipe
719736
}()

0 commit comments

Comments
 (0)