bridgevm: the plugin reports the version the VM has

It printed a string literal beside bridgevm.Version. Bump either and the
binary an operator asks reports a version it is not. Splitting run() out of
main() makes what the plugin does separable from how a process reports it,
and testable.
This commit is contained in:
2026-08-28 12:05:31 -07:00
parent a927ce8a7e
commit 3035c643f0
+23 -20
View File
@@ -16,26 +16,29 @@ import (
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "version" {
fmt.Println("Bridge-VM/1.0.0")
os.Exit(0)
}
if err := ulimit.Set(ulimit.DefaultFDLimit, log.Root()); err != nil {
fmt.Fprintf(os.Stderr, "failed to set fd limit: %s\n", err)
os.Exit(1)
}
f := &bridgevm.Factory{}
raw, err := f.New(log.Root())
if err != nil {
fmt.Fprintf(os.Stderr, "factory error: %s\n", err)
os.Exit(1)
}
vm := raw.(chain.ChainVM)
if err := rpc.Serve(context.Background(), log.Root(), vm); err != nil {
fmt.Fprintf(os.Stderr, "rpc.Serve error: %s\n", err)
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
// run is the plugin: answer for the version, or serve the VM. It is a
// function rather than the body of main so what it does is separable from how
// a process reports it.
func run() error {
if len(os.Args) > 1 && os.Args[1] == "version" {
// The version comes from the VM, not from a second copy of the number
// here. Two declarations of one version disagree the first time either
// is bumped, and the one an operator reads is this one.
fmt.Printf("Bridge-VM/%s\n", bridgevm.Version)
return nil
}
if err := ulimit.Set(ulimit.DefaultFDLimit, log.Root()); err != nil {
return fmt.Errorf("set fd limit: %w", err)
}
raw, err := (&bridgevm.Factory{}).New(log.Root())
if err != nil {
return fmt.Errorf("build the VM: %w", err)
}
return rpc.Serve(context.Background(), log.Root(), raw.(chain.ChainVM))
}