-
Notifications
You must be signed in to change notification settings - Fork 669
/
context.go
101 lines (85 loc) · 2.65 KB
/
context.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snow
import (
"io"
"net/http"
"sync"
stdatomic "sync/atomic"
"github.com/prometheus/client_golang/prometheus"
"github.com/ava-labs/gecko/chains/atomic"
"github.com/ava-labs/gecko/database"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow/triggers"
"github.com/ava-labs/gecko/utils/logging"
)
// Callable ...
type Callable interface {
Call(writer http.ResponseWriter, method, base, endpoint string, body io.Reader, headers map[string]string) error
}
// Keystore ...
type Keystore interface {
GetDatabase(username, password string) (database.Database, error)
}
// AliasLookup ...
type AliasLookup interface {
Lookup(alias string) (ids.ID, error)
PrimaryAlias(id ids.ID) (string, error)
}
// SubnetLookup ...
type SubnetLookup interface {
SubnetID(chainID ids.ID) (ids.ID, error)
}
// Context is information about the current execution.
// [NetworkID] is the ID of the network this context exists within.
// [ChainID] is the ID of the chain this context exists within.
// [NodeID] is the ID of this node
type Context struct {
NetworkID uint32
SubnetID ids.ID
ChainID ids.ID
NodeID ids.ShortID
XChainID ids.ID
AVAXAssetID ids.ID
Log logging.Logger
DecisionDispatcher *triggers.EventDispatcher
ConsensusDispatcher *triggers.EventDispatcher
Lock sync.RWMutex
Keystore Keystore
SharedMemory atomic.SharedMemory
BCLookup AliasLookup
SNLookup SubnetLookup
// Non-zero iff this chain bootstrapped. Should only be accessed atomically.
bootstrapped uint32
Namespace string
Metrics prometheus.Registerer
}
// IsBootstrapped returns true iff this chain is done bootstrapping
func (ctx *Context) IsBootstrapped() bool {
return stdatomic.LoadUint32(&ctx.bootstrapped) > 0
}
// Bootstrapped marks this chain as done bootstrapping
func (ctx *Context) Bootstrapped() {
stdatomic.StoreUint32(&ctx.bootstrapped, 1)
}
// DefaultContextTest ...
func DefaultContextTest() *Context {
decisionED := triggers.EventDispatcher{}
decisionED.Initialize(logging.NoLog{})
consensusED := triggers.EventDispatcher{}
consensusED.Initialize(logging.NoLog{})
aliaser := &ids.Aliaser{}
aliaser.Initialize()
return &Context{
NetworkID: 0,
SubnetID: ids.Empty,
ChainID: ids.Empty,
NodeID: ids.ShortEmpty,
Log: logging.NoLog{},
DecisionDispatcher: &decisionED,
ConsensusDispatcher: &consensusED,
BCLookup: aliaser,
Namespace: "",
Metrics: prometheus.NewRegistry(),
}
}