We were ignoring quite a few error cases, and had one case where we weren't actually updating state where we wanted to. Unfortunately, if the linter doesn't pass, nobody has any reason to actually check lint failures in CI. There are three remaining XXXs marked in the code for lint.
		
			
				
	
	
		
			48 lines
		
	
	
		
			696 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			696 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package stats
 | |
| 
 | |
| import (
 | |
| 	"container/list"
 | |
| 
 | |
| 	"github.com/filecoin-project/lotus/api"
 | |
| )
 | |
| 
 | |
| type headBuffer struct {
 | |
| 	buffer *list.List
 | |
| 	size   int
 | |
| }
 | |
| 
 | |
| func newHeadBuffer(size int) *headBuffer {
 | |
| 	buffer := list.New()
 | |
| 	buffer.Init()
 | |
| 
 | |
| 	return &headBuffer{
 | |
| 		buffer: buffer,
 | |
| 		size:   size,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (h *headBuffer) push(hc *api.HeadChange) (rethc *api.HeadChange) {
 | |
| 	if h.buffer.Len() == h.size {
 | |
| 		var ok bool
 | |
| 
 | |
| 		el := h.buffer.Front()
 | |
| 		rethc, ok = el.Value.(*api.HeadChange)
 | |
| 		if !ok {
 | |
| 			panic("Value from list is not the correct type")
 | |
| 		}
 | |
| 
 | |
| 		h.buffer.Remove(el)
 | |
| 	}
 | |
| 
 | |
| 	h.buffer.PushBack(hc)
 | |
| 
 | |
| 	return
 | |
| }
 | |
| 
 | |
| func (h *headBuffer) pop() {
 | |
| 	el := h.buffer.Back()
 | |
| 	if el != nil {
 | |
| 		h.buffer.Remove(el)
 | |
| 	}
 | |
| }
 |