Skip to content

Commit

Permalink
Merge pull request #6374 from filecoin-project/chore/transport
Browse files Browse the repository at this point in the history
feat:ec: integrate F3 dynamic manifest
  • Loading branch information
simlecode authored Jul 5, 2024
2 parents 7a19742 + 076f0f8 commit 5faee07
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 66 deletions.
1 change: 1 addition & 0 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ func (a *ethAPI) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (types.
)

for blocksIncluded < int(params.BlkCount) && ts.Height() > 0 {
basefee = ts.Blocks()[0].ParentBaseFee
msgs, rcpts, err := messagesAndReceipts(ctx, ts, a.em.chainModule.MessageStore, a.em.chainModule.Stmgr)
if err != nil {
return types.EthFeeHistory{}, fmt.Errorf("failed to retrieve messages and receipts for height %d: %w", ts.Height(), err)
Expand Down
1 change: 0 additions & 1 deletion app/submodule/f3/f3_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type f3API struct {
var ErrF3Disabled = errors.New("f3 is disabled")

func (f3api *f3API) F3Participate(ctx context.Context, miner address.Address) (<-chan string, error) {

if f3api.f3module.F3 == nil {
log.Infof("F3Participate called for %v, F3 is disabled", miner)
return nil, ErrF3Disabled
Expand Down
29 changes: 17 additions & 12 deletions app/submodule/f3/f3_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ type F3Submodule struct {
F3 *vf3.F3
}

func NewF3Submodule(ctx context.Context, repo repo.Repo, chain *chain.ChainSubmodule, network *network.NetworkSubmodule, walletAPI v1api.IWallet) (*F3Submodule, error) {
netconf := repo.Config().NetworkParams
if !netconf.F3Enabled {
func NewF3Submodule(ctx context.Context,
repo repo.Repo,
chain *chain.ChainSubmodule,
network *network.NetworkSubmodule,
walletAPI v1api.IWallet,
) (*F3Submodule, error) {
netConf := repo.Config().NetworkParams
if !netConf.F3Enabled {
return &F3Submodule{
F3: &vf3.F3{},
F3: nil,
}, nil
}
m, err := vf3.New(ctx, vf3.F3Params{
NetworkName: network.NetworkName,
NetworkParams: netconf,
PubSub: network.Pubsub,
Host: network.Host,
ChainStore: chain.ChainReader,
StateManager: chain.Stmgr,
Datastore: repo.ChainDatastore(),
Wallet: walletAPI,
ManifestServerID: netConf.ManifestServerID,
PubSub: network.Pubsub,
Host: network.Host,
ChainStore: chain.ChainReader,
StateManager: chain.Stmgr,
Datastore: repo.ChainDatastore(),
Wallet: walletAPI,
ManifestProvider: vf3.NewManifestProvider(network.NetworkName, chain.ChainReader, chain.Stmgr, network.Pubsub, netConf),
})
if err != nil {
return nil, err
Expand Down
5 changes: 2 additions & 3 deletions fixtures/networks/butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,17 @@ func ButterflySnapNet() *NetworkConf {
UpgradePhoenixHeight: -26,
UpgradeWaffleHeight: 100,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet},
AddressNetwork: address.Testnet,
PropagationDelaySecs: 6,
AllowableClockDriftSecs: 1,
Eip155ChainID: 3141592,
ActorDebugging: false,
F3Enabled: true,
F3BootstrapEpoch: 200,
ManifestServerID: "12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYWvBK9TC3Yn6",
},
}

nc.Network.DrandSchedule[nc.Network.ForkUpgradeParam.UpgradePhoenixHeight] = config.DrandQuicknet

return nc
}
7 changes: 4 additions & 3 deletions fixtures/networks/calibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,22 @@ func Calibration() *NetworkConf {
UpgradeWatermelonFix2Height: 1108174, // 2023-11-21T13:00:00Z
UpgradeDragonHeight: 1427974, // 2024-03-11T14:00:00Z
UpgradeCalibrationDragonFixHeight: 1493854, // 2024-04-03T11:00:00Z
UpgradeWaffleHeight: 9999999999, //
UpgradeWaffleHeight: 1779094, // 2024-07-11T12:00:00Z
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1},
AddressNetwork: address.Testnet,
PropagationDelaySecs: 10,
AllowableClockDriftSecs: 1,
Eip155ChainID: 314159,
ActorDebugging: false,
F3Enabled: false,
F3BootstrapEpoch: -1,
F3Enabled: true,
},
}

nc.Network.ForkUpgradeParam.UpgradePhoenixHeight = nc.Network.ForkUpgradeParam.UpgradeDragonHeight + 120
nc.Network.DrandSchedule[nc.Network.ForkUpgradeParam.UpgradePhoenixHeight] = config.DrandQuicknet

nc.Network.F3BootstrapEpoch = nc.Network.ForkUpgradeParam.UpgradeWaffleHeight + 100

return nc
}
4 changes: 2 additions & 2 deletions fixtures/networks/forcenet.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ func ForceNet() *NetworkConf {
UpgradePhoenixHeight: -26,
UpgradeWaffleHeight: 200,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandMainnet},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet},
AddressNetwork: address.Testnet,
PropagationDelaySecs: 1,
AllowableClockDriftSecs: 1,
Eip155ChainID: 31415926,
ActorDebugging: true,
F3Enabled: true,
F3BootstrapEpoch: 100,
ManifestServerID: "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG",
},
}
nc.Network.DrandSchedule[nc.Network.ForkUpgradeParam.UpgradePhoenixHeight] = config.DrandQuicknet

