Skip to content

Commit

Permalink
WarpySyncer: store last synced block timestamp in database
Browse files Browse the repository at this point in the history
  • Loading branch information
asiaziola committed Apr 12, 2024
1 parent 5d5c70f commit aa49bdb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/warpy_sync/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Store struct {
savedLastSyncedBlockHeight uint64
lastSyncedBlockHeight uint64
lastSyncedBlockHash string
lastSyncedBlockTimestamp uint64
syncedComponent model.SyncedComponent
}

Expand Down Expand Up @@ -61,6 +62,7 @@ func (self *Store) WithSyncedComponent(syncedComponent model.SyncedComponent) *S
func (self *Store) process(payload *LastSyncedBlockPayload) (out []*LastSyncedBlockPayload, err error) {
self.lastSyncedBlockHeight = payload.Height
self.lastSyncedBlockHash = payload.Hash
self.lastSyncedBlockTimestamp = payload.Timestamp
return
}

Expand Down Expand Up @@ -111,8 +113,9 @@ func (self *Store) updateLastSyncedHeight(tx *gorm.DB) (err error) {
Name: self.syncedComponent,
}).
Updates(model.State{
FinishedBlockHeight: uint64(self.lastSyncedBlockHeight),
FinishedBlockHash: arweave.Base64String(self.lastSyncedBlockHash),
FinishedBlockHeight: self.lastSyncedBlockHeight,
FinishedBlockHash: arweave.Base64String(self.lastSyncedBlockHash),
FinishedBlockTimestamp: self.lastSyncedBlockTimestamp,
}).
Error
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions src/warpy_sync/syncer_delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ func (self *SyncerDelta) run() (err error) {
case <-self.Ctx.Done():
return nil
case self.Output <- &LastSyncedBlockPayload{
Height: block.Height,
Hash: block.Hash,
Height: block.Height,
Hash: block.Hash,
Timestamp: block.Timestamp,
}:
}

Expand Down
5 changes: 3 additions & 2 deletions src/warpy_sync/syncer_sommelier.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ func (self *SyncerSommelier) run() (err error) {
case <-self.Ctx.Done():
return nil
case self.Output <- &LastSyncedBlockPayload{
Height: block.Height,
Hash: block.Hash,
Height: block.Height,
Hash: block.Hash,
Timestamp: block.Timestamp,
}:
}

Expand Down
5 changes: 3 additions & 2 deletions src/warpy_sync/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type BlockInfoPayload struct {
}

type LastSyncedBlockPayload struct {
Height uint64
Hash string
Height uint64
Hash string
Timestamp uint64
}

type InteractionPayload struct {
Expand Down

0 comments on commit aa49bdb

Please sign in to comment.