Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/transport #6426

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/submodule/eth/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (e *ethAPIDummy) EthGetBlockByHash(ctx context.Context, blkHash types.EthHa
return types.EthBlock{}, ErrModuleDisabled
}

func (e *ethAPIDummy) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (*types.EthBlock, error) {
return nil, ErrModuleDisabled
func (e *ethAPIDummy) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (types.EthBlock, error) {
return types.EthBlock{}, ErrModuleDisabled
}

func (e *ethAPIDummy) EthGetTransactionByHash(ctx context.Context, txHash *types.EthHash) (*types.EthTx, error) {
Expand Down
18 changes: 4 additions & 14 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,13 @@ func (a *ethAPI) parseBlkParam(ctx context.Context, blkParam string, strict bool
}
}

func (a *ethAPI) EthGetBlockByNumber(ctx context.Context, blkParam string, fullTxInfo bool) (*types.EthBlock, error) {
// Get the tipset for the specified block parameter
ts, err := a.parseBlkParam(ctx, blkParam, true)
func (a *ethAPI) EthGetBlockByNumber(ctx context.Context, blkParam string, fullTxInfo bool) (types.EthBlock, error) {
ts, err := getTipsetByBlockNumber(ctx, a.em.chainModule.ChainReader, blkParam, true)
if err != nil {
if err == ErrNullRound {
// Return nil for null rounds
return nil, nil
}
return nil, fmt.Errorf("failed to get tipset: %w", err)
}
// Create an Ethereum block from the Filecoin tipset
block, err := newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo, a.em.chainModule.MessageStore, a.em.chainModule.Stmgr)
if err != nil {
return nil, fmt.Errorf("failed to create Ethereum block: %w", err)
return types.EthBlock{}, err
}

return &block, nil
return newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo, a.em.chainModule.MessageStore, a.em.chainModule.Stmgr)
}

func (a *ethAPI) EthGetTransactionByHash(ctx context.Context, txHash *types.EthHash) (*types.EthTx, error) {
Expand Down
7 changes: 7 additions & 0 deletions app/submodule/f3/f3_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ func (f3api *f3API) F3GetProgress(context.Context) (gpbft.Instant, error) {
}
return f3api.f3module.F3.Progress(), nil
}

func (f3api *f3API) F3ListParticipants(ctx context.Context) ([]types.F3Participant, error) {
if f3api.f3module.F3 == nil {
return nil, types.ErrF3Disabled
}
return f3api.f3module.F3.ListParticipants(), nil
}
1 change: 0 additions & 1 deletion app/submodule/syncer/syncer_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,5 @@ func (sa *syncerAPI) SyncIncomingBlocks(ctx context.Context) (<-chan *types.Bloc
}

func (sa *syncerAPI) SyncCheckpoint(ctx context.Context, tsk types.TipSetKey) error {
log.Warnf("Marking tipset %s as checkpoint", tsk)
return sa.syncer.SyncProvider.SyncCheckpoint(ctx, tsk)
}
1 change: 0 additions & 1 deletion fixtures/networks/butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func ButterflySnapNet() *NetworkConf {
F3Enabled: true,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYWvBK9TC3Yn6",
F3Consensus: true,
F3InitialPowerTableCID: cid.Undef,
},
}
Expand Down
3 changes: 1 addition & 2 deletions fixtures/networks/calibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func Calibration() *NetworkConf {
AllowableClockDriftSecs: 1,
Eip155ChainID: 314159,
ActorDebugging: false,
F3Consensus: true,
F3InitialPowerTableCID: cid.Undef,
F3InitialPowerTableCID: cid.MustParse("bafy2bzaceab236vmmb3n4q4tkvua2n4dphcbzzxerxuey3mot4g3cov5j3r2c"),
},
}

