mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
dchain: one construction path for the D-Chain VM
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.
This commit is contained in:
@@ -31,7 +31,14 @@ func Run() {
|
||||
fmt.Println(versionStr)
|
||||
os.Exit(0)
|
||||
}
|
||||
if err := rpc.Serve(context.Background(), log.Root(), &dchain.VM{}); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package dchain
|
||||
|
||||
import (
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/log"
|
||||
"github.com/luxfi/vm/manager"
|
||||
)
|
||||
|
||||
// VMID is the D-Chain's identifier, the one the node resolves a CreateChainTx
|
||||
// to. It is spelled here, beside the VM, so the chain and the id it answers to
|
||||
// cannot drift apart.
|
||||
var VMID = ids.ID{'d', 'e', 'x', 'v', 'm'}
|
||||
|
||||
// Factory builds D-Chain VMs. It is the ONE construction path: the node calls
|
||||
// it to register the chain in-process, and the plugin entrypoint calls it
|
||||
// before handing the VM to rpc.Serve. Two constructors would eventually build
|
||||
// two different VMs and the difference would show up as a chain that behaves
|
||||
// one way inside luxd and another way behind the plugin harness.
|
||||
//
|
||||
// A VM built here holds nothing. Initialize opens the database, rebuilds the
|
||||
// book cache from the order rows, and does the rest.
|
||||
type Factory struct{}
|
||||
|
||||
var _ manager.Factory = (*Factory)(nil)
|
||||
|
||||
func (*Factory) New(log.Logger) (interface{}, error) { return &VM{}, nil }
|
||||
Reference in New Issue
Block a user