@@ -18,13 +18,18 @@ import (
18
18
"github.com/code-payments/code-vm-indexer/data/ram"
19
19
)
20
20
21
+ const (
22
+ confirmationsToFinalization = 32
23
+ )
24
+
21
25
type cachedVirtualAccount struct {
22
- IsInitialized bool
23
- Index int
24
- Type cvm.VirtualAccountType
25
- Address string
26
- State []byte
27
- Slot uint64
26
+ IsInitialized bool
27
+ Index int
28
+ Type cvm.VirtualAccountType
29
+ Address string
30
+ State []byte
31
+ Slot uint64
32
+ IsSlotAdvanced bool
28
33
}
29
34
30
35
type MemoryAccountWithDataUpdateHandler struct {
@@ -301,19 +306,28 @@ func (h *MemoryAccountWithDataUpdateHandler) onStateObserved(ctx context.Context
301
306
302
307
var dbUpdate * cachedVirtualAccount
303
308
if isInitialized {
309
+ var isSlotAdvanced bool
304
310
if cachedVirtualAccountState .IsInitialized &&
305
311
cachedVirtualAccountState .Address == base58VirtualAccountAddress &&
306
- bytes .Equal (cachedVirtualAccountState .State , newVirtualAccountState ) &&
307
- observedAtSlot - cachedVirtualAccountState .Slot < 100 { // todo: configurable?
308
- continue
312
+ bytes .Equal (cachedVirtualAccountState .State , newVirtualAccountState ) {
313
+
314
+ if cachedVirtualAccountState .IsSlotAdvanced || observedAtSlot - cachedVirtualAccountState .Slot < 2 * confirmationsToFinalization {
315
+ continue
316
+ }
317
+
318
+ // Advance the slot sufficiently far past finalization if it hasn't
319
+ // already been advanced. This is necessary for systems that rely on
320
+ // finalized states via the RPC service.
321
+ isSlotAdvanced = true
309
322
}
310
323
311
324
dbUpdate = & cachedVirtualAccount {
312
- IsInitialized : true ,
313
- Index : index ,
314
- Type : virtualAccountType ,
315
- Address : base58VirtualAccountAddress ,
316
- State : newVirtualAccountState ,
325
+ IsInitialized : true ,
326
+ Index : index ,
327
+ Type : virtualAccountType ,
328
+ Address : base58VirtualAccountAddress ,
329
+ State : newVirtualAccountState ,
330
+ IsSlotAdvanced : isSlotAdvanced ,
317
331
}
318
332
} else {
319
333
if ! cachedVirtualAccountState .IsInitialized {
0 commit comments