mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
The VM had no factory, so the only way to build it was the literal in the plugin entrypoint. That kept the D-Chain reachable exactly one way — as an execed binary — and left the node unable to register it beside the chains it links, which is why luxd came up without a D-Chain at all. Factory is now the one constructor: the node registers it in-process and the plugin entrypoint builds through it before handing the VM to rpc.Serve. VMID moves in beside it so the chain and the id it answers to cannot drift apart.
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Package plugin boots the native D-Chain DEX VM as a luxd rpcchainvm plugin,
|
|
// mirroring github.com/luxfi/evm/plugin/runner. rpc.Serve takes the engine
|
|
// address from the runtime.EngineAddressKey env var, opens this chain's own
|
|
// badgerdb/zapdb, hands it to VM.Initialize, and serves block requests so
|
|
// BuildBlock/Verify/Accept run inside luxd's multi-validator consensus — the
|
|
// exact harness lux/evm boots through. The VM (pkg/dchain) is pure-Go (CGO=0);
|
|
// this entrypoint links no native code.
|
|
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/luxfi/dex/pkg/dchain"
|
|
log "github.com/luxfi/log"
|
|
"github.com/luxfi/version"
|
|
"github.com/luxfi/vm/rpc"
|
|
)
|
|
|
|
// Run boots the d-chain VM over the rpcchainvm plugin transport. It blocks
|
|
// until the node runtime shuts the VM down. When luxd probes the plugin version
|
|
// (a single "version" arg), it prints the version line and exits 0.
|
|
func Run() {
|
|
versionStr := fmt.Sprintf("Lux-DChain/%s [node=%s, rpcchainvm=%d]",
|
|
dchain.Version, version.Current, version.RPCChainVMProtocol)
|
|
if printVersion() {
|
|
fmt.Println(versionStr)
|
|
os.Exit(0)
|
|
}
|
|
raw, err := (&dchain.Factory{}).New(log.Root())
|
|
if err != nil {
|
|
fmt.Printf("dchain factory error: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
vm := raw.(*dchain.VM)
|
|
|
|
if err := rpc.Serve(context.Background(), log.Root(), vm); err != nil {
|
|
fmt.Printf("dchain rpc.Serve error: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// printVersion reports whether the process was asked to just print its version
|
|
// and exit. The node passes a single "version" arg when probing a plugin.
|
|
func printVersion() bool {
|
|
for _, a := range os.Args[1:] {
|
|
if a == "version" || a == "--version" || a == "-version" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|