Skip to content

Commit

Permalink
Merge pull request #6383 from filecoin-project/chore/transport
Browse files Browse the repository at this point in the history
Chore/transport
  • Loading branch information
LinZexiao authored Jul 30, 2024
2 parents 87dcb28 + f3a9a75 commit ccd6e42
Show file tree
Hide file tree
Showing 47 changed files with 1,002 additions and 800 deletions.
3 changes: 1 addition & 2 deletions app/node/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/filecoin-project/venus/app/submodule/storagenetworking"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/api/f3"
)

// Env is the environment for command API handlers.
Expand All @@ -27,7 +26,7 @@ type Env struct {
PaychAPI v1api.IPaychan
CommonAPI v1api.ICommon
EthAPI v1api.IETH
F3API f3.F3
F3API v1api.IF3
}

var _ cmds.Environment = (*Env)(nil)
Expand Down
2 changes: 1 addition & 1 deletion app/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (node *Node) runRestfulAPI(ctx context.Context, handler *http.ServeMux, roo
return nil
}

func (node *Node) runJsonrpcAPI(ctx context.Context, handler *http.ServeMux) error { // nolint
func (node *Node) runJsonrpcAPI(_ context.Context, handler *http.ServeMux) error { // nolint
handler.Handle("/rpc/v0", node.jsonRPCService)
handler.Handle("/rpc/v1", node.jsonRPCServiceV1)
return nil
Expand Down
16 changes: 13 additions & 3 deletions app/node/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/venus/app/submodule/actorevent"
"github.com/filecoin-project/venus/app/submodule/eth"
"github.com/filecoin-project/venus/app/submodule/f3"
v0api "github.com/filecoin-project/venus/venus-shared/api/chain/v0"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/api/permission"
Expand Down Expand Up @@ -40,16 +41,25 @@ func (builder *RPCBuilder) AddServices(services ...RPCService) error {
return nil
}

var ethSubModuleTyp = reflect.TypeOf(&eth.EthSubModule{}).Elem()
var actorEventSubModuleTyp = reflect.TypeOf(&actorevent.ActorEventSubModule{}).Elem()
var skipList = []reflect.Type{
reflect.TypeOf(&eth.EthSubModule{}).Elem(),
reflect.TypeOf(&actorevent.ActorEventSubModule{}).Elem(),
reflect.TypeOf(&f3.F3Submodule{}).Elem(),
}

func skipV0API(in interface{}) bool {
inT := reflect.TypeOf(in)
if inT.Kind() == reflect.Pointer {
inT = inT.Elem()
}

return inT.AssignableTo(ethSubModuleTyp) || inT.AssignableTo(actorEventSubModuleTyp)
for _, t := range skipList {
if inT.AssignableTo(t) {
return true
}
}

return false
}

func (builder *RPCBuilder) AddV0API(service RPCService) error {
Expand Down
2 changes: 1 addition & 1 deletion app/node/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/filecoin-project/go-jsonrpc"
tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags"
"github.com/filecoin-project/venus/venus-shared/api/permission"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/assert"
)

func TestWsBuilder(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion app/submodule/eth/eth_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func decodeCreateViaEAM(et *types.ExecutionTrace) (initcode []byte, addr *types.
}
ret, err := decodeReturn[eam12.CreateReturn](&et.MsgRct)
if err != nil {
return nil, (*types.EthAddress)(&ret.EthAddress), err
return nil, nil, err
}
return initcode, (*types.EthAddress)(&ret.EthAddress), nil
}
Expand Down
49 changes: 35 additions & 14 deletions app/submodule/f3/f3_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,46 @@ package f3
import (
"context"
"errors"
"fmt"
"time"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-f3/certs"
"github.com/filecoin-project/venus/venus-shared/api/f3"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-f3/gpbft"
v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/types"
)

var _ f3.F3 = &f3API{}
var _ v1.IF3 = &f3API{}

type f3API struct {
f3module *F3Submodule
}

var ErrF3Disabled = errors.New("f3 is disabled")

func (f3api *f3API) F3Participate(ctx context.Context, miner address.Address) (<-chan string, error) {
func (f3api *f3API) F3Participate(ctx context.Context,
minerAddr address.Address,
newLeaseExpiration time.Time,
oldLeaseExpiration time.Time,
) (bool, error) {
if f3api.f3module.F3 == nil {
log.Infof("F3Participate called for %v, F3 is disabled", miner)
return nil, ErrF3Disabled
log.Infof("F3Participate called for %v, F3 is disabled", minerAddr)
return false, ErrF3Disabled
}

// Make channel with some buffer to avoid blocking under higher load.
errCh := make(chan string, 4)
log.Infof("starting F3 participation for %v", miner)
if leaseDuration := time.Until(newLeaseExpiration); leaseDuration > 5*time.Minute {
return false, fmt.Errorf("F3 participation lease too long: %v > 5 min", leaseDuration)
} else if leaseDuration < 0 {
return false, fmt.Errorf("F3 participation lease is in the past: %d < 0", leaseDuration)
}

actorID, err := address.IDFromAddress(miner)
minerID, err := address.IDFromAddress(minerAddr)
if err != nil {
return nil, xerrors.Errorf("miner address in F3Participate not of ID type: %w", err)
return false, fmt.Errorf("miner address is not of ID type: %v: %w", minerID, err)
}

// Participate takes control of closing the channel
go f3api.f3module.F3.Participate(ctx, actorID, errCh)
return errCh, nil
return f3api.f3module.F3.Participate(ctx, minerID, newLeaseExpiration, oldLeaseExpiration), nil
}

func (f3api *f3API) F3GetCertificate(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error) {
Expand All @@ -51,3 +58,17 @@ func (f3api *f3API) F3GetLatestCertificate(ctx context.Context) (*certs.Finality
}
return f3api.f3module.F3.GetLatestCert(ctx)
}

func (f3api *f3API) F3GetECPowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error) {
if f3api.f3module.F3 == nil {
return nil, ErrF3Disabled
}
return f3api.f3module.F3.GetPowerTable(ctx, tsk)
}

func (f3api *f3API) F3GetF3PowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error) {
if f3api.f3module.F3 == nil {
return nil, ErrF3Disabled
}
return f3api.f3module.F3.GetF3PowerTable(ctx, tsk)
}
13 changes: 3 additions & 10 deletions app/submodule/f3/f3_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/filecoin-project/venus/pkg/repo"
"github.com/filecoin-project/venus/pkg/vf3"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/api/f3"
logging "github.com/ipfs/go-log"
)

