Skip to content

Commit

Permalink
move network to blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Dec 24, 2024
1 parent bdd9b61 commit 6cf99cb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
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.Subnet(CompatibleNetwork), 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.Subnet(CompatibleNetwork)
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.Subnet(CompatibleNetwork).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.Subnet(CompatibleNetwork)
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
10 changes: 2 additions & 8 deletions chainservice/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ import (
"github.com/iotexproject/iotex-core/v2/systemcontractindex/stakingindex"
)

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

var (
_blockchainFullnessMtc = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -143,7 +137,7 @@ func (cs *ChainService) HandleActionRequest(ctx context.Context, peer peer.AddrI
}
return err
}
return cs.p2pAgent.Subnet(CompatibleNetwork).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 @@ -226,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.Subnet(CompatibleNetwork)
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
10 changes: 5 additions & 5 deletions e2etest/local_actpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/iotexproject/go-pkgs/crypto"

"github.com/iotexproject/iotex-core/v2/action"
"github.com/iotexproject/iotex-core/v2/chainservice"
"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 @@ -60,8 +60,8 @@ func TestLocalActPool(t *testing.T) {
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {

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

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

Expand Down
9 changes: 4 additions & 5 deletions e2etest/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/iotexproject/iotex-core/v2/blockchain/blockdao"
"github.com/iotexproject/iotex-core/v2/blockchain/filedao"
"github.com/iotexproject/iotex-core/v2/blockchain/genesis"
"github.com/iotexproject/iotex-core/v2/chainservice"
"github.com/iotexproject/iotex-core/v2/config"
"github.com/iotexproject/iotex-core/v2/db"
"github.com/iotexproject/iotex-core/v2/p2p"
Expand Down Expand Up @@ -126,8 +125,8 @@ func TestLocalCommit(t *testing.T) {
},
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {
},
p2p.JoinSubnet(chainservice.CompatibleNetwork),
).Subnet(chainservice.CompatibleNetwork)
p2p.JoinSubnet(blockchain.CompatibleNetwork),
).Subnet(blockchain.CompatibleNetwork)
require.NotNil(p)
require.NoError(p.Start(ctx))
defer func() {
Expand Down Expand Up @@ -332,7 +331,7 @@ func TestLocalSync(t *testing.T) {
hash.ZeroHash256,
func(_ context.Context, _ uint32, _ string, msg proto.Message) {},
func(_ context.Context, _ uint32, _ peer.AddrInfo, _ proto.Message) {},
p2p.JoinSubnet(chainservice.CompatibleNetwork),
p2p.JoinSubnet(blockchain.CompatibleNetwork),
)
require.NoError(bootnode.Start(ctx))
addrs, err := bootnode.Self()
Expand Down Expand Up @@ -408,7 +407,7 @@ func TestLocalSync(t *testing.T) {
}()

err = testutil.WaitUntil(time.Millisecond*100, time.Second*60, func() (bool, error) {
peers, err := svr.P2PAgent().Subnet(chainservice.CompatibleNetwork).ConnectedPeers()
peers, err := svr.P2PAgent().Subnet(blockchain.CompatibleNetwork).ConnectedPeers()
return len(peers) >= 1, err
})
require.NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion server/itx/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go.uber.org/zap"

"github.com/iotexproject/iotex-core/v2/api"
"github.com/iotexproject/iotex-core/v2/blockchain"
"github.com/iotexproject/iotex-core/v2/chainservice"
"github.com/iotexproject/iotex-core/v2/config"
"github.com/iotexproject/iotex-core/v2/dispatcher"
Expand Down Expand Up @@ -65,7 +66,7 @@ func newServer(cfg config.Config, testing bool) (*Server, error) {
case config.StandaloneScheme:
p2pAgent = p2p.NewDummyAgent()
default:
p2pAgent = p2p.NewAgent(cfg.Network, cfg.Chain.ID, cfg.Genesis.Hash(), dispatcher.HandleBroadcast, dispatcher.HandleTell, p2p.JoinSubnet(chainservice.CompatibleNetwork))
p2pAgent = p2p.NewAgent(cfg.Network, cfg.Chain.ID, cfg.Genesis.Hash(), dispatcher.HandleBroadcast, dispatcher.HandleTell, p2p.JoinSubnet(blockchain.CompatibleNetwork))
}
chains := make(map[uint32]*chainservice.ChainService)
apiServers := make(map[uint32]*api.ServerV2)
Expand Down

0 comments on commit 6cf99cb

Please sign in to comment.