github.com/MetalBlockchain/metalgo@v1.11.9/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/MetalBlockchain/metalgo/version" 12 "github.com/MetalBlockchain/metalgo/vms/rpcchainvm/runtime" 13 ) 14 15 var _ runtime.Initializer = (*initializer)(nil) 16 17 // Subprocess VM Runtime intializer. 18 type initializer struct { 19 once sync.Once 20 // Address of the RPC Chain VM server 21 vmAddr string 22 // Error, if one occurred, during Initialization 23 err error 24 // Initialized is closed once Initialize is called 25 initialized chan struct{} 26 } 27 28 func newInitializer() *initializer { 29 return &initializer{ 30 initialized: make(chan struct{}), 31 } 32 } 33 34 func (i *initializer) Initialize(_ context.Context, protocolVersion uint, vmAddr string) error { 35 i.once.Do(func() { 36 if version.RPCChainVMProtocol != protocolVersion { 37 i.err = fmt.Errorf("%w. MetalGo version %s implements RPCChainVM protocol version %d. The VM 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", 38 runtime.ErrProtocolVersionMismatch, 39 version.Current, 40 version.RPCChainVMProtocol, 41 protocolVersion, 42 ) 43 } 44 i.vmAddr = vmAddr 45 close(i.initialized) 46 }) 47 return i.err 48 }