-
Notifications
You must be signed in to change notification settings - Fork 669
/
initializer.go
48 lines (41 loc) · 1.06 KB
/
initializer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package subprocess
import (
"context"
"fmt"
"sync"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime"
)
var _ runtime.Initializer = (*initializer)(nil)
// Subprocess VM Runtime intializer.
type initializer struct {
once sync.Once
// Address of the RPC Chain VM server
vmAddr string
// Error, if one occurred, during Initialization
err error
// Initialized is closed once Initialize is called
initialized chan struct{}
}
func newInitializer() *initializer {
return &initializer{
initialized: make(chan struct{}),
}
}
func (i *initializer) Initialize(_ context.Context, protocolVersion uint, vmAddr string) error {
i.once.Do(func() {
if version.RPCChainVMProtocol != protocolVersion {
i.err = fmt.Errorf(
"%w avalanchego: %d, vm: %d",
runtime.ErrProtocolVersionMismatch,
version.RPCChainVMProtocol,
protocolVersion,
)
}
i.vmAddr = vmAddr
close(i.initialized)
})
return i.err
}