Skip to content

Commit

Permalink
fix legacy network port args
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Feb 12, 2024
1 parent e1356de commit b6e712e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
36 changes: 36 additions & 0 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@ value-log-gc = true
# the max levels can not be decreased once up, so be cautious
max-compaction-levels = 7

# this is the old network configuration, should be deprecated
[network]
# the public endpoint to receive peer packets, may be a proxy or load balancer
# must be a public reachable domain or IP, and the port allowed by firewall
listener = "mixin-node.example.com:7239"
# the nodes list
peers = [
"new-mixin-node0.exinpool.com:7239",
"new-mixin-node1.exinpool.com:7239",
"new-mixin-node2.exinpool.com:7239",
"new-mixin-node3.exinpool.com:7239",
"mixin-node-lehigh-1.hotot.org:7239",
"mixin-node-lehigh-2.hotot.org:7239",
"mixin-node-42.f1ex.io:7239",
"mixin-node-fes.f1ex.io:7239",
"mixin-node-box-1.b.watch:7239",
"mixin-node-box-2.b.watch:7239",
"mixin-node-box-3.b.watch:7239",
"mixin-node-box-4.b.watch:7239",
"mixin-node-okashi.mixin.fan:7239",
"mixin-node1.b1.run:7239",
"mixin-node2.b1.run:7239",
"mixin-node3.b1.run:7239",
"mixin-node4.b1.run:7239",
"mixin-node6.b1.run:7239",
"mixin-node7.b1.run:7239",
"mixin-node8b.b1.run:7239",
"34.42.197.136:7239",
"13.51.72.77:7239",
"3.227.254.217:7239",
"44.197.199.140:7239",
"16.170.250.120:7239",
"13.51.169.35:7239",
"43.206.154.20:7239"
]