return nc
}
3 changes: 3 additions & 0 deletions fixtures/networks/integrationtestnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func IntegrationNet() *NetworkConf {
AllowableClockDriftSecs: 1,
Eip155ChainID: 314,
ActorDebugging: false,
F3Enabled: false,
F3BootstrapEpoch: -1,
ManifestServerID: "12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7",
},
}

Expand Down
5 changes: 2 additions & 3 deletions fixtures/networks/interopnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,17 @@ func InteropNet() *NetworkConf {
UpgradePhoenixHeight: -26,
UpgradeWaffleHeight: 50,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet},
AddressNetwork: address.Testnet,
PropagationDelaySecs: 6,
AllowableClockDriftSecs: 1,
Eip155ChainID: 3141592,
ActorDebugging: false,
F3Enabled: true,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWQJ2rdVnG4okDUB6yHQhAjNutGNemcM7XzqC9Eo4z9Jce",
},
}

nc.Network.DrandSchedule[nc.Network.ForkUpgradeParam.UpgradePhoenixHeight] = config.DrandQuicknet

return nc
}
1 change: 1 addition & 0 deletions fixtures/networks/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func Mainnet() *NetworkConf {
ActorDebugging: false,
F3Enabled: false,
F3BootstrapEpoch: -1,
ManifestServerID: "12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7",
},
}

Expand Down
5 changes: 2 additions & 3 deletions fixtures/networks/net_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,17 @@ func Net2k() *NetworkConf {
UpgradePhoenixHeight: -26,
UpgradeWaffleHeight: 200,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 1},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: config.DrandQuicknet},
AddressNetwork: address.Testnet,
PropagationDelaySecs: 1,
AllowableClockDriftSecs: 1,
Eip155ChainID: 31415926,
ActorDebugging: true,
F3Enabled: true,
F3BootstrapEpoch: 100,
ManifestServerID: "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG",
},
}

nc.Network.DrandSchedule[nc.Network.ForkUpgradeParam.UpgradePhoenixHeight] = config.DrandQuicknet

return nc
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/filecoin-project/go-commp-utils v0.1.3
github.com/filecoin-project/go-crypto v0.0.1
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc6
github.com/filecoin-project/go-f3 v0.0.2
github.com/filecoin-project/go-f3 v0.0.3-0.20240702063402-d48771055cf4
github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-fil-markets v1.28.2
github.com/filecoin-project/go-jsonrpc v0.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc6 h1:EsbXTWsBKT764qtX4M
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc6/go.mod h1:cX1acvFVWC5EXnnmFPWEFXbO7nLUdSZa+nqgi1QpTpw=
github.com/filecoin-project/go-ds-versioning v0.1.2 h1:to4pTadv3IeV1wvgbCbN6Vqd+fu+7tveXgv/rCEZy6w=
github.com/filecoin-project/go-ds-versioning v0.1.2/go.mod h1:C9/l9PnB1+mwPa26BBVpCjG/XQCB0yj/q5CK2J8X1I4=
github.com/filecoin-project/go-f3 v0.0.2 h1:bzw/GndxntJnUYA+WCaXwHE2qwGRwrFVo9umz3unTUs=
github.com/filecoin-project/go-f3 v0.0.2/go.mod h1:Wry0mNa8z767TBHb7N0cVb+9j00KsHbD2pzsC3li4R8=
github.com/filecoin-project/go-f3 v0.0.3-0.20240702063402-d48771055cf4 h1:eQW2fyKyMuiweuySEb/zMIc3WLSAnIOY8lpqCVQM7pU=
github.com/filecoin-project/go-f3 v0.0.3-0.20240702063402-d48771055cf4/go.mod h1:Wry0mNa8z767TBHb7N0cVb+9j00KsHbD2pzsC3li4R8=
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88OqLYEo6roi+GiIeOh8=
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ type NetworkParamsConfig struct {
ActorDebugging bool `json:"-"`
F3Enabled bool `json:"f3Enabled"`
F3BootstrapEpoch abi.ChainEpoch `json:"f3BootstrapEpoch"`
ManifestServerID string `json:"manifestServerID"`
}

// ForkUpgradeConfig record upgrade parameters
Expand Down
31 changes: 30 additions & 1 deletion pkg/net/gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net

