github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/model/chainsync/status.go (about) 1 package chainsync 2 3 import ( 4 "time" 5 6 "github.com/onflow/flow-go/model/flow" 7 ) 8 9 // Status keeps track of a block download status. 10 type Status struct { 11 BlockHeight uint64 // always present even if we haven't received the header 12 Queued time.Time // when we originally queued this block request 13 Requested time.Time // the last time we requested this block 14 Attempts uint // how many times we've requested this block 15 Header *flow.Header // the requested header, if we've received it 16 Received time.Time // when we received a response 17 } 18 19 func (s *Status) WasQueued() bool { 20 return s != nil 21 } 22 23 func (s *Status) WasRequested() bool { 24 if s == nil { 25 return false 26 } 27 return !s.Requested.IsZero() 28 } 29 30 func (s *Status) WasReceived() bool { 31 if s == nil { 32 return false 33 } 34 return !s.Received.IsZero() 35 } 36 37 func (s *Status) StatusString() string { 38 if s.WasReceived() { 39 return "Received" 40 } else if s.WasRequested() { 41 return "Requested" 42 } else if s.WasQueued() { 43 return "Queued" 44 } else { 45 return "Unknown" 46 } 47 } 48 49 func NewQueuedStatus(height uint64) *Status { 50 return &Status{ 51 BlockHeight: height, 52 Queued: time.Now(), 53 } 54 }