Files
chains/mpcvm/cmd/plugin/main.go
T
zeekay 6981a3cd6c mpcvm: M-Chain to 98.6%
The lane that did this was killed before it could commit; the tree it left is
green and is preserved here rather than lost. Root package 51.5% at the start
of the day, 93.3% at its last checkpoint, 98.6% now, with cert, fhe, types and
cmd/plugin all passing.

Includes the fault-injection suite it was building when it stopped: a node that
cannot read its state does not start, and one that cannot enumerate its
registry does not either.

Not reviewed by me beyond build, vet, gofmt and the full suite under -count=1.
The lane's own report is owed and did not arrive, so its mutation count and its
verdict on the mpcvm/fhe duplication are unrecorded.
2026-08-28 13:25:30 -07:00

57 lines
1.9 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Command plugin serves the M-Chain VM to a Lux node.
//
// The binary's FILENAME must be the CB58 of mpcvm.VMID
// (qCURact1n41FcoNBch8iMVBwc9AWie48D118ZNJ5tBdWrvryS) — that is how the node's
// plugin registry resolves a vmID from a CreateChainTx to an implementation.
// A binary installed under any other name is invisible and the chain silently
// never starts, which is why `version` prints the id it must be installed as:
// the fact an operator needs is in the place an operator already looks.
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/luxfi/chains/mpcvm"
"github.com/luxfi/log"
"github.com/luxfi/sys/ulimit"
"github.com/luxfi/vm/chain"
"github.com/luxfi/vm/rpc"
)
func main() {
os.Exit(run(context.Background(), os.Args[1:], os.Stdout, os.Stderr))
}
// run is main with the exit lifted out, so what the plugin does is reachable
// from a test and only the exit itself is not.
func run(ctx context.Context, args []string, out, errOut io.Writer) int {
if len(args) > 0 && args[0] == "version" {
fmt.Fprintf(out, "mpcvm/%s %s\n", mpcvm.Version, mpcvm.VMID)
return 0
}
if err := ulimit.Set(ulimit.DefaultFDLimit, log.Root()); err != nil {
return fail(errOut, err)
}
// Typed at the declaration: "this plugin serves M-Chain's ChainVM" is then
// a compile error to get wrong, rather than a runtime type assertion on a
// factory that returns interface{} and an error it never returns.
var vm chain.ChainVM = &mpcvm.VM{}
if err := rpc.Serve(ctx, log.Root(), vm); err != nil {
return fail(errOut, err)
}
return 0
}
// fail reports why the plugin is not serving and gives the node a non-zero
// exit. A plugin that dies quietly presents as a chain that never starts.
func fail(w io.Writer, err error) int {
fmt.Fprintf(w, "mpcvm plugin: %s\n", err)
return 1
}