Expand Down Expand Up @@ -36,9 +35,9 @@ func NewF3Submodule(ctx context.Context,
Host: network.Host,
ChainStore: chain.ChainReader,
StateManager: chain.Stmgr,
Datastore: repo.ChainDatastore(),
Datastore: repo.MetaDatastore(),
Wallet: walletAPI,
ManifestProvider: vf3.NewManifestProvider(network.NetworkName, chain.ChainReader, chain.Stmgr, network.Pubsub, netConf),
ManifestProvider: vf3.NewManifestProvider(network.NetworkName, repo.MetaDatastore(), network.Pubsub, netConf),
})
if err != nil {
return nil, err
Expand All @@ -47,13 +46,7 @@ func NewF3Submodule(ctx context.Context,
return &F3Submodule{m}, nil
}

func (m *F3Submodule) API() f3.F3 {
return &f3API{
f3module: m,
}
}

func (m *F3Submodule) V0API() f3.F3 {
func (m *F3Submodule) API() v1api.IF3 {
return &f3API{
f3module: m,
}
Expand Down
Binary file modified fixtures/assets/genesis-car/butterflynet.car
Binary file not shown.
6 changes: 3 additions & 3 deletions fixtures/networks/butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func ButterflySnapNet() *NetworkConf {
nc := &NetworkConf{
Bootstrap: config.BootstrapConfig{
Addresses: []string{
"/dns4/bootstrap-0.butterfly.fildev.network/tcp/1347/p2p/12D3KooWE9GZUna2UpMMtcCcpmSwiEB7jcKse8gixzwVomgbQysC",
"/dns4/bootstrap-1.butterfly.fildev.network/tcp/1347/p2p/12D3KooWJGtqGX2XBssujaMn3FsybJu1xJhFZzhVjNnWvC6a26iG",
"/dns4/bootstrap-0.butterfly.fildev.network/tcp/1347/p2p/12D3KooWGW6xMTpjEBqndYkqytbu8PWfJmpK4wKLLLNSkXL2QZtD",
"/dns4/bootstrap-1.butterfly.fildev.network/tcp/1347/p2p/12D3KooWFGz9HegR3Rjrtm8b9WXTM6E3kN1sdd6X1JztuCgQaZSB",
},
Period: "30s",
},
Expand Down Expand Up @@ -70,7 +70,7 @@ func ButterflySnapNet() *NetworkConf {
Eip155ChainID: 3141592,
ActorDebugging: false,
F3Enabled: true,
F3BootstrapEpoch: 200,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYWvBK9TC3Yn6",
},
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/networks/integrationtestnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func IntegrationNet() *NetworkConf {
UpgradeWatermelonFix2Height: -101, // This fix upgrade only ran on calibrationnet
UpgradeDragonHeight: 3855360,
UpgradeCalibrationDragonFixHeight: -102, // This fix upgrade only ran on calibrationnet
UpgradeWaffleHeight: 9999999999999,
UpgradeWaffleHeight: 4154640,
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 5, 51000: 1},
AddressNetwork: address.Testnet,
Expand Down
4 changes: 2 additions & 2 deletions fixtures/networks/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func Mainnet() *NetworkConf {
UpgradeWatermelonFix2Height: -101, // This fix upgrade only ran on calibrationnet
UpgradeDragonHeight: 3855360, // 2024-04-24T14:00:00Z
UpgradeCalibrationDragonFixHeight: -102, // This fix upgrade only ran on calibrationnet
UpgradeWaffleHeight: 999999999999, //
UpgradeWaffleHeight: 4154640, // 2024-08-06T12:00:00Z
},
DrandSchedule: map[abi.ChainEpoch]config.DrandEnum{0: 5, 51000: 1},
AddressNetwork: address.Mainnet,
PropagationDelaySecs: 10,
AllowableClockDriftSecs: 1,
Eip155ChainID: 314,
ActorDebugging: false,
F3Enabled: false,
F3Enabled: true,
F3BootstrapEpoch: -1,
ManifestServerID: "12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7",
},
Expand Down
2 changes: 1 addition & 1 deletion fixtures/networks/net_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Net2k() *NetworkConf {
Eip155ChainID: 31415926,
ActorDebugging: true,
F3Enabled: true,
F3BootstrapEpoch: 100,
F3BootstrapEpoch: 1000,
ManifestServerID: "12D3KooWHcNBkqXEBrsjoveQvj6zDF3vK5S9tAfqyYaQF1LGSJwG",
},
}
Expand Down
51 changes: 27 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ 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.3-0.20240702063402-d48771055cf4
github.com/filecoin-project/go-f3 v0.0.7
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
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.14.0-rc5
github.com/filecoin-project/go-state-types v0.14.0
github.com/filecoin-project/pubsub v1.0.0
github.com/filecoin-project/specs-actors v0.9.15
github.com/filecoin-project/specs-actors/v2 v2.3.6
Expand All @@ -49,14 +49,14 @@ require (
github.com/golang/mock v1.6.0
github.com/google/go-github v17.0.0+incompatible
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.1
github.com/gorilla/websocket v1.5.3
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru/arc/v2 v2.0.7
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/ipfs-force-community/metrics v1.0.1-0.20231207081445-30178e706d09
github.com/ipfs-force-community/metrics v1.0.1-0.20240725062356-39b286636574
github.com/ipfs-force-community/sophon-auth v1.16.0-rc1
github.com/ipfs/boxo v0.20.0
github.com/ipfs/go-cid v0.4.1
Expand All @@ -77,7 +77,7 @@ require (
github.com/ipld/go-car/v2 v2.13.1
github.com/ipni/go-libipni v0.0.7
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-libp2p v0.35.0
github.com/libp2p/go-libp2p v0.35.4
github.com/libp2p/go-libp2p-kad-dht v0.25.2
github.com/libp2p/go-libp2p-pubsub v0.11.0
github.com/libp2p/go-msgio v0.3.0
Expand All @@ -99,15 +99,16 @@ require (
github.com/whyrusleeping/go-sysinfo v0.0.0-20190219211824-4a357d4b90b1
github.com/zyedidia/generic v1.2.1
go.opencensus.io v0.24.0
go.opentelemetry.io/otel/bridge/opencensus v0.39.0
go.opentelemetry.io/otel/bridge/opencensus v1.28.0
go.opentelemetry.io/otel/exporters/jaeger v1.14.0
go.opentelemetry.io/otel/sdk v1.26.0
go.opentelemetry.io/otel/exporters/prometheus v0.50.0
go.opentelemetry.io/otel/sdk v1.28.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.23.0
golang.org/x/net v0.25.0
golang.org/x/oauth2 v0.20.0
golang.org/x/crypto v0.24.0
golang.org/x/net v0.26.0
golang.org/x/oauth2 v0.21.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/sys v0.21.0
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
gopkg.in/cheggaaa/pb.v1 v1.0.28
gorm.io/driver/mysql v1.1.1
Expand All @@ -117,6 +118,7 @@ require (

require (
github.com/Kubuxu/go-broadcast v0.0.0-20240621161059-1a8c90734cd6 // indirect
github.com/filecoin-project/go-clock v0.1.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/ipfs/go-blockservice v0.5.2 // indirect
github.com/ipfs/go-ipfs-blockstore v1.3.1 // indirect
Expand All @@ -125,10 +127,11 @@ require (
github.com/ipfs/go-ipfs-exchange-interface v0.2.1 // indirect
github.com/ipfs/go-merkledag v0.11.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.3 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
github.com/pion/datachannel v1.5.6 // indirect
github.com/pion/dtls/v2 v2.2.11 // indirect
github.com/pion/ice/v2 v2.3.24 // indirect
github.com/pion/ice/v2 v2.3.25 // indirect
github.com/pion/interceptor v0.1.29 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.12 // indirect
Expand Down Expand Up @@ -195,7 +198,7 @@ require (
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand Down Expand Up @@ -292,8 +295,8 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/statsd_exporter v0.23.0 // indirect
github.com/puzpuzpuz/xsync/v2 v2.4.1
github.com/quic-go/qpack v0.4.0 // indirect
Expand All @@ -320,25 +323,25 @@ require (
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
go.opentelemetry.io/otel v1.26.0
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.39.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/fx v1.21.1 // indirect
go.uber.org/fx v1.22.1 // indirect
go.uber.org/multierr v1.11.0
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/api v0.81.0 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit ccd6e42

Please sign in to comment.