Skip to content

Commit 67fc818

Browse files
committed
Make checkpointing chainstore optional via build constraints
1 parent 31aebd2 commit 67fc818

10 files changed

+48
-15
lines changed

build/buildconstants/params_2k.go

+4
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,7 @@ var F3Enabled = true
200200
const ManifestServerID = "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG"
201201

202202
var F3BootstrapEpoch abi.ChainEpoch = 1000
203+
204+
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
205+
// flag has no effect if F3 is not enabled.
206+
const F3Consensus = true

build/buildconstants/params_butterfly.go

+4
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ var WhitelistedBlock = cid.Undef
101101
const F3Enabled = true
102102
const ManifestServerID = "12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYWvBK9TC3Yn6"
103103
const F3BootstrapEpoch abi.ChainEpoch = 1000
104+
105+
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
106+
// flag has no effect if F3 is not enabled.
107+
const F3Consensus = true

build/buildconstants/params_calibnet.go

+4
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,7 @@ var WhitelistedBlock = cid.Undef
148148
const F3Enabled = true
149149
const ManifestServerID = "12D3KooWS9vD9uwm8u2uPyJV32QBAhKAmPYwmziAgr3Xzk2FU1Mr"
150150
const F3BootstrapEpoch abi.ChainEpoch = UpgradeWaffleHeight + 100
151+
152+
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
153+
// flag has no effect if F3 is not enabled.
154+
const F3Consensus = true

build/buildconstants/params_interop.go

+4
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,7 @@ var WhitelistedBlock = cid.Undef
139139
const F3Enabled = true
140140
const ManifestServerID = "12D3KooWQJ2rdVnG4okDUB6yHQhAjNutGNemcM7XzqC9Eo4z9Jce"
141141
const F3BootstrapEpoch abi.ChainEpoch = 1000
142+
143+
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
144+
// flag has no effect if F3 is not enabled.
145+
const F3Consensus = true

build/buildconstants/params_mainnet.go

+4
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,7 @@ var WhitelistedBlock = cid.MustParse("bafy2bzaceapyg2uyzk7vueh3xccxkuwbz3nxewjyg
173173
const F3Enabled = true
174174
const ManifestServerID = "12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7"
175175
const F3BootstrapEpoch abi.ChainEpoch = -1
176+
177+
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
178+
// flag has no effect if F3 is not enabled.
179+
const F3Consensus = false

build/buildconstants/params_testground.go

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ var (
126126
F3Enabled = false
127127
ManifestServerID = ""
128128
F3BootstrapEpoch abi.ChainEpoch = -1
129+
130+
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
131+
// flag has no effect if F3 is not enabled.
132+
F3Consensus = true
129133
)
130134

131135
func init() {

chain/lf3/ec.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type ecWrapper struct {
3030
ChainStore *store.ChainStore
3131
Syncer *chain.Syncer
3232
StateManager *stmgr.StateManager
33+
34+
// Checkpoint sets whether to checkpoint tipsets finalized by F3 in ChainStore.
35+
Checkpoint bool
3336
}
3437

3538
type f3TipSet struct {
@@ -209,6 +212,9 @@ func (ec *ecWrapper) getPowerTableLotusTSK(ctx context.Context, tsk types.TipSet
209212
}
210213

211214
func (ec *ecWrapper) Finalize(ctx context.Context, key gpbft.TipSetKey) error {
215+
if !ec.Checkpoint {
216+
return nil // Nothing to do; checkpointing is not enabled.
217+
}
212218
tsk, err := toLotusTipSetKey(key)
213219
if err != nil {
214220
return err
@@ -242,9 +248,5 @@ func (ec *ecWrapper) getTipSetFromF3TSK(ctx context.Context, key gpbft.TipSetKey
242248
}
243249

244250
func toLotusTipSetKey(key gpbft.TipSetKey) (types.TipSetKey, error) {
245-
tsk, err := types.TipSetKeyFromBytes(key)
246-
if err != nil {
247-
return types.TipSetKey{}, xerrors.Errorf("decoding tpiset key: %w", err)
248-
}
249-
return tsk, nil
251+
return types.TipSetKeyFromBytes(key)
250252
}

chain/lf3/f3.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ type F3 struct {
3636
newLeases chan leaseRequest
3737
}
3838

39+
type F3ConsensusEnabled bool
40+
3941
type F3Params struct {
4042
fx.In
4143

42-
NetworkName dtypes.NetworkName
43-
ManifestProvider manifest.ManifestProvider
44-
PubSub *pubsub.PubSub
45-
Host host.Host
46-
ChainStore *store.ChainStore
47-
Syncer *chain.Syncer
48-
StateManager *stmgr.StateManager
49-
Datastore dtypes.MetadataDS
50-
Wallet api.Wallet
44+
NetworkName dtypes.NetworkName
45+
ManifestProvider manifest.ManifestProvider
46+
PubSub *pubsub.PubSub
47+
Host host.Host
48+
ChainStore *store.ChainStore
49+
Syncer *chain.Syncer
50+
StateManager *stmgr.StateManager
51+
Datastore dtypes.MetadataDS
52+
Wallet api.Wallet
53+
F3ConsensusEnabled F3ConsensusEnabled
5154
}
5255

5356
var log = logging.Logger("f3")
@@ -59,6 +62,7 @@ func New(mctx helpers.MetricsCtx, lc fx.Lifecycle, params F3Params) (*F3, error)
5962
ChainStore: params.ChainStore,
6063
StateManager: params.StateManager,
6164
Syncer: params.Syncer,
65+
Checkpoint: bool(params.F3ConsensusEnabled),
6266
}
6367
verif := blssig.VerifierWithKeyOnG1()
6468

chain/types/tipset_key.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
block "github.com/ipfs/go-block-format"
1111
"github.com/ipfs/go-cid"
1212
typegen "github.com/whyrusleeping/cbor-gen"
13+
"golang.org/x/xerrors"
1314

1415
"github.com/filecoin-project/go-state-types/abi"
1516
)
@@ -52,7 +53,7 @@ func NewTipSetKey(cids ...cid.Cid) TipSetKey {
5253
func TipSetKeyFromBytes(encoded []byte) (TipSetKey, error) {
5354
_, err := decodeKey(encoded)
5455
if err != nil {
55-
return EmptyTSK, err
56+
return EmptyTSK, xerrors.Errorf("decoding tpiset key: %w", err)
5657
}
5758
return TipSetKey{string(encoded)}, nil
5859
}

node/builder_chain.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/filecoin-project/lotus/api"
1515
"github.com/filecoin-project/lotus/build"
16+
"github.com/filecoin-project/lotus/build/buildconstants"
1617
"github.com/filecoin-project/lotus/chain"
1718
"github.com/filecoin-project/lotus/chain/beacon"
1819
"github.com/filecoin-project/lotus/chain/consensus"
@@ -164,6 +165,7 @@ var ChainNode = Options(
164165
),
165166

166167
If(build.IsF3Enabled(),
168+
Override(new(*lf3.F3ConsensusEnabled), buildconstants.F3Consensus),
167169
Override(new(manifest.ManifestProvider), lf3.NewManifestProvider),
168170
Override(new(*lf3.F3), lf3.New),
169171
),

0 commit comments

Comments
 (0)