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

[p2p] support network separation #3817

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion action/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ func (log *Log) ConvertToLogPb() *iotextypes.Log {
l := &iotextypes.Log{}
l.ContractAddress = log.Address
l.Topics = [][]byte{}
var shareTopic hash.Hash256
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with #4532

for _, topic := range log.Topics {
shareTopic = topic
if log.NotFixTopicCopyBug {
l.Topics = append(l.Topics, topic[:])
l.Topics = append(l.Topics, shareTopic[:])
} else {
data := make([]byte, len(topic))
copy(data, topic[:])
Expand Down
6 changes: 6 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const (
SigP256sm2 = "p256sm2"
)

// Message networks definition
const (
// CompatiableNetwork is the network for connecting to the nodes without message network feature
CompatibleNetwork = ""
)

var (
_blockMtc = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down
8 changes: 4 additions & 4 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (builder *Builder) buildNodeInfoManager() error {
return errors.New("cannot find staking protocol")
}
chain := builder.cs.chain
dm := nodeinfo.NewInfoManager(&builder.cfg.NodeInfo, cs.p2pAgent, cs.chain, builder.cfg.Chain.ProducerPrivateKey(), func() []string {
dm := nodeinfo.NewInfoManager(&builder.cfg.NodeInfo, cs.p2pAgent.Subnet(blockchain.CompatibleNetwork), cs.chain, builder.cfg.Chain.ProducerPrivateKey(), func() []string {
ctx := protocol.WithFeatureCtx(
protocol.WithBlockCtx(
genesis.WithGenesisContext(context.Background(), chain.Genesis()),
Expand Down Expand Up @@ -552,7 +552,7 @@ func (builder *Builder) buildBlockSyncer() error {
return nil
}

p2pAgent := builder.cs.p2pAgent
p2pAgent := builder.cs.p2pAgent.Subnet(blockchain.CompatibleNetwork)
chain := builder.cs.chain
consens := builder.cs.consensus
dao := builder.cs.blockdao
Expand Down Expand Up @@ -647,7 +647,7 @@ func (builder *Builder) buildActionSyncer() error {
p2pAgent := builder.cs.p2pAgent
actionsync := actsync.NewActionSync(builder.cfg.ActionSync, &actsync.Helper{
P2PNeighbor: p2pAgent.ConnectedPeers,
UnicastOutbound: p2pAgent.UnicastOutbound,
UnicastOutbound: p2pAgent.Subnet(blockchain.CompatibleNetwork).UnicastOutbound,
})
builder.cs.actionsync = actionsync
builder.cs.lifecycle.Add(actionsync)
Expand Down Expand Up @@ -787,7 +787,7 @@ func (builder *Builder) buildBlockTimeCalculator() (err error) {
}

func (builder *Builder) buildConsensusComponent() error {
p2pAgent := builder.cs.p2pAgent
p2pAgent := builder.cs.p2pAgent.Subnet(blockchain.CompatibleNetwork)
copts := []consensus.Option{
consensus.WithBroadcast(func(msg proto.Message) error {
return p2pAgent.BroadcastOutbound(context.Background(), msg)
Expand Down
4 changes: 2 additions & 2 deletions chainservice/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (cs *ChainService) HandleActionRequest(ctx context.Context, peer peer.AddrI
}
return err
}
return cs.p2pAgent.UnicastOutbound(ctx, peer, act.Proto())
return cs.p2pAgent.Subnet(blockchain.CompatibleNetwork).UnicastOutbound(ctx, peer, act.Proto())
}

// HandleBlock handles incoming block request.
Expand Down Expand Up @@ -220,7 +220,7 @@ func (cs *ChainService) NewAPIServer(cfg api.Config, plugins map[int]interface{}
if cfg.GRPCPort == 0 && cfg.HTTPPort == 0 {
return nil, nil
}
p2pAgent := cs.p2pAgent
p2pAgent := cs.p2pAgent.Subnet(blockchain.CompatibleNetwork)
apiServerOptions := []api.Option{
api.WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error {
return p2pAgent.BroadcastOutbound(ctx, msg)
Expand Down
7 changes: 5 additions & 2 deletions e2etest/local_actpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/iotexproject/go-pkgs/crypto"

"github.com/iotexproject/iotex-core/v2/action"
"github.com/iotexproject/iotex-core/v2/blockchain"
"github.com/iotexproject/iotex-core/v2/config"
"github.com/iotexproject/iotex-core/v2/p2p"
"github.com/iotexproject/iotex-core/v2/server/itx"
Expand Down Expand Up @@ -59,7 +60,8 @@ func TestLocalActPool(t *testing.T) {
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {

},
)
p2p.JoinSubnet(blockchain.CompatibleNetwork),
).Subnet(blockchain.CompatibleNetwork)
require.NotNil(cli)
require.NoError(cli.Start(ctx))
fmt.Println("p2p agent started")
Expand Down Expand Up @@ -137,7 +139,8 @@ func TestPressureActPool(t *testing.T) {
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {

},
)
p2p.JoinSubnet(blockchain.CompatibleNetwork),
).Subnet(blockchain.CompatibleNetwork)
require.NotNil(cli)
require.NoError(cli.Start(ctx))

Expand Down
9 changes: 6 additions & 3 deletions e2etest/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ func TestLocalCommit(t *testing.T) {
},
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {
},
)
p2p.JoinSubnet(blockchain.CompatibleNetwork),
).Subnet(blockchain.CompatibleNetwork)
require.NotNil(p)
require.NoError(p.Start(ctx))
defer func() {
Expand Down Expand Up @@ -329,7 +330,9 @@ func TestLocalSync(t *testing.T) {
cfg.Chain.ID,
hash.ZeroHash256,
func(_ context.Context, _ uint32, _ string, msg proto.Message) {},
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {})
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {},
p2p.JoinSubnet(blockchain.CompatibleNetwork),
)
require.NoError(bootnode.Start(ctx))
addrs, err := bootnode.Self()
require.NoError(err)
Expand Down Expand Up @@ -404,7 +407,7 @@ func TestLocalSync(t *testing.T) {
}()

err = testutil.WaitUntil(time.Millisecond*100, time.Second*60, func() (bool, error) {
peers, err := svr.P2PAgent().ConnectedPeers()
peers, err := svr.P2PAgent().Subnet(blockchain.CompatibleNetwork).ConnectedPeers()
return len(peers) >= 1, err
})
require.NoError(err)
Expand Down
63 changes: 33 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/iotexproject/iotex-core/v2

go 1.21
go 1.23.3

require (
github.com/agiledragon/gomonkey/v2 v2.11.0
Expand Down Expand Up @@ -42,29 +42,29 @@ require (
github.com/schollz/progressbar/v2 v2.15.0
github.com/shirou/gopsutil/v3 v3.22.8
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/tidwall/gjson v1.11.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/uptrace/opentelemetry-go-extra/otelzap v0.2.2
go.elastic.co/ecszap v1.0.0
go.etcd.io/bbolt v1.3.6
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
go.opentelemetry.io/otel/trace v1.33.0
go.uber.org/automaxprocs v1.5.2
go.uber.org/config v1.3.1
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.25.0
golang.org/x/crypto v0.30.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/net v0.27.0
golang.org/x/sync v0.7.0
golang.org/x/text v0.16.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
golang.org/x/net v0.32.0
golang.org/x/sync v0.10.0
golang.org/x/text v0.21.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576
google.golang.org/grpc v1.68.1
google.golang.org/protobuf v1.35.2
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -86,9 +86,11 @@ require (
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
Expand All @@ -101,14 +103,25 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.39.4 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/supranational/blst v0.3.11 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/fx v1.20.1 // indirect
go.uber.org/mock v0.3.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Expand All @@ -125,11 +138,9 @@ require (
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustinxie/gmsm v1.4.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down Expand Up @@ -196,26 +207,16 @@ require (
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.39.4 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand All @@ -230,11 +231,11 @@ require (
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/time v0.6.0
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -245,3 +246,5 @@ require (
replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v0.5.0

replace golang.org/x/xerrors => golang.org/x/xerrors v0.0.0-20190212162355-a5947ffaace3

replace github.com/iotexproject/go-p2p => github.com/envestcc/go-p2p v0.0.0-20241224005618-3ebca52e6a3a
Loading
Loading