@@ -20,8 +20,8 @@ import (
2020// sequence numbers. It also will provide the capability
2121// to signal whenever expected block has arrived.
2222type PayloadsBuffer interface {
23- // Adds new block into the buffer
24- Push (payload * proto.Payload )
23+ // Adds new block into the buffer, returns true if added
24+ Push (payload * proto.Payload ) bool
2525
2626 // Returns next expected sequence number
2727 Next () uint64
@@ -73,16 +73,16 @@ func (b *PayloadsBufferImpl) Ready() chan struct{} {
7373// Push new payload into the buffer structure in case new arrived payload
7474// sequence number is below the expected next block number payload will be
7575// thrown away.
76- // TODO return bool to indicate if payload was added or not, so that caller can log result .
77- func (b * PayloadsBufferImpl ) Push (payload * proto.Payload ) {
76+ // Returns true if payload was added, false otherwise .
77+ func (b * PayloadsBufferImpl ) Push (payload * proto.Payload ) bool {
7878 b .mutex .Lock ()
7979 defer b .mutex .Unlock ()
8080
8181 seqNum := payload .SeqNum
8282
8383 if seqNum < b .next || b .buf [seqNum ] != nil {
8484 b .logger .Debugf ("Payload with sequence number = %d has been already processed" , payload .SeqNum )
85- return
85+ return false
8686 }
8787
8888 b .buf [seqNum ] = payload
@@ -91,6 +91,7 @@ func (b *PayloadsBufferImpl) Push(payload *proto.Payload) {
9191 if seqNum == b .next && len (b .readyChan ) == 0 {
9292 b .readyChan <- struct {}{}
9393 }
94+ return true
9495}
9596
9697// Next function provides the number of the next expected block
@@ -153,9 +154,10 @@ type metricsBuffer struct {
153154 chainID string
154155}
155156
156- func (mb * metricsBuffer ) Push (payload * proto.Payload ) {
157- mb .PayloadsBuffer .Push (payload )
157+ func (mb * metricsBuffer ) Push (payload * proto.Payload ) bool {
158+ res := mb .PayloadsBuffer .Push (payload )
158159 mb .reportSize ()
160+ return res
159161}
160162
161163func (mb * metricsBuffer ) Pop () * proto.Payload {
0 commit comments