Expand Down
1 change: 0 additions & 1 deletion fixtures/networks/forcenet.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func ForceNet() *NetworkConf {
F3Enabled: true,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG",
F3Consensus: true,
F3InitialPowerTableCID: cid.Undef,
},
}
Expand Down
1 change: 0 additions & 1 deletion fixtures/networks/integrationtestnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func IntegrationNet() *NetworkConf {
F3Enabled: false,
F3BootstrapEpoch: -1,
ManifestServerID: "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG",
F3Consensus: true,
F3InitialPowerTableCID: cid.Undef,
},
}
Expand Down
1 change: 0 additions & 1 deletion fixtures/networks/interopnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func InteropNet() *NetworkConf {
F3Enabled: true,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWQJ2rdVnG4okDUB6yHQhAjNutGNemcM7XzqC9Eo4z9Jce",
F3Consensus: true,
F3InitialPowerTableCID: cid.Undef,
},
}
Expand Down
1 change: 0 additions & 1 deletion fixtures/networks/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func Mainnet() *NetworkConf {
F3Enabled: true,
F3BootstrapEpoch: -1,
ManifestServerID: "12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7",
F3Consensus: false,
F3InitialPowerTableCID: cid.Undef,
},
}
Expand Down
1 change: 0 additions & 1 deletion fixtures/networks/net_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func Net2k() *NetworkConf {
F3Enabled: true,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG",
F3Consensus: true,
F3InitialPowerTableCID: cid.Undef,
},
}
Expand Down
74 changes: 51 additions & 23 deletions pkg/chain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ func (store *Store) GetTipSet(ctx context.Context, key types.TipSetKey) (*types.
return store.GetHead(), nil
}

return store.getTipSet(ctx, key)
}

