shouldCutHead checks whether the head block should be cut and returns the reason(s). Caller must hold blocksMtx.
(immediate bool)
| 501 | // shouldCutHead checks whether the head block should be cut and returns the |
| 502 | // reason(s). Caller must hold blocksMtx. |
| 503 | func (i *instance) shouldCutHead(immediate bool) cutReason { |
| 504 | hb := i.blocks.Load().headBlock |
| 505 | if hb == nil || hb.DataLength() == 0 { |
| 506 | return cutReasonNone |
| 507 | } |
| 508 | |
| 509 | var reason cutReason |
| 510 | |
| 511 | if immediate { |
| 512 | reason |= cutReasonImmediate |
| 513 | } |
| 514 | if time.Since(i.lastCutTime) >= i.Cfg.MaxBlockDuration { |
| 515 | reason |= cutReasonMaxBlockDuration |
| 516 | } |
| 517 | if hb.DataLength() >= i.Cfg.MaxBlockBytes { |
| 518 | reason |= cutReasonMaxBlockBytes |
| 519 | } |
| 520 | |
| 521 | return reason |
| 522 | } |
| 523 | |
| 524 | func recordBlockCutMetric(reason cutReason) { |
| 525 | if reason&cutReasonImmediate != 0 { |