@@ -32,7 +32,7 @@ func newPeriodLinkedArray() {
32
32
}
33
33
34
34
type LinkedArray interface {
35
- GetByHeight ( height uint64 ) (* consensus_db.Point , error )
35
+ GetByIndex ( index uint64 ) (* consensus_db.Point , error )
36
36
}
37
37
38
38
type linkedArray struct {
@@ -42,24 +42,24 @@ type linkedArray struct {
42
42
lowerArr LinkedArray
43
43
}
44
44
45
- func (self * linkedArray ) GetByHeight ( height uint64 ) (* consensus_db.Point , error ) {
46
- point , err := self .db .GetPointByHeight (self .prefix , height )
45
+ func (self * linkedArray ) GetByIndex ( index uint64 ) (* consensus_db.Point , error ) {
46
+ point , err := self .db .GetPointByHeight (self .prefix , index )
47
47
if err != nil {
48
48
return nil , err
49
49
}
50
50
if point != nil {
51
51
return point , nil
52
52
}
53
53
54
- return self .getByHeight ( height )
54
+ return self .getByIndex ( index )
55
55
}
56
56
57
- func (self * linkedArray ) getByHeight ( height uint64 ) (* consensus_db.Point , error ) {
57
+ func (self * linkedArray ) getByIndex ( index uint64 ) (* consensus_db.Point , error ) {
58
58
result := & consensus_db.Point {}
59
- start := height * self .rate
59
+ start := index * self .rate
60
60
end := start + self .rate
61
61
for i := start ; i < end ; i ++ {
62
- p , err := self .lowerArr .GetByHeight (i )
62
+ p , err := self .lowerArr .GetByIndex (i )
63
63
if err != nil {
64
64
return nil , err
65
65
}
@@ -71,6 +71,7 @@ func (self *linkedArray) getByHeight(height uint64) (*consensus_db.Point, error)
71
71
return result , nil
72
72
}
73
73
74
+ var PERIOD_TO_SECS = uint64 (75 )
74
75
var HOUR_TO_PERIOD = uint64 (48 )
75
76
var DAY_TO_HOUR = uint64 (24 )
76
77
var DAY_TO_PERIOD = uint64 (24 * 48 )
@@ -112,15 +113,15 @@ func newPeriodPointArray(rw Chain, cs DposReader) *periodLinkedArray {
112
113
return & periodLinkedArray {rw : rw , periods : cache , snapshot : cs }
113
114
}
114
115
115
- func (self * periodLinkedArray ) GetByHeight ( height uint64 ) (* consensus_db.Point , error ) {
116
- value , ok := self .periods .Get (height )
116
+ func (self * periodLinkedArray ) GetByIndex ( index uint64 ) (* consensus_db.Point , error ) {
117
+ value , ok := self .periods .Get (index )
117
118
if ! ok || value == nil {
118
- result , err := self .getByHeight ( height )
119
+ result , err := self .getByIndex ( index )
119
120
if err != nil {
120
121
return nil , err
121
122
}
122
123
if result != nil {
123
- self .Set (height , result )
124
+ self .Set (index , result )
124
125
return & result .Point , nil
125
126
} else {
126
127
return nil , nil
@@ -129,12 +130,12 @@ func (self *periodLinkedArray) GetByHeight(height uint64) (*consensus_db.Point,
129
130
point := value .(* periodPoint )
130
131
valid := self .checkValid (point )
131
132
if ! valid {
132
- result , err := self .getByHeight ( height )
133
+ result , err := self .getByIndex ( index )
133
134
if err != nil {
134
135
return nil , err
135
136
}
136
137
if result != nil {
137
- self .Set (height , result )
138
+ self .Set (index , result )
138
139
return & result .Point , nil
139
140
} else {
140
141
return nil , nil
@@ -143,28 +144,24 @@ func (self *periodLinkedArray) GetByHeight(height uint64) (*consensus_db.Point,
143
144
return & point .Point , nil
144
145
}
145
146
146
- func (self * periodLinkedArray ) Set (height uint64 , block * periodPoint ) error {
147
- self .periods .Add (height , block )
147
+ func (self * periodLinkedArray ) Set (index uint64 , block * periodPoint ) error {
148
+ self .periods .Add (index , block )
148
149
return nil
149
150
}
150
151
151
- func (self * periodLinkedArray ) NextHeight (height uint64 ) uint64 {
152
- return height + 1
153
- }
154
-
155
- func (self * periodLinkedArray ) getByHeight (height uint64 ) (* periodPoint , error ) {
156
- stime , etime := self .snapshot .Index2Time (height )
152
+ func (self * periodLinkedArray ) getByIndex (index uint64 ) (* periodPoint , error ) {
153
+ stime , etime := self .snapshot .Index2Time (index )
157
154
// todo opt
158
155
endSnapshotBlock , err := self .rw .GetSnapshotHeaderBeforeTime (& etime )
159
156
if err != nil {
160
157
return nil , err
161
158
}
162
159
if endSnapshotBlock .Timestamp .Before (stime ) {
163
- return self .emptyPoint (height , & stime , & etime , endSnapshotBlock )
160
+ return self .emptyPoint (index , & stime , & etime , endSnapshotBlock )
164
161
}
165
162
166
163
if self .rw .IsGenesisSnapshotBlock (endSnapshotBlock .Hash ) {
167
- return self .emptyPoint (height , & stime , & etime , endSnapshotBlock )
164
+ return self .emptyPoint (index , & stime , & etime , endSnapshotBlock )
168
165
}
169
166
170
167
blocks , err := self .rw .GetSnapshotHeadersAfterOrEqualTime (& ledger.HashHeight {Hash : endSnapshotBlock .Hash , Height : endSnapshotBlock .Height }, & stime , nil )
@@ -174,15 +171,15 @@ func (self *periodLinkedArray) getByHeight(height uint64) (*periodPoint, error)
174
171
175
172
// actually no block
176
173
if len (blocks ) == 0 {
177
- return self .emptyPoint (height , & stime , & etime , endSnapshotBlock )
174
+ return self .emptyPoint (index , & stime , & etime , endSnapshotBlock )
178
175
}
179
176
180
- result , err := self .snapshot .ElectionIndex (height )
177
+ result , err := self .snapshot .ElectionIndex (index )
181
178
if err != nil {
182
179
return nil , err
183
180
}
184
181
185
- return self .genPeriodPoint (height , & stime , & etime , endSnapshotBlock , blocks , result )
182
+ return self .genPeriodPoint (index , & stime , & etime , endSnapshotBlock , blocks , result )
186
183
}
187
184
188
185
func (self * periodLinkedArray ) checkValid (point * periodPoint ) bool {
@@ -211,7 +208,7 @@ func (self *periodLinkedArray) checkValid(point *periodPoint) bool {
211
208
return false
212
209
}
213
210
214
- func (self * periodLinkedArray ) emptyPoint (height uint64 , stime , etime * time.Time , endSnapshotBlock * ledger.SnapshotBlock ) (* periodPoint , error ) {
211
+ func (self * periodLinkedArray ) emptyPoint (index uint64 , stime , etime * time.Time , endSnapshotBlock * ledger.SnapshotBlock ) (* periodPoint , error ) {
215
212
point := & periodPoint {}
216
213
point .stime = stime
217
214
point .etime = etime
@@ -228,7 +225,7 @@ func (self *periodLinkedArray) emptyPoint(height uint64, stime, etime *time.Time
228
225
}
229
226
return point , nil
230
227
}
231
- func (self * periodLinkedArray ) genPeriodPoint (height uint64 , stime * time.Time , etime * time.Time , endSnapshot * ledger.SnapshotBlock , blocks []* ledger.SnapshotBlock , result * electionResult ) (* periodPoint , error ) {
228
+ func (self * periodLinkedArray ) genPeriodPoint (index uint64 , stime * time.Time , etime * time.Time , endSnapshot * ledger.SnapshotBlock , blocks []* ledger.SnapshotBlock , result * electionResult ) (* periodPoint , error ) {
232
229
point := & periodPoint {}
233
230
point .stime = stime
234
231
point .etime = etime
0 commit comments