Repository navigation
feat: rollkit start running application logic of the rollup #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
7554d20
xWIP: running entrypoint start under the hood of rollkit start if rol…
yarikbratashchuk dff0b71
Intercept all commands if rollkit.toml
yarikbratashchuk ec59abd
Move related vars consts
yarikbratashchuk 1885fa9
Minor refactor + comments
yarikbratashchuk 0e82212
Remove fmt.Printf
yarikbratashchuk 686f44e
Remove duplicate import
yarikbratashchuk 042149a
Update cmd/rollkit/commands/intercept.go
yarikbratashchuk f8266bf
Comment InterceptCommand call
yarikbratashchuk 51361f5
Comment ReadToml, minor error improvements
yarikbratashchuk 4075314
Move toml config to read toml
yarikbratashchuk 3053669
Go mod tidy
yarikbratashchuk 74d7bec
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 9ee56ac
Update config/cli.go
yarikbratashchuk ffb99ec
Update config/cli.go
yarikbratashchuk 0372d73
Update config/cli.go
yarikbratashchuk a3da6b5
Update config/cli.go
yarikbratashchuk d12aae3
Minor fixes
yarikbratashchuk fe6bafc
Ignore gosec
yarikbratashchuk a57fa52
Fix lint
yarikbratashchuk 53dee2a
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 4e6073d
Add tests for InterceptCommand and inner funcs
yarikbratashchuk 6eb74c6
Update cmd/rollkit/main.go
yarikbratashchuk 0621833
Fix lint issues
yarikbratashchuk b247bec
Update comments
yarikbratashchuk 0c4c5ce
Fix lint issue
yarikbratashchuk 1b8bf9e
Check if chain config dir is relative
yarikbratashchuk f851029
Fix test
yarikbratashchuk 7403dd4
Dont pass --home if not specified
yarikbratashchuk b82fa0f
Update cmd/rollkit/main.go
yarikbratashchuk a2517bb
Fix error undefined
yarikbratashchuk 6ef2cbe
rollkit toml init & fixes after @tzdybal's review
yarikbratashchuk 8a8891c
logging
yarikbratashchuk 51270d9
Merge branch 'main' into yarik/rollkit
yarikbratashchuk a574335
Error wrapping
yarikbratashchuk 5bf0168
Fix lint errors
yarikbratashchuk f361126
Update tests for finding entrypoint
yarikbratashchuk c59b6e8
Generate docs and skip all rollkit commands except start
yarikbratashchuk e510aae
Remove toml from the list to skip
yarikbratashchuk e5c7259
Fix test lint
yarikbratashchuk 3c20c80
Update docs
yarikbratashchuk a87b4be
Remove redundant logs
yarikbratashchuk 26c763e
Fixes after MSevey's review
yarikbratashchuk afabac5
Update cmd/rollkit/main.go
yarikbratashchuk 72bbf30
Update intercept test to check for returned book value
yarikbratashchuk 9fa4391
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 2c55b1f
Improve intercept testing
yarikbratashchuk 7ac7fd7
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 1ebefac
Remove cov.out
yarikbratashchuk 45b8854
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 3b4f270
Merge branch 'main' into yarik/rollkit
yarikbratashchuk f381256
Merge branch 'main' into yarik/rollkit
yarikbratashchuk a530d85
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 073be74
Fix naming collision during rebase
yarikbratashchuk 62dee68
Merge branch 'main' into yarik/rollkit
yarikbratashchuk 5d02b06
Avoid recursion by checking command root dir not being rollkit
yarikbratashchuk 99f1246
Docs-gen
yarikbratashchuk 39741af
Revert "Docs-gen"
yarikbratashchuk 92b64c1
Update docs
yarikbratashchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
|
|
||
| "github.com/BurntSushi/toml" | ||
| cometos "github.com/cometbft/cometbft/libs/os" | ||
| rollconf "github.com/rollkit/rollkit/config" | ||
| ) | ||
|
|
||
| func InterceptCommand() error { | ||
| var err error | ||
| rollkitConfig, err = readTomlConfig() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if rollkitConfig.Entrypoint != "" { | ||
| flags := []string{} | ||
| if len(os.Args) >= 2 { | ||
| flags = os.Args[1:] | ||
| } | ||
| return runEntrypoint(rollkitConfig, flags) | ||
| } | ||
|
|
||
| return nil | ||
|
yarikbratashchuk marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| func readTomlConfig() (rollconf.TomlConfig, error) { | ||
| var config rollconf.TomlConfig | ||
| startDir, err := os.Getwd() | ||
| if err != nil { | ||
| return config, fmt.Errorf("error getting current directory: %v", err) | ||
|
yarikbratashchuk marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| configPath, err := findConfigFile(startDir) | ||
| if err != nil { | ||
| return config, err | ||
| } | ||
|
|
||
| if _, err := toml.DecodeFile(configPath, &config); err != nil { | ||
| return config, fmt.Errorf("error reading rollkit.toml: %v", err) | ||
| } | ||
|
|
||
| config.RootDir = filepath.Dir(configPath) | ||
|
|
||
| return config, nil | ||
| } | ||
|
|
||
| func findConfigFile(startDir string) (string, error) { | ||
| dir := startDir | ||
| for { | ||
| configPath := filepath.Join(dir, "rollkit.toml") | ||
| if _, err := os.Stat(configPath); err == nil { | ||
| return configPath, nil | ||
| } | ||
|
|
||
| parentDir := filepath.Dir(dir) | ||
| if parentDir == dir { | ||
| break | ||
| } | ||
| dir = parentDir | ||
| } | ||
| return "", fmt.Errorf("no rollkit.toml found") | ||
| } | ||
|
yarikbratashchuk marked this conversation as resolved.
|
||
|
|
||
| func runEntrypoint(rollkitConfig rollconf.TomlConfig, args []string) error { | ||
| entrypointSourceFile := filepath.Join(rollkitConfig.RootDir, rollkitConfig.Entrypoint) | ||
| entrypointBinaryFile := filepath.Join(rollkitConfig.RootDir, rollupBinEntrypoint) | ||
|
yarikbratashchuk marked this conversation as resolved.
|
||
|
|
||
| if !cometos.FileExists(entrypointBinaryFile) { | ||
| if !cometos.FileExists(entrypointSourceFile) { | ||
| return fmt.Errorf("rollkit: no such entrypoint file: %s", entrypointSourceFile) | ||
| } | ||
|
|
||
| // try to build the entrypoint | ||
| var buildArgs []string | ||
| buildArgs = append(buildArgs, "build") | ||
| buildArgs = append(buildArgs, "-o", entrypointBinaryFile) | ||
| buildArgs = append(buildArgs, entrypointSourceFile) | ||
|
yarikbratashchuk marked this conversation as resolved.
Outdated
|
||
| buildCmd := exec.Command("go", buildArgs...) | ||
|
yarikbratashchuk marked this conversation as resolved.
Outdated
|
||
| buildCmd.Stdout = os.Stdout | ||
| buildCmd.Stderr = os.Stderr | ||
| if err := buildCmd.Run(); err != nil { | ||
| return fmt.Errorf("rollkit: failed to build entrypoint: %w", err) | ||
| } | ||
| } | ||
|
|
||
| // run the entrypoint | ||
| var runArgs []string | ||
| runArgs = append(runArgs, args...) | ||
| // we have to pass --home flag to the entrypoint, so it reads the correct config root directory | ||
| runArgs = append(runArgs, "--home", rollkitConfig.Chain.ConfigDir) | ||
| fmt.Printf("Running entrypoint: %s %v\n", entrypointBinaryFile, runArgs) | ||
| entrypointCmd := exec.Command(entrypointBinaryFile, runArgs...) | ||
| entrypointCmd.Stdout = os.Stdout | ||
| entrypointCmd.Stderr = os.Stderr | ||
|
|
||
| if err := entrypointCmd.Run(); err != nil { | ||
| return fmt.Errorf("rollkit: failed to run entrypoint: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.