import (
"context"
"fmt"
"net"
"time"

Expand All @@ -14,6 +15,7 @@ import (
blake2b "github.com/minio/blake2b-simd"

"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/manifest"
"github.com/filecoin-project/venus/pkg/config"
"github.com/filecoin-project/venus/venus-shared/types"
)
Expand All @@ -40,6 +42,12 @@ const (
GraylistScoreThreshold = -2500
AcceptPXScoreThreshold = 1000
OpportunisticGraftScoreThreshold = 3.5

// Determines the max. number of configuration changes
// that are allowed for the dynamic manifest.
// If the manifest changes more than this number, the F3
// message topic will be filtered
MaxDynamicManifestChangesAllowed = 1000
)

func NewGossipSub(ctx context.Context,
Expand Down Expand Up @@ -313,7 +321,28 @@ func NewGossipSub(ctx context.Context,
}
allowTopics = append(allowTopics, drandTopics...)
if f3enabled {
allowTopics = append(allowTopics, gpbft.NetworkName(networkName).PubSubTopic())
f3TopicName := manifest.PubSubTopicFromNetworkName(gpbft.NetworkName(networkName))
allowTopics = append(allowTopics, f3TopicName)

// allow dynamic manifest topic and the new topic names after a reconfiguration.
// Note: This is pretty ugly, but I tried to use a regex subscription filter
// as the commented code below, but unfortunately it overwrites previous filters. A simple fix would
// be to allow combining several topic filters, but for now this works.
//
// pattern := fmt.Sprintf(`^\/f3\/%s\/0\.0\.1\/?[0-9]*$`, in.Nn)
// rx, err := regexp.Compile(pattern)
// if err != nil {
// return nil, xerrors.Errorf("failed to compile manifest topic regex: %w", err)
// }
// options = append(options,
// pubsub.WithSubscriptionFilter(
// pubsub.WrapLimitSubscriptionFilter(
// pubsub.NewRegexpSubscriptionFilter(rx),
// 100)))
allowTopics = append(allowTopics, manifest.ManifestPubSubTopicName)
for i := 0; i < MaxDynamicManifestChangesAllowed; i++ {
allowTopics = append(allowTopics, f3TopicName+"/"+fmt.Sprintf("%d", i))
}
}
options = append(options,
pubsub.WithSubscriptionFilter(
Expand Down
15 changes: 7 additions & 8 deletions pkg/vf3/ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-f3"
"github.com/filecoin-project/go-f3/ec"
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/venus/pkg/chain"
Expand All @@ -21,7 +21,6 @@ import (
type ecWrapper struct {
ChainStore *chain.Store
StateManager *statemanger.Stmgr
Manifest f3.Manifest
}

type f3TipSet types.TipSet
Expand Down Expand Up @@ -55,7 +54,7 @@ func (ts *f3TipSet) Timestamp() time.Time {
return time.Unix(int64(ts.cast().Blocks()[0].Timestamp), 0)
}

func wrapTS(ts *types.TipSet) f3.TipSet {
func wrapTS(ts *types.TipSet) ec.TipSet {
if ts == nil {
return nil
}
Expand All @@ -64,15 +63,15 @@ func wrapTS(ts *types.TipSet) f3.TipSet {

// GetTipsetByEpoch should return a tipset before the one requested if the requested
// tipset does not exist due to null epochs
func (ec *ecWrapper) GetTipsetByEpoch(ctx context.Context, epoch int64) (f3.TipSet, error) {
func (ec *ecWrapper) GetTipsetByEpoch(ctx context.Context, epoch int64) (ec.TipSet, error) {
ts, err := ec.ChainStore.GetTipSetByHeight(ctx, nil, abi.ChainEpoch(epoch), true)
if err != nil {
return nil, xerrors.Errorf("getting tipset by height: %w", err)
}
return wrapTS(ts), nil
}

func (ec *ecWrapper) GetTipset(ctx context.Context, tsk gpbft.TipSetKey) (f3.TipSet, error) {
func (ec *ecWrapper) GetTipset(ctx context.Context, tsk gpbft.TipSetKey) (ec.TipSet, error) {
tskLotus, err := types.TipSetKeyFromBytes(tsk)
if err != nil {
return nil, xerrors.Errorf("decoding tsk: %w", err)
Expand All @@ -86,16 +85,16 @@ func (ec *ecWrapper) GetTipset(ctx context.Context, tsk gpbft.TipSetKey) (f3.Tip
return wrapTS(ts), nil
}

func (ec *ecWrapper) GetHead(_ context.Context) (f3.TipSet, error) {
func (ec *ecWrapper) GetHead(_ context.Context) (ec.TipSet, error) {
return wrapTS(ec.ChainStore.GetHead()), nil
}

func (ec *ecWrapper) GetParent(ctx context.Context, tsF3 f3.TipSet) (f3.TipSet, error) {
func (ec *ecWrapper) GetParent(ctx context.Context, tsF3 ec.TipSet) (ec.TipSet, error) {
var ts *types.TipSet
if tsW, ok := tsF3.(*f3TipSet); ok {
ts = tsW.cast()
} else {
// There are only two implementations of F3.TipSet: f3TipSet, and one in fake EC
// There are only two implementations of ec.TipSet: f3TipSet, and one in fake EC
// backend.
//
// TODO: Revisit the type check here and remove as needed once testing
Expand Down
Loading

0 comments on commit 5faee07

Please sign in to comment.