Skip to content

Commit

Permalink
p2psim: Remove start flag of p2psim node create
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhv0212 committed Dec 25, 2024
1 parent 455e285 commit fb68f6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
37 changes: 16 additions & 21 deletions cmd/p2psim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ func main() {
Value: "",
Usage: "node private key (hex encoded)",
},
&cli.BoolFlag{
Name: "start",
Value: true,
Usage: "start the node after creating successfully",
},
&cli.BoolFlag{
Name: "autofill.bootnodes",
Value: true,
Expand Down Expand Up @@ -458,15 +453,6 @@ func createNode(ctx *cli.Context) error {
return err
}
fmt.Fprintln(ctx.App.Writer, "Created", node.Name)

// Start node if needed
if ctx.Bool("start") {
if err := client.StartNode(node.Name); err != nil {
return err
}
fmt.Fprintln(ctx.App.Writer, "Started", node.Name)
}

return nil
}

Expand Down Expand Up @@ -567,14 +553,23 @@ func createMultiNode(ctx *cli.Context) error {
}
ctx.Set("name", nodeName)
for {
if err := createNode(ctx); err != nil {
fmt.Fprintln(ctx.App.Writer, "Failed to create node", nodeName, err)
// Try to create the node again
client.DeleteNode(nodeName)
time.Sleep(500 * time.Millisecond)
} else {
break
err := createNode(ctx)
if err == nil {
// Start node if needed
if ctx.Bool("start") {
err = client.StartNode(nodeName)
if err == nil {
fmt.Fprintln(ctx.App.Writer, "Started", nodeName)
break
}
}
}

fmt.Fprintln(ctx.App.Writer, "Failed to create node, retrying...", nodeName, err)
// Try to create the node again
client.DeleteNode(nodeName)
time.Sleep(500 * time.Millisecond)

}
if createInterval > 0 {
time.Sleep(createInterval)
Expand Down
1 change: 1 addition & 0 deletions p2p/simulations/examples/discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (s *networkCompatibilityService) Info() interface{} {
return nil
}

// mimic the behavior of the Snap protocol check
func (s *networkCompatibilityService) Run(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
if !peer.RunningCap(s.name, []uint{1}) {
log.Error("peer does not support protocol", "peer", peer.ID())
Expand Down

0 comments on commit fb68f6f

Please sign in to comment.