/
storage.go
584 lines (468 loc) · 21.2 KB
/
storage.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
package fcob
import (
"sync"
"time"
"github.com/cockroachdb/errors"
"github.com/iotaledger/hive.go/byteutils"
"github.com/iotaledger/hive.go/cerrors"
"github.com/iotaledger/hive.go/kvstore"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/hive.go/stringify"
"github.com/iotaledger/goshimmer/packages/clock"
"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/goshimmer/packages/tangle"
"github.com/iotaledger/goshimmer/packages/vote/opinion"
)
// region Storage //////////////////////////////////////////////////////////////////////////////////////////////////////
// Storage is a component of the ConsensusMechanism that encapsulates the Storage related methods.
type Storage struct {
store kvstore.KVStore
opinionStorage *objectstorage.ObjectStorage
timestampOpinionStorage *objectstorage.ObjectStorage
messageMetadataStorage *objectstorage.ObjectStorage
}
// NewStorage is the constructor for a Storage.
func NewStorage(store kvstore.KVStore, cacheProvider *database.CacheTimeProvider) (storage *Storage) {
osFactory := objectstorage.NewFactory(store, database.PrefixFCOB)
storage = &Storage{
store: store,
opinionStorage: osFactory.New(PrefixOpinion, OpinionFromObjectStorage, cacheProvider.CacheTime(cacheTime), objectstorage.LeakDetectionEnabled(false)),
timestampOpinionStorage: osFactory.New(PrefixTimestampOpinion, TimestampOpinionFromObjectStorage, cacheProvider.CacheTime(cacheTime), objectstorage.LeakDetectionEnabled(false)),
messageMetadataStorage: osFactory.New(PrefixMessageMetadata, MessageMetadataFromObjectStorage, cacheProvider.CacheTime(cacheTime), objectstorage.LeakDetectionEnabled(false)),
}
genesis := NewMessageMetadata(tangle.EmptyMessageID)
genesis.SetMessageOpinionFormed(true)
genesis.SetMessageOpinionTriggered(true)
genesis.SetPayloadOpinionFormed(true)
genesis.SetTimestampOpinionFormed(true)
storage.StoreMessageMetadata(genesis)
return
}
// OpinionEssence returns the OpinionEssence (i.e., a copy of the triple{timestamp, liked, levelOfKnowledge})
// of given transactionID.
func (s *Storage) OpinionEssence(transactionID ledgerstate.TransactionID) (opinion OpinionEssence) {
(&CachedOpinion{CachedObject: s.opinionStorage.Load(transactionID.Bytes())}).Consume(func(storedOpinion *Opinion) {
opinion = storedOpinion.OpinionEssence
})
return
}
// Opinion returns the Opinion associated with given TransactionID.
func (s *Storage) Opinion(transactionID ledgerstate.TransactionID) (cachedOpinion *CachedOpinion) {
return &CachedOpinion{CachedObject: s.opinionStorage.Load(transactionID.Bytes())}
}
// TimestampOpinion returns the TimestampOpinion associated with given MessageID.
func (s *Storage) TimestampOpinion(messageID tangle.MessageID) (cachedTimestampOpinion *CachedTimestampOpinion) {
return &CachedTimestampOpinion{CachedObject: s.timestampOpinionStorage.Load(messageID.Bytes())}
}
// MessageMetadata returns the MessageMetadata associated with given MessageID.
func (s *Storage) MessageMetadata(messageID tangle.MessageID) (cachedMessageMetadata *CachedMessageMetadata) {
return &CachedMessageMetadata{CachedObject: s.messageMetadataStorage.Load(messageID.Bytes())}
}
// StoreTimestampOpinion stores the TimestampOpinion in the object Storage. It returns true if it was stored or updated.
func (s *Storage) StoreTimestampOpinion(timestampOpinion *TimestampOpinion) (stored bool) {
cachedTimestampOpinion, stored := s.timestampOpinionStorage.StoreIfAbsent(timestampOpinion)
if stored {
cachedTimestampOpinion.Release()
return
}
return
}
// StoreMessageMetadata stores the MessageMetadata in the object Storage. It returns true if it was stored or updated.
func (s *Storage) StoreMessageMetadata(messageMetadata *MessageMetadata) (stored bool) {
cachedMessageMetadata, stored := s.messageMetadataStorage.StoreIfAbsent(messageMetadata)
if stored {
cachedMessageMetadata.Release()
return
}
return
}
// Shutdown shuts down the Storage and causes its content to be persisted to the disk.
func (s *Storage) Shutdown() {
s.opinionStorage.Shutdown()
s.timestampOpinionStorage.Shutdown()
s.messageMetadataStorage.Shutdown()
}
// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// region Object Storage Parameters ////////////////////////////////////////////////////////////////////////////////////
const (
// PrefixOpinion defines the Storage prefix for the opinion Storage.
PrefixOpinion byte = iota
// PrefixTimestampOpinion defines the Storage prefix for the timestamp opinion Storage.
PrefixTimestampOpinion
// PrefixMessageMetadata defines the Storage prefix for the MessageMetadata Storage.
PrefixMessageMetadata
// cacheTime defines the duration that the object Storage caches objects.
cacheTime = 1 * time.Second
)
// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// region MessageMetadata //////////////////////////////////////////////////////////////////////////////////////////////
// MessageMetadata defines the metadata for a message.
type MessageMetadata struct {
id tangle.MessageID
payloadOpinionFormed bool
payloadOpinionFormedMutex sync.RWMutex
timestampOpinionFormed bool
timestampOpinionFormedMutex sync.RWMutex
messageOpinionFormed bool
messageOpinionFormedMutex sync.RWMutex
messageOpinionTriggered bool
messageOpinionTriggeredMutex sync.RWMutex
opinionFormedTime time.Time
opinionFormedTimeMutex sync.RWMutex
objectstorage.StorableObjectFlags
}
// MessageMetadataFromBytes unmarshals a MessageMetadata object from a sequence of bytes.
func MessageMetadataFromBytes(bytes []byte) (messageMetadata *MessageMetadata, consumedBytes int, err error) {
marshalUtil := marshalutil.New(bytes)
if messageMetadata, err = MessageMetadataFromMarshalUtil(marshalUtil); err != nil {
err = errors.Errorf("failed to parse MessageMetadata from MarshalUtil: %w", err)
return
}
consumedBytes = marshalUtil.ReadOffset()
return
}
// MessageMetadataFromMarshalUtil unmarshals a MessageMetadata object using a MarshalUtil (for easier unmarshaling).
func MessageMetadataFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (messageMetadata *MessageMetadata, err error) {
messageMetadata = &MessageMetadata{}
if messageMetadata.id, err = tangle.MessageIDFromMarshalUtil(marshalUtil); err != nil {
err = errors.Errorf("failed to parse MessageID: %w", err)
return
}
if messageMetadata.payloadOpinionFormed, err = marshalUtil.ReadBool(); err != nil {
err = errors.Errorf("failed to parse payloadOpinionFormed flag (%v): %w", err, cerrors.ErrParseBytesFailed)
return
}
if messageMetadata.timestampOpinionFormed, err = marshalUtil.ReadBool(); err != nil {
err = errors.Errorf("failed to parse timestampOpinionFormed flag (%v): %w", err, cerrors.ErrParseBytesFailed)
return
}
if messageMetadata.messageOpinionFormed, err = marshalUtil.ReadBool(); err != nil {
err = errors.Errorf("failed to parse messageOpinionFormed flag (%v): %w", err, cerrors.ErrParseBytesFailed)
return
}
if messageMetadata.messageOpinionTriggered, err = marshalUtil.ReadBool(); err != nil {
err = errors.Errorf("failed to parse messageOpinionTriggered flag (%v): %w", err, cerrors.ErrParseBytesFailed)
return
}
if messageMetadata.opinionFormedTime, err = marshalUtil.ReadTime(); err != nil {
err = errors.Errorf("failed to parse opinionFormedTime (%v): %w", err, cerrors.ErrParseBytesFailed)
return
}
return
}
// MessageMetadataFromObjectStorage restores a MessageMetadata object from the object Storage.
func MessageMetadataFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error) {
if result, _, err = MessageMetadataFromBytes(byteutils.ConcatBytes(key, data)); err != nil {
err = errors.Errorf("failed to parse MessageMetadata from bytes: %w", err)
return
}
return
}
// NewMessageMetadata is the constructor of the MessageMetadata object.
func NewMessageMetadata(messageID tangle.MessageID) *MessageMetadata {
return &MessageMetadata{
id: messageID,
}
}
// ID returns the MessageID that this MessageMetadata object belongs to.
func (m *MessageMetadata) ID() tangle.MessageID {
return m.id
}
// PayloadOpinionFormed returns the payloadOpinionFormed flag of the MessageMetadata.
func (m *MessageMetadata) PayloadOpinionFormed() bool {
m.payloadOpinionFormedMutex.RLock()
defer m.payloadOpinionFormedMutex.RUnlock()
return m.payloadOpinionFormed
}
// SetPayloadOpinionFormed sets the payloadOpinionFormed flag to the given value. It returns true if the value has been
// updated.
func (m *MessageMetadata) SetPayloadOpinionFormed(payloadOpinionFormed bool) (modified bool) {
m.payloadOpinionFormedMutex.Lock()
defer m.payloadOpinionFormedMutex.Unlock()
if m.payloadOpinionFormed == payloadOpinionFormed {
return
}
m.payloadOpinionFormed = payloadOpinionFormed
modified = true
m.SetModified()
return
}
// TimestampOpinionFormed returns the timestampOpinionFormed flag of the MessageMetadata.
func (m *MessageMetadata) TimestampOpinionFormed() bool {
m.timestampOpinionFormedMutex.RLock()
defer m.timestampOpinionFormedMutex.RUnlock()
return m.timestampOpinionFormed
}
// SetTimestampOpinionFormed sets the timestampOpinionFormed flag to the given value. It returns true if the value has
// been updated.
func (m *MessageMetadata) SetTimestampOpinionFormed(timestampOpinionFormed bool) (modified bool) {
m.timestampOpinionFormedMutex.Lock()
defer m.timestampOpinionFormedMutex.Unlock()
if m.timestampOpinionFormed == timestampOpinionFormed {
return
}
m.timestampOpinionFormed = timestampOpinionFormed
modified = true
m.SetModified()
return
}
// OpinionFormedTime returns the opinionFormed time of the MessageMetadata.
func (m *MessageMetadata) OpinionFormedTime() time.Time {
m.opinionFormedTimeMutex.RLock()
defer m.opinionFormedTimeMutex.RUnlock()
return m.opinionFormedTime
}
// MessageOpinionFormed returns the messageOpinionFormed flag of the MessageMetadata.
func (m *MessageMetadata) MessageOpinionFormed() bool {
m.messageOpinionFormedMutex.RLock()
defer m.messageOpinionFormedMutex.RUnlock()
return m.messageOpinionFormed
}
// SetMessageOpinionFormed sets the messageOpinionFormed flag to the given value. It returns true if the value has been
// updated.
func (m *MessageMetadata) SetMessageOpinionFormed(messageOpinionFormed bool) (modified bool) {
m.messageOpinionFormedMutex.Lock()
defer m.messageOpinionFormedMutex.Unlock()
m.opinionFormedTimeMutex.Lock()
defer m.opinionFormedTimeMutex.Unlock()
if m.messageOpinionFormed == messageOpinionFormed {
return
}
m.messageOpinionFormed = messageOpinionFormed
m.opinionFormedTime = clock.SyncedTime()
modified = true
m.SetModified()
return
}
// MessageOpinionTriggered returns the messageOpinionTriggered flag of the MessageMetadata.
func (m *MessageMetadata) MessageOpinionTriggered() bool {
m.messageOpinionTriggeredMutex.RLock()
defer m.messageOpinionTriggeredMutex.RUnlock()
return m.messageOpinionTriggered
}
// SetMessageOpinionTriggered sets the messageOpinionTriggered flag to the given value. It returns true if the value has been
// updated.
func (m *MessageMetadata) SetMessageOpinionTriggered(messageOpinionTriggered bool) (modified bool) {
m.messageOpinionTriggeredMutex.Lock()
defer m.messageOpinionTriggeredMutex.Unlock()
if m.messageOpinionTriggered == messageOpinionTriggered {
return
}
m.messageOpinionTriggered = messageOpinionTriggered
modified = true
m.SetModified()
return
}
// Bytes returns a marshaled version of the MessageMetadata.
func (m *MessageMetadata) Bytes() []byte {
return byteutils.ConcatBytes(m.ObjectStorageKey(), m.ObjectStorageValue())
}
// String returns a human readable version of the MessageMetadata.
func (m *MessageMetadata) String() string {
return stringify.Struct("MessageMetadata",
stringify.StructField("payloadOpinionFormed", m.ID().String()),
stringify.StructField("payloadOpinionFormed", m.PayloadOpinionFormed()),
stringify.StructField("timestampOpinionFormed", m.TimestampOpinionFormed()),
stringify.StructField("messageOpinionFormed", m.MessageOpinionFormed()),
stringify.StructField("messageOpinionTriggered", m.MessageOpinionTriggered()),
stringify.StructField("opinionFormedTime", m.OpinionFormedTime()),
)
}
// Update is disabled and panics if it ever gets called - it is required to match the StorableObject interface.
func (m *MessageMetadata) Update(objectstorage.StorableObject) {
panic("updates disabled")
}
// ObjectStorageKey returns the key that is used to store the object in the database. It is required to match the
// StorableObject interface.
func (m *MessageMetadata) ObjectStorageKey() []byte {
return m.id.Bytes()
}
// ObjectStorageValue marshals the MessageMetadata into a sequence of bytes that are used as the value part in the
// object Storage.
func (m *MessageMetadata) ObjectStorageValue() []byte {
return marshalutil.New(4*marshalutil.BoolSize + marshalutil.TimeSize).
WriteBool(m.PayloadOpinionFormed()).
WriteBool(m.TimestampOpinionFormed()).
WriteBool(m.MessageOpinionFormed()).
WriteBool(m.MessageOpinionTriggered()).
WriteTime(m.OpinionFormedTime()).
Bytes()
}
// code contract (make sure the struct implements all required methods)
var _ objectstorage.StorableObject = &MessageMetadata{}
// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// region CachedMessageMetadata ////////////////////////////////////////////////////////////////////////////////////////
// CachedMessageMetadata is a wrapper for the generic CachedObject returned by the object Storage that overrides the
// accessor methods with a type-casted one.
type CachedMessageMetadata struct {
objectstorage.CachedObject
}
// ID returns the MessageID of the requested MessageMetadata.
func (c *CachedMessageMetadata) ID() (messageID tangle.MessageID) {
messageID, _, err := tangle.MessageIDFromBytes(c.Key())
if err != nil {
panic(err)
}
return
}
// Retain marks the CachedObject to still be in use by the program.
func (c *CachedMessageMetadata) Retain() *CachedMessageMetadata {
return &CachedMessageMetadata{c.CachedObject.Retain()}
}
// Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.
func (c *CachedMessageMetadata) Unwrap() *MessageMetadata {
untypedObject := c.Get()
if untypedObject == nil {
return nil
}
typedObject := untypedObject.(*MessageMetadata)
if typedObject == nil || typedObject.IsDeleted() {
return nil
}
return typedObject
}
// Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it
// exists). It automatically releases the object when the consumer finishes.
func (c *CachedMessageMetadata) Consume(consumer func(messageMetadata *MessageMetadata), forceRelease ...bool) (consumed bool) {
return c.CachedObject.Consume(func(object objectstorage.StorableObject) {
consumer(object.(*MessageMetadata))
}, forceRelease...)
}
// String returns a human readable version of the CachedMessageMetadata.
func (c *CachedMessageMetadata) String() string {
return stringify.Struct("CachedMessageMetadata",
stringify.StructField("CachedObject", c.Unwrap()),
)
}
// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// region TimestampOpinion /////////////////////////////////////////////////////////////////////////////////////////////
const (
// TimestampOpinionLength defines the length of a TimestampOpinion object (1 byte of opinion, 1 byte of LoK).
TimestampOpinionLength = tangle.MessageIDLength + 2
)
// TimestampOpinion contains the value of a timestamp opinion as well as its level of knowledge.
type TimestampOpinion struct {
MessageID tangle.MessageID
Value opinion.Opinion
LoK LevelOfKnowledge
objectstorage.StorableObjectFlags
}
// TimestampOpinionFromBytes parses a TimestampOpinion from a byte slice.
func TimestampOpinionFromBytes(bytes []byte) (timestampOpinion *TimestampOpinion, consumedBytes int, err error) {
marshalUtil := marshalutil.New(bytes)
if timestampOpinion, err = TimestampOpinionFromMarshalUtil(marshalUtil); err != nil {
err = errors.Errorf("failed to parse TimestampOpinion from MarshalUtil: %w", err)
return
}
consumedBytes = marshalUtil.ReadOffset()
return
}
// TimestampOpinionFromMarshalUtil is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.
func TimestampOpinionFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *TimestampOpinion, err error) {
readStartOffset := marshalUtil.ReadOffset()
// read information that are required to identify the TimestampOpinion
result = &TimestampOpinion{}
if result.MessageID, err = tangle.MessageIDFromMarshalUtil(marshalUtil); err != nil {
err = errors.Errorf("failed to parse MessageID from MarshalUtil: %w", err)
return
}
opinionByte, e := marshalUtil.ReadByte()
if e != nil {
err = errors.Errorf("failed to parse opinion from bytes: %w", e)
return
}
result.Value = opinion.Opinion(opinionByte)
loKUint8, err := marshalUtil.ReadUint8()
if err != nil {
err = errors.Errorf("failed to parse Level of Knowledge from bytes: %w", err)
return
}
result.LoK = LevelOfKnowledge(loKUint8)
// return the number of bytes we processed
parsedBytes := marshalUtil.ReadOffset() - readStartOffset
if parsedBytes != TimestampOpinionLength {
err = errors.Errorf("parsed bytes (%d) did not match expected size (%d): %w", parsedBytes, TimestampOpinionLength, cerrors.ErrParseBytesFailed)
return
}
return
}
// TimestampOpinionFromObjectStorage restores a TimestampOpinion from the object Storage.
func TimestampOpinionFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error) {
if result, _, err = TimestampOpinionFromBytes(byteutils.ConcatBytes(key, data)); err != nil {
err = errors.Errorf("failed to parse TimestampOpinion from bytes: %w", err)
return
}
return
}
// Equals returns true if the given timestampOpinion is equal to the given x.
func (t *TimestampOpinion) Equals(x *TimestampOpinion) bool {
return t.MessageID == x.MessageID && t.Value == x.Value && t.LoK == x.LoK
}
// Bytes returns the timestamp statement encoded as bytes.
func (t *TimestampOpinion) Bytes() (bytes []byte) {
return byteutils.ConcatBytes(t.ObjectStorageKey(), t.ObjectStorageValue())
}
// String returns a human readable version of the TimestampOpinion.
func (t *TimestampOpinion) String() string {
return stringify.Struct("TimestampOpinion",
stringify.StructField("MessageID", t.MessageID),
stringify.StructField("Value", t.Value),
stringify.StructField("LoK", t.LoK),
)
}
// Update is disabled and panics if it ever gets called - it is required to match the StorableObject interface.
func (t *TimestampOpinion) Update(objectstorage.StorableObject) {
panic("updates disabled")
}
// ObjectStorageKey returns the key that is used to store the object in the database. It is required to match the
// StorableObject interface.
func (t *TimestampOpinion) ObjectStorageKey() []byte {
return t.MessageID.Bytes()
}
// ObjectStorageValue marshals the TimestampOpinion into a sequence of bytes that are used as the value part in the
// object Storage.
func (t *TimestampOpinion) ObjectStorageValue() []byte {
return marshalutil.New(2).
WriteByte(byte(t.Value)).
WriteUint8(uint8(t.LoK)).
Bytes()
}
// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// region CachedTimestampOpinion ///////////////////////////////////////////////////////////////////////////////////////
// CachedTimestampOpinion is a wrapper for the generic CachedObject returned by the object Storage that overrides the accessor
// methods with a type-casted one.
type CachedTimestampOpinion struct {
objectstorage.CachedObject
}
// Retain marks the CachedObject to still be in use by the program.
func (c *CachedTimestampOpinion) Retain() *CachedTimestampOpinion {
return &CachedTimestampOpinion{c.CachedObject.Retain()}
}
// Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.
func (c *CachedTimestampOpinion) Unwrap() *TimestampOpinion {
untypedObject := c.Get()
if untypedObject == nil {
return nil
}
typedObject := untypedObject.(*TimestampOpinion)
if typedObject == nil || typedObject.IsDeleted() {
return nil
}
return typedObject
}
// Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it
// exists). It automatically releases the object when the consumer finishes.
func (c *CachedTimestampOpinion) Consume(consumer func(timestampOpinion *TimestampOpinion), forceRelease ...bool) (consumed bool) {
return c.CachedObject.Consume(func(object objectstorage.StorableObject) {
consumer(object.(*TimestampOpinion))
}, forceRelease...)
}
// String returns a human readable version of the CachedTimestampOpinion.
func (c *CachedTimestampOpinion) String() string {
return stringify.Struct("CachedTimestampOpinion",
stringify.StructField("CachedObject", c.Unwrap()),
)
}
// endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////