-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledger.go
183 lines (149 loc) · 7.51 KB
/
ledger.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright 2018 Insolar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package core
// JetRole is number representing a node role.
type JetRole int
const (
// RoleVirtualExecutor is responsible for current pulse CPU operations.
RoleVirtualExecutor = JetRole(iota + 1)
// RoleVirtualValidator is responsible for previous pulse CPU operations.
RoleVirtualValidator
// RoleLightExecutor is responsible for current pulse Disk operations.
RoleLightExecutor
// RoleLightValidator is responsible for previous pulse Disk operations.
RoleLightValidator
// RoleHeavyExecutor is responsible for permanent Disk operations.
RoleHeavyExecutor
)
// Ledger is the global ledger handler. Other system parts communicate with ledger through it.
type Ledger interface {
// GetArtifactManager returns artifact manager to work with.
GetArtifactManager() ArtifactManager
// GetJetCoordinator returns jet coordinator to work with.
GetJetCoordinator() JetCoordinator
// GetPulseManager returns pulse manager to work with.
GetPulseManager() PulseManager
}
// JetCoordinator provides methods for calculating Jet affinity
// (e.g. to which Jet a message should be sent).
type JetCoordinator interface {
// IsAuthorized checks for role on concrete pulse for the address.
IsAuthorized(role JetRole, obj RecordRef, pulse PulseNumber, node RecordRef) (bool, error)
// QueryRole returns node refs responsible for role bound operations for given object and pulse.
QueryRole(role JetRole, obj RecordRef, pulse PulseNumber) ([]RecordRef, error)
}
// ArtifactManager is a high level storage interface.
type ArtifactManager interface {
// RootRef returns the root record reference.
//
// Root record is the parent for all top-level records.
RootRef() *RecordRef
// GetCode returns code from code record by provided reference according to provided machine preference.
//
// This method is used by VM to fetch code for execution.
GetCode(ref RecordRef, machinePref []MachineType) (CodeDescriptor, error)
// GetClass returns descriptor for provided state.
//
// If provided state is nil, the latest state will be returned (with deactivation check). Returned descriptor will
// provide methods for fetching all related data.
GetClass(head RecordRef, state *RecordRef) (ClassDescriptor, error)
// GetObject returns descriptor for provided state.
//
// If provided state is nil, the latest state will be returned (with deactivation check). Returned descriptor will
// provide methods for fetching all related data.
GetObject(head RecordRef, state *RecordRef) (ObjectDescriptor, error)
// GetDelegate returns provided object's delegate reference for provided class.
//
// Object delegate should be previously created for this object. If object delegate does not exist, an error will
// be returned.
GetDelegate(head, asClass RecordRef) (*RecordRef, error)
// DeclareType creates new type record in storage.
//
// Type is a contract interface. It contains one method signature.
DeclareType(domain, request RecordRef, typeDec []byte) (*RecordRef, error)
// DeployCode creates new code record in storage.
//
// Code records are used to activate class or as migration code for an object.
DeployCode(domain, request RecordRef, codeMap map[MachineType][]byte) (*RecordRef, error)
// ActivateClass creates activate class record in storage. Provided code reference will be used as a class code.
//
// Activation reference will be this class'es identifier and referred as "class head".
ActivateClass(domain, request RecordRef) (*RecordRef, error)
// DeactivateClass creates deactivate record in storage. Provided reference should be a reference to the head of
// the class. If class is already deactivated, an error should be returned.
//
// Deactivated class cannot be changed or instantiate objects.
DeactivateClass(domain, request, class RecordRef) (*RecordRef, error)
// UpdateClass creates amend class record in storage. Provided reference should be a reference to the head of
// the class. Migrations are references to code records.
//
// Returned reference will be the latest class state (exact) reference. Migration code will be executed by VM to
// migrate objects memory in the order they appear in provided slice.
UpdateClass(domain, request, class, code RecordRef, migrationRefs []RecordRef) (*RecordRef, error)
// ActivateObject creates activate object record in storage. Provided class reference will be used as object's class.
// If memory is not provided, the class default memory will be used.
//
// Activation reference will be this object's identifier and referred as "object head".
ActivateObject(domain, request, class, parent RecordRef, memory []byte) (*RecordRef, error)
// ActivateObjectDelegate is similar to ActivateObj but it created object will be parent's delegate of provided class.
ActivateObjectDelegate(domain, request, class, parent RecordRef, memory []byte) (*RecordRef, error)
// DeactivateObject creates deactivate object record in storage. Provided reference should be a reference to the head
// of the object. If object is already deactivated, an error should be returned.
//
// Deactivated object cannot be changed.
DeactivateObject(domain, request, obj RecordRef) (*RecordRef, error)
// UpdateObject creates amend object record in storage. Provided reference should be a reference to the head of the
// object. Provided memory well be the new object memory.
//
// Returned reference will be the latest object state (exact) reference.
UpdateObject(domain, request, obj RecordRef, memory []byte) (*RecordRef, error)
}
// CodeDescriptor represents meta info required to fetch all code data.
type CodeDescriptor interface {
// Ref returns reference to represented code record.
Ref() *RecordRef
// MachineType returns first available machine type for provided machine preference.
MachineType() MachineType
// Code returns code for first available machine type for provided machine preference.
Code() []byte
}
// ClassDescriptor represents meta info required to fetch all object data.
type ClassDescriptor interface {
// HeadRef returns head reference to represented class record.
HeadRef() *RecordRef
// StateRef returns reference to represented class state record.
StateRef() *RecordRef
// CodeDescriptor returns descriptor for fetching class's code data.
CodeDescriptor(machinePref []MachineType) (CodeDescriptor, error)
}
// ObjectDescriptor represents meta info required to fetch all object data.
type ObjectDescriptor interface {
// HeadRef returns head reference to represented object record.
HeadRef() *RecordRef
// StateRef returns reference to object state record.
StateRef() *RecordRef
// Memory fetches object memory from storage.
Memory() []byte
// ClassDescriptor returns descriptor for fetching object's class data.
ClassDescriptor(state *RecordRef) (ClassDescriptor, error)
// Children returns object's children references.
Children() RefIterator
}
// RefIterator is used for iteration over affined children(parts) of container.
type RefIterator interface {
Next() (RecordRef, error)
HasNext() bool
}