@@ -18,13 +18,18 @@ import (
1818 "github.com/code-payments/code-vm-indexer/data/ram"
1919)
2020
21+ const (
22+ confirmationsToFinalization = 32
23+ )
24+
2125type 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
2833}
2934
3035type MemoryAccountWithDataUpdateHandler struct {
@@ -301,19 +306,28 @@ func (h *MemoryAccountWithDataUpdateHandler) onStateObserved(ctx context.Context
301306
302307 var dbUpdate * cachedVirtualAccount
303308 if isInitialized {
309+ var isSlotAdvanced bool
304310 if cachedVirtualAccountState .IsInitialized &&
305311 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
309322 }
310323
311324 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 ,
317331 }
318332 } else {
319333 if ! cachedVirtualAccountState .IsInitialized {
0 commit comments