[p2p]
# the UDP port for communcation with other nodes
port = 5850
Expand Down
2 changes: 1 addition & 1 deletion kernel/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func setupTestNode(require *require.Assertions, dir string) *Node {
store, err := storage.NewBadgerStore(custom, dir)
require.Nil(err)
require.NotNil(store)
node, err := SetupNode(custom, store, cache, ":7239", dir)
node, err := SetupNode(custom, store, cache, 7239, dir)
require.Nil(err)
require.Equal(mainnetId, node.networkId.String())
return node
Expand Down
24 changes: 12 additions & 12 deletions kernel/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type Node struct {
Signer common.Address
isRelayer bool

Listener string
// FIXME deprecate these
LegacyAddr string
LegacyPeer *network.Peer
LegacySyncPoints *legacySyncMap
LegacySyncPointsMap map[crypto.Hash]*network.SyncPoint
Expand Down Expand Up @@ -54,7 +55,6 @@ type Node struct {
cacheStore *ristretto.Cache
custom *config.Custom
configDir string
addr string

done chan struct{}
elc chan struct{}
Expand All @@ -77,17 +77,17 @@ type CNode struct {
ConsensusIndex int
}

func SetupNode(custom *config.Custom, persistStore storage.Store, cacheStore *ristretto.Cache, addr, dir string) (*Node, error) {
var node = &Node{
func SetupNode(custom *config.Custom, persistStore storage.Store, cacheStore *ristretto.Cache, legacyPort int, dir string) (*Node, error) {
node := &Node{
SyncPoints: &syncMap{mutex: new(sync.RWMutex), m: make(map[crypto.Hash]*p2p.SyncPoint)},
LegacySyncPoints: &legacySyncMap{mutex: new(sync.RWMutex), m: make(map[crypto.Hash]*network.SyncPoint)},
LegacyAddr: fmt.Sprintf(":%d", legacyPort),
chains: &chainsMap{m: make(map[crypto.Hash]*Chain)},
genesisNodesMap: make(map[crypto.Hash]bool),
persistStore: persistStore,
cacheStore: cacheStore,
custom: custom,
configDir: dir,
addr: addr,
startAt: clock.Now(),
done: make(chan struct{}),
elc: make(chan struct{}),
Expand Down Expand Up @@ -131,7 +131,7 @@ func SetupNode(custom *config.Custom, persistStore storage.Store, cacheStore *ri
}
node.chain = node.BootChain(node.IdForNetwork)

logger.Printf("Listen:\t%s\n", addr)
logger.Printf("Listen:\t%d\n", node.custom.P2P.Port)
logger.Printf("Signer:\t%s\n", node.Signer.String())
logger.Printf("Network:\t%s\n", node.networkId.String())
logger.Printf("Node Id:\t%s\n", node.IdForNetwork.String())
Expand All @@ -147,7 +147,6 @@ func (node *Node) loadNodeConfig() {
addr.PublicViewKey = addr.PrivateViewKey.Public()
node.Signer = addr
node.isRelayer = node.custom.P2P.Relayer
node.Listener = node.custom.LegacyNetwork.Listener
}

func (node *Node) buildNodeStateSequences(allNodesSortedWithState []*CNode, acceptedOnly bool) []*NodeStateSequence {
Expand Down Expand Up @@ -342,7 +341,8 @@ func (node *Node) NewTransaction(assetId crypto.Hash) *common.Transaction {
}

func (node *Node) addRelayersFromConfig() error {
node.Peer = p2p.NewPeer(node, node.IdForNetwork, node.addr, node.isRelayer)
addr := fmt.Sprintf(":%d", node.custom.P2P.Port)
node.Peer = p2p.NewPeer(node, node.IdForNetwork, addr, node.isRelayer)

for _, s := range node.custom.P2P.Seeds {
parts := strings.Split(s, "@")
Expand Down Expand Up @@ -426,10 +426,10 @@ func (node *Node) AuthenticateAs(recipientId crypto.Hash, msg []byte, timeoutSec
}

func (node *Node) PingNeighborsFromConfig() error {
node.LegacyPeer = network.NewPeer(node, node.IdForNetwork, node.addr, true, true)
node.LegacyPeer = network.NewPeer(node, node.IdForNetwork, node.LegacyAddr, true, true)

for _, s := range node.custom.LegacyNetwork.Peers {
if s == node.Listener {
if s == node.custom.LegacyNetwork.Listener {
continue
}
node.LegacyPeer.PingNeighbor(s)
Expand All @@ -439,7 +439,7 @@ func (node *Node) PingNeighborsFromConfig() error {

func (node *Node) UpdateNeighbors(neighbors []string) error {
for _, in := range neighbors {
if in == node.Listener {
if in == node.custom.LegacyNetwork.Listener {
continue
}
node.LegacyPeer.PingNeighbor(in)
Expand Down Expand Up @@ -526,7 +526,7 @@ func (node *Node) BuildLegacyAuthenticationMessage() []byte {
dh := crypto.Blake3Hash(data)
sig := node.Signer.PrivateSpendKey.Sign(dh)
data = append(data, sig[:]...)
return append(data, []byte(node.Listener)...)
return append(data, []byte(node.custom.LegacyNetwork.Listener)...)
}

func (node *Node) Authenticate(msg []byte) (crypto.Hash, string, error) {
Expand Down
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func main() {
Aliases: []string{"d"},
Usage: "the data directory",
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Value: 7239,
Usage: "the peer port to listen",
},
&cli.IntFlag{
Name: "log",
Aliases: []string{"l"},
Expand Down Expand Up @@ -671,8 +677,7 @@ func kernelCmd(c *cli.Context) error {
}
defer store.Close()

addr := fmt.Sprintf(":%d", custom.P2P.Port)
node, err := kernel.SetupNode(custom, store, cache, addr, c.String("dir"))
node, err := kernel.SetupNode(custom, store, cache, c.Int("port"), c.String("dir"))
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions rpc/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func testConsensus(t *testing.T, withRelayers bool) {
if i == 0 {
kernel.TestMockDiff(epoch.Sub(time.Now()))
}
node, err := kernel.SetupNode(custom, store, cache, fmt.Sprintf(":170%02d", i+1), dir)
node, err := kernel.SetupNode(custom, store, cache, 0, dir)
require.Nil(err)
require.NotNil(node)
instances = append(instances, node)
Expand Down Expand Up @@ -643,7 +643,7 @@ func testPledgeNewNode(t *testing.T, nodes []*Node, domain common.Address, genes
store, err := storage.NewBadgerStore(custom, dir)
require.Nil(err)
require.NotNil(store)
pnode, err := kernel.SetupNode(custom, store, cache, fmt.Sprintf(":170%02d", 99), dir)
pnode, err := kernel.SetupNode(custom, store, cache, 0, dir)
require.Nil(err)
require.NotNil(pnode)
go pnode.Loop()
Expand Down Expand Up @@ -830,7 +830,7 @@ func setupTestNet(root string, withRelayers bool) ([]common.Address, []common.Ad
custom, _ := config.Initialize(dir + "/config.toml")
cache := newCache(custom)
store, _ := storage.NewBadgerStore(custom, dir)
node, _ := kernel.SetupNode(custom, store, cache, fmt.Sprintf(":160%02d", i+1), dir)
node, _ := kernel.SetupNode(custom, store, cache, 0, dir)
go node.Loop()
}
}
Expand Down

0 comments on commit b6e712e

Please sign in to comment.