| 71 | } |
| 72 | |
| 73 | func (c *Chain) fetchBlockByCount(count uint32) (b *types.BPBlock, height uint32, err error) { |
| 74 | var node = c.head().ancestorByCount(count) |
| 75 | // Not found |
| 76 | if node == nil { |
| 77 | return |
| 78 | } |
| 79 | // OK, and block is cached |
| 80 | if b = node.load(); b != nil { |
| 81 | height = node.height |
| 82 | return |
| 83 | } |
| 84 | // Not cached, read from database |
| 85 | if b, err = c.loadBlock(node.hash); err != nil { |
| 86 | return |
| 87 | } |
| 88 | height = node.height |
| 89 | return |
| 90 | } |
| 91 | |
| 92 | func (c *Chain) nextNonce(addr proto.AccountAddress) (n pi.AccountNonce, err error) { |
| 93 | c.RLock() |