Skip to content

Commit ceadfcb

Browse files
authored
Use XDG_STATE_HOME dir if set (#326)
Closes #325
1 parent fe444f9 commit ceadfcb

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ docker logs -f $(docker ps | grep contender | cut -d' ' -f1)
110110

111111
## Common Options
112112

113-
- `--output` (string): The directory where the chain data and artifacts are stored. Defaults to `$HOME/.playground/devnet`
113+
- `--output` (string): The directory where the chain data and artifacts are stored. Defaults to `$HOME/.local/state/builder-playground/devnet`
114114
- `--detached` (bool): Run the recipes in the background. Defaults to `false`.
115115
- `--genesis-delay` (int): The delay in seconds before the genesis block is created. Defaults to `10` seconds
116116
- `--watchdog` (bool): Enable the watchdog service to monitor the specific chain
@@ -121,7 +121,7 @@ docker logs -f $(docker ps | grep contender | cut -d' ' -f1)
121121
- `--prefunded-accounts` (string, repeated): 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).
122122
- `--contender` (bool): Enable [contender](https://github.com/flashbots/contender) spammer. Required to use other contender flags.
123123
- `--contender.arg` (string): Pass custom args to the contender CLI.
124-
Example: `--contender.arg "--tpb 20"`
124+
Example: `--contender.arg "--tpb 20"`
125125
- `--contender.target` (string): Change the default target node to spam. On the `l1` recipe, the default is "el", and on `opstack` it's "op-geth".
126126
- `--with-prometheus` (bool); Whether to deploy a Prometheus server and gather metrics. Defaults to `false`.
127127

@@ -158,6 +158,7 @@ $ builder-playground logs validator
158158
With single session running, the commands are straightforward.
159159

160160
With multiple sessions running, it's easy to navigate:
161+
161162
- listing: `list` -> pick session `major-hornet` -> `list major-hornet` -> see service list
162163
- viewing logs: see service `validator` with `logs major-hornet validator`
163164

@@ -223,6 +224,7 @@ WithArgs("--metrics", `0.0.0.0:{{Port "metrics" 9090}}`)
223224
By default, Prometheus scrapes the `/metrics` path, but services can override this by specifying a custom path with `WithLabel("metrics_path", "/custom/path")`. All configured services are automatically registered as scrape targets.
224225

225226
### Usage
227+
226228
Enable Prometheus for any recipe:
227229

228230
```bash

examples/op-stack-rollup-boost.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ First, download the `op-reth` binary:
88
$ go run main.go artifacts op-reth
99
```
1010

11-
This will download the op-reth binary and save it under `$HOME/.playground/op-reth-v1.3.12`.
11+
This will download the op-reth binary and save it under `$HOME/.local/state/builder-playground/op-reth-v1.3.12`.
1212

1313
Second, we can deploy the Op Stack with rollup-boost:
1414

@@ -35,9 +35,9 @@ The `--external-builder` flag is used to specify the URL of the external block b
3535
Third, we can start the `op-reth` binary as the external block builder:
3636

3737
```bash
38-
$ $HOME/.playground/op-reth-v1.3.12 node --http --http.port 2222 \
39-
--authrpc.addr 0.0.0.0 --authrpc.port 4444 --authrpc.jwtsecret $HOME/.playground/devnet/jwtsecret \
40-
--chain $HOME/.playground/devnet/l2-genesis.json --datadir /tmp/builder --disable-discovery --port 30333 \
38+
$ $HOME/.local/state/builder-playground/op-reth-v1.3.12 node --http --http.port 2222 \
39+
--authrpc.addr 0.0.0.0 --authrpc.port 4444 --authrpc.jwtsecret $HOME/.local/state/builder-playground/devnet/jwtsecret \
40+
--chain $HOME/.local/state/builder-playground/devnet/l2-genesis.json --datadir /tmp/builder --disable-discovery --port 30333 \
4141
--trusted-peers enode://79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8@127.0.0.1:30304
4242
```
4343

examples/rbuilder-config.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
chain = "$HOME/.playground/devnet/genesis.json"
3-
reth_datadir = "$HOME/.playground/devnet/volume-el-data"
2+
chain = "$HOME/.local/state/builder-playground/devnet/genesis.json"
3+
reth_datadir = "$HOME/.local/state/builder-playground/devnet/volume-el-data"
44
relay_secret_key = "5eae315483f028b5cdd5d1090ff0c7618b18737ea9bf3c35047189db22835c48"
5-
el_node_ipc_path = "$HOME/.playground/devnet/volume-el-data/reth.ipc"
5+
el_node_ipc_path = "$HOME/.local/state/builder-playground/devnet/volume-el-data/reth.ipc"
66
live_builders = ["mgp-ordering"]
77
enabled_relays = ["playground"]
88
log_level = "info,rbuilder=debug"
99
coinbase_secret_key = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
1010

11-
root_hash_use_sparse_trie=true
12-
root_hash_compare_sparse_trie=false
11+
root_hash_use_sparse_trie = true
12+
root_hash_compare_sparse_trie = false
1313
slot_delta_to_start_bidding_ms = -20000
1414

1515
[[relays]]

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,15 @@ func runIt(recipe playground.Recipe) error {
341341
}
342342
logging.ConfigureSlog(logLevelFlag)
343343
sessionID := utils.GeneratePetName()
344+
345+
out, err := playground.NewOutput(outputFlag)
346+
if err != nil {
347+
return err
348+
}
349+
344350
slog.Info("Welcome to Builder Playground! ⚡️🤖")
345351
slog.Info("Session ID: "+greenColor.Sprint(sessionID), "log-level", logLevel)
352+
slog.Info("Output folder: " + out.Dst())
346353
slog.Info("")
347354

348355
// parse the overrides
@@ -355,11 +362,6 @@ func runIt(recipe playground.Recipe) error {
355362
overrides[parts[0]] = parts[1]
356363
}
357364

358-
out, err := playground.NewOutput(outputFlag)
359-
if err != nil {
360-
return err
361-
}
362-
363365
slog.Debug("Building artifacts...")
364366
builder := recipe.Artifacts()
365367
builder.GenesisDelay(genesisDelayFlag)

playground/artifacts.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ func NewOutput(dst string) (*output, error) {
514514
return out, nil
515515
}
516516

517+
func (o *output) Dst() string {
518+
return o.dst
519+
}
520+
517521
func (o *output) Read(path string) (string, error) {
518522
data, err := os.ReadFile(filepath.Join(o.dst, path))
519523
if err != nil {
@@ -699,8 +703,18 @@ func GetHomeDir() (string, error) {
699703
return "", fmt.Errorf("error getting user home directory: %w", err)
700704
}
701705

706+
// if legacy .playground dir is present, remove it
707+
if err := os.RemoveAll(filepath.Join(homeDir, ".playground")); err != nil {
708+
return "", err
709+
}
710+
711+
stateHomeDir := os.Getenv("XDG_STATE_HOME")
712+
if stateHomeDir == "" {
713+
stateHomeDir = filepath.Join(homeDir, ".local", "state")
714+
}
715+
702716
// Define the path for our custom home directory
703-
customHomeDir := filepath.Join(homeDir, ".playground")
717+
customHomeDir := filepath.Join(stateHomeDir, "builder-playground")
704718

705719
// Create output directory if it doesn't exist
706720
if err := os.MkdirAll(customHomeDir, 0o755); err != nil {

0 commit comments

Comments
 (0)