func (store *Store) getTipSet(ctx context.Context, key types.TipSetKey) (*types.TipSet, error) {
if val, has := store.tsCache.Get(key); has {
return val, nil
}
Expand Down Expand Up @@ -1099,9 +1103,7 @@ func (store *Store) Import(ctx context.Context, r io.Reader) (*types.TipSet, *ty
// SetCheckpoint will set a checkpoint past which the chainstore will not allow forks. If the new
// checkpoint is not an ancestor of the current head, head will be set to the new checkpoint.
//
// NOTE: Checkpoints cannot be set beyond ForkLengthThreshold epochs in the past, but can be set
// arbitrarily far into the future.
// NOTE: The new checkpoint must already be synced.
// NOTE: Checkpoints cannot revert more than policy.Finality epochs.
func (store *Store) SetCheckpoint(ctx context.Context, ts *types.TipSet) error {
log.Infof("SetCheckPoint at %d: %v", ts.Height(), ts.Key())
buf := new(bytes.Buffer)
Expand All @@ -1113,26 +1115,57 @@ func (store *Store) SetCheckpoint(ctx context.Context, ts *types.TipSet) error {
store.mu.RLock()
defer store.mu.RUnlock()

// Otherwise, this operation could get _very_ expensive.
if store.head.Height()-ts.Height() > policy.ChainFinality {
return fmt.Errorf("cannot set a checkpoint before the fork threshold")
finality := store.head.Height() - policy.ChainFinality
targetChain, currentChain := ts, store.head

// First attempt to skip backwards to a common height using the chain index.
if targetChain.Height() > currentChain.Height() {
targetChain, err = store.GetTipSetByHeight(ctx, targetChain, currentChain.Height(), true)
} else if targetChain.Height() < currentChain.Height() {
currentChain, err = store.GetTipSetByHeight(ctx, currentChain, targetChain.Height(), true)
}
if err != nil {
return fmt.Errorf("checkpoint failed: error when finding the fork point: %w", err)
}

if !ts.Equals(store.head) {
anc, err := store.IsAncestorOf(ctx, ts, store.head)
if err != nil {
return fmt.Errorf("cannot determine whether checkpoint tipset is in main-chain: %w", err)
// Then walk backwards until either we find a common block (the fork height) or we reach
// finality. If the tipsets are _equal_ on the first pass through this loop, it means one
// chain is a prefix of the other chain because we've only walked back on one chain so far.
// In that case, we _don't_ check finality because we're not forking.
for !currentChain.Equals(targetChain) && currentChain.Height() > finality {
if currentChain.Height() >= targetChain.Height() {
currentChain, err = store.getTipSet(ctx, currentChain.Parents())
if err != nil {
return fmt.Errorf("checkpoint failed: error when walking the current chain: %w", err)
}
}

if !anc {
if err := store.setHead(ctx, ts); err != nil {
return fmt.Errorf("failed to switch chains when setting checkpoint: %w", err)
if targetChain.Height() > currentChain.Height() {
targetChain, err = store.getTipSet(ctx, targetChain.Parents())
if err != nil {
return fmt.Errorf("checkpoint failed: error when walking the target chain: %w", err)
}
}
}

// If we haven't found a common tipset by this point, we can't switch chains.
if !currentChain.Equals(targetChain) {
return fmt.Errorf("checkpoint failed: failed to find the fork point from %s (head) to %s (target) within finality",
store.head.Key(),
ts.Key(),
)
}

// If the target tipset isn't an ancestor of our current chain, we need to switch chains.
if !currentChain.Equals(ts) {
if err := store.setHead(ctx, ts); err != nil {
return fmt.Errorf("failed to switch chains when setting checkpoint: %w", err)
}
}

// Finally, set the checkpoint.
if err := store.ds.Put(ctx, CheckPoint, buf.Bytes()); err != nil {
return err
return fmt.Errorf("checkpoint failed: failed to record checkpoint in the datastore: %w", err)
}
store.checkPoint = ts.Key()

Expand All @@ -1145,17 +1178,12 @@ func (store *Store) IsAncestorOf(ctx context.Context, a, b *types.TipSet) (bool,
return false, nil
}

cur := b
for !a.Equals(cur) && cur.Height() > a.Height() {
next, err := store.GetTipSet(ctx, cur.Parents())
if err != nil {
return false, err
}

cur = next
target, err := store.GetTipSetByHeight(ctx, b, a.Height(), false)
if err != nil {
return false, err
}

return cur.Equals(a), nil
return target.Equals(a), nil
}

// GetCheckPoint get the check point from store or disk.
Expand Down
1 change: 1 addition & 0 deletions pkg/chainsync/syncer/syncer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestLoadFork(t *testing.T) {
// Load a new chain bsstore on the underlying data. It will only compute state for the
// left (heavy) branch. It has a fetcher that can't provide blocks.
newStore := chain.NewStore(builder.Repo().ChainDatastore(), builder.BlockStore(), genesis.At(0).Cid(), chainselector.Weight)
require.NoError(t, newStore.SetHead(ctx, genesis))
require.NoError(t, newStore.SetCheckpoint(ctx, genesis))
require.NoError(t, newStore.Load(ctx))
_, err = syncer.NewSyncer(stmgr,
Expand Down
3 changes: 0 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ type NetworkParamsConfig struct {
F3Enabled bool `json:"f3Enabled"`
F3BootstrapEpoch abi.ChainEpoch `json:"f3BootstrapEpoch"`
ManifestServerID string `json:"manifestServerID"`
// F3Consensus set whether F3 should checkpoint tipsets finalized by F3. This
// flag has no effect if F3 is not enabled.
F3Consensus bool `json:"f3Consensus"`
// The initial F3 power table CID.
F3InitialPowerTableCID cid.Cid `json:"f3InitialPowerTableCID"`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vf3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewManifest(
Finality: int64(finality),
DelayMultiplier: manifest.DefaultEcConfig.DelayMultiplier,
BaseDecisionBackoffTable: manifest.DefaultEcConfig.BaseDecisionBackoffTable,
HeadLookback: 0,
HeadLookback: 4,
Finalize: true,
},
CertificateExchange: manifest.CxConfig{
Expand Down
13 changes: 13 additions & 0 deletions pkg/vf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,16 @@ func (fff *F3) IsRunning() bool {
func (fff *F3) Progress() gpbft.Instant {
return fff.inner.Progress()
}

func (fff *F3) ListParticipants() []types.F3Participant {
leases := fff.leaser.getValidLeases()
participants := make([]types.F3Participant, len(leases))
for i, lease := range leases {
participants[i] = types.F3Participant{
MinerID: lease.MinerID,
FromInstance: lease.FromInstance,
ValidityTerm: lease.ValidityTerm,
}
}
return participants
}
Loading
Loading