@@ -13,6 +13,7 @@ import (
1313 "time"
1414
1515 "github.com/flashbots/builder-playground/playground"
16+ "github.com/flashbots/builder-playground/playground/cmd"
1617 "github.com/spf13/cobra"
1718)
1819
@@ -34,6 +35,7 @@ var contenderEnabled bool
3435var contenderArgs []string
3536var contenderTarget string
3637var prefundedAccounts []string
38+ var readyzPort int
3739
3840var rootCmd = & cobra.Command {
3941 Use : "playground" ,
@@ -56,73 +58,6 @@ var cookCmd = &cobra.Command{
5658 },
5759}
5860
59- var artifactsCmd = & cobra.Command {
60- Use : "artifacts" ,
61- Short : "List available artifacts" ,
62- RunE : func (cmd * cobra.Command , args []string ) error {
63- if len (args ) != 1 {
64- return fmt .Errorf ("please specify a service name" )
65- }
66- serviceName := args [0 ]
67- component := playground .FindComponent (serviceName )
68- if component == nil {
69- return fmt .Errorf ("service %s not found" , serviceName )
70- }
71- releaseService , ok := component .(playground.ReleaseService )
72- if ! ok {
73- return fmt .Errorf ("service %s is not a release service" , serviceName )
74- }
75- output := outputFlag
76- if output == "" {
77- homeDir , err := playground .GetHomeDir ()
78- if err != nil {
79- return fmt .Errorf ("failed to get home directory: %w" , err )
80- }
81- output = homeDir
82- }
83- location , err := playground .DownloadRelease (output , releaseService .ReleaseArtifact ())
84- if err != nil {
85- return fmt .Errorf ("failed to download release: %w" , err )
86- }
87- fmt .Println (location )
88- return nil
89- },
90- }
91-
92- var artifactsAllCmd = & cobra.Command {
93- Use : "artifacts-all" ,
94- Short : "Download all the artifacts available in the catalog (Used for testing purposes)" ,
95- RunE : func (cmd * cobra.Command , args []string ) error {
96- fmt .Println ("Downloading all artifacts..." )
97-
98- output := outputFlag
99- if output == "" {
100- homeDir , err := playground .GetHomeDir ()
101- if err != nil {
102- return fmt .Errorf ("failed to get home directory: %w" , err )
103- }
104- output = homeDir
105- }
106- for _ , component := range playground .Components {
107- releaseService , ok := component .(playground.ReleaseService )
108- if ! ok {
109- continue
110- }
111- location , err := playground .DownloadRelease (output , releaseService .ReleaseArtifact ())
112- if err != nil {
113- return fmt .Errorf ("failed to download release: %w" , err )
114- }
115-
116- // make sure the artifact is valid to be executed on this platform
117- log .Printf ("Downloaded %s to %s\n " , releaseService .ReleaseArtifact ().Name , location )
118- if err := isExecutableValid (location ); err != nil {
119- return fmt .Errorf ("failed to check if artifact is valid: %w" , err )
120- }
121- }
122- return nil
123- },
124- }
125-
12661var inspectCmd = & cobra.Command {
12762 Use : "inspect" ,
12863 Short : "Inspect a connection between two services" ,
@@ -187,18 +122,16 @@ func main() {
187122 recipeCmd .Flags ().StringArrayVar (& contenderArgs , "contender.arg" , []string {}, "add/override contender CLI flags" )
188123 recipeCmd .Flags ().StringVar (& contenderTarget , "contender.target" , "" , "override the node that contender spams -- accepts names like \" el\" " )
189124 recipeCmd .Flags ().StringArrayVar (& prefundedAccounts , "prefunded-account" , []string {}, "Fund this account in addition to static prefunded accounts, the input should the account's private key in hexadecimal format prefixed with 0x, the account is added to L1 and to L2 (if present)" )
125+ recipeCmd .Flags ().IntVar (& readyzPort , "readyz-port" , 0 , "port for readyz HTTP endpoint (0 to disable)" )
190126
191127 cookCmd .AddCommand (recipeCmd )
192128 }
193129
194- // reuse the same output flag for the artifacts command
195- artifactsCmd .Flags ().StringVar (& outputFlag , "output" , "" , "Output folder for the artifacts" )
196- artifactsAllCmd .Flags ().StringVar (& outputFlag , "output" , "" , "Output folder for the artifacts" )
130+ cmd .InitWaitReadyCmd ()
197131
198132 rootCmd .AddCommand (cookCmd )
199- rootCmd .AddCommand (artifactsCmd )
200- rootCmd .AddCommand (artifactsAllCmd )
201133 rootCmd .AddCommand (inspectCmd )
134+ rootCmd .AddCommand (cmd .WaitReadyCmd )
202135
203136 if err := rootCmd .Execute (); err != nil {
204137 fmt .Println (err )
@@ -233,15 +166,17 @@ func runIt(recipe playground.Recipe) error {
233166 return err
234167 }
235168
236- // if contender.tps is set, assume contender is enabled
237- svcManager := recipe .Apply (& playground.ExContext {
169+ exCtx := & playground.ExContext {
238170 LogLevel : logLevel ,
171+ // if contender.tps is set, assume contender is enabled
239172 Contender : & playground.ContenderContext {
240173 Enabled : contenderEnabled ,
241174 ExtraArgs : contenderArgs ,
242175 TargetChain : contenderTarget ,
243176 },
244- }, artifacts )
177+ }
178+ svcManager := playground .NewManifest (exCtx , artifacts .Out )
179+ recipe .Apply (svcManager )
245180 if err := svcManager .Validate (); err != nil {
246181 return fmt .Errorf ("failed to validate manifest: %w" , err )
247182 }
@@ -299,6 +234,16 @@ func runIt(recipe playground.Recipe) error {
299234 cancel ()
300235 }()
301236
237+ var readyzServer * playground.ReadyzServer
238+ if readyzPort > 0 {
239+ readyzServer = playground .NewReadyzServer (dockerRunner .Instances (), readyzPort )
240+ if err := readyzServer .Start (); err != nil {
241+ return fmt .Errorf ("failed to start readyz server: %w" , err )
242+ }
243+ defer readyzServer .Stop ()
244+ fmt .Printf ("Readyz endpoint available at http://localhost:%d/readyz\n " , readyzPort )
245+ }
246+
302247 if err := dockerRunner .Run (); err != nil {
303248 dockerRunner .Stop ()
304249 return fmt .Errorf ("failed to run docker: %w" , err )
@@ -330,10 +275,13 @@ func runIt(recipe playground.Recipe) error {
330275 return fmt .Errorf ("failed to wait for service readiness: %w" , err )
331276 }
332277
278+ fmt .Printf ("\n Waiting for network to be ready for transactions...\n " )
279+ networkReadyStart := time .Now ()
333280 if err := playground .CompleteReady (dockerRunner .Instances ()); err != nil {
334281 dockerRunner .Stop ()
335- return fmt .Errorf ("failed to complete ready: %w" , err )
282+ return fmt .Errorf ("network not ready: %w" , err )
336283 }
284+ fmt .Printf ("Network is ready for transactions (took %.1fs)\n " , time .Since (networkReadyStart ).Seconds ())
337285
338286 // get the output from the recipe
339287 output := recipe .Output (svcManager )
0 commit comments