github.com/ava-labs/avalanchego@v1.11.11/vms/rpcchainvm/runtime/subprocess/initializer.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package subprocess 5 6 import ( 7 "context" 8 "fmt" 9 "sync" 10 11 "github.com/ava-labs/avalanchego/version" 12 "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" 13 ) 14 15 var _ runtime.Initializer = (*initializer)(nil) 16 17 // Subprocess VM Runtime intializer. 18 type initializer struct { 19 path string 20 21 once sync.Once 22 // Address of the RPC Chain VM server 23 vmAddr string 24 // Error, if one occurred, during Initialization 25 err error 26 // Initialized is closed once Initialize is called 27 initialized chan struct{} 28 } 29 30 func newInitializer(path string) *initializer { 31 return &initializer{ 32 path: path, 33 initialized: make(chan struct{}), 34 } 35 } 36 37 func (i *initializer) Initialize(_ context.Context, protocolVersion uint, vmAddr string) error { 38 i.once.Do(func() { 39 if version.RPCChainVMProtocol != protocolVersion { 40 i.err = fmt.Errorf("%w. AvalancheGo version %s implements RPCChainVM protocol version %d. The VM located at %s implements RPCChainVM protocol version %d. Please make sure that there is an exact match of the protocol versions. This can be achieved by updating your VM or running an older/newer version of AvalancheGo. Please be advised that some virtual machines may not yet support the latest RPCChainVM protocol version", 41 runtime.ErrProtocolVersionMismatch, 42 version.Current, 43 version.RPCChainVMProtocol, 44 i.path, 45 protocolVersion, 46 ) 47 } 48 i.vmAddr = vmAddr 49 close(i.initialized) 50 }) 51 return i.err 52 }