You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

633 lines
20 KiB

7 years ago
7 years ago
7 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package evidence
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "sync"
  7. "sync/atomic"
  8. "time"
  9. "github.com/gogo/protobuf/proto"
  10. gogotypes "github.com/gogo/protobuf/types"
  11. "github.com/google/orderedcode"
  12. dbm "github.com/tendermint/tm-db"
  13. clist "github.com/tendermint/tendermint/internal/libs/clist"
  14. sm "github.com/tendermint/tendermint/internal/state"
  15. "github.com/tendermint/tendermint/libs/log"
  16. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  17. "github.com/tendermint/tendermint/types"
  18. )
  19. const (
  20. // prefixes are unique across all tm db's
  21. prefixCommitted = int64(9)
  22. prefixPending = int64(10)
  23. )
  24. // Pool maintains a pool of valid evidence to be broadcasted and committed
  25. type Pool struct {
  26. logger log.Logger
  27. evidenceStore dbm.DB
  28. evidenceList *clist.CList // concurrent linked-list of evidence
  29. evidenceSize uint32 // amount of pending evidence
  30. // needed to load validators to verify evidence
  31. stateDB sm.Store
  32. // needed to load headers and commits to verify evidence
  33. blockStore BlockStore
  34. mtx sync.Mutex
  35. // latest state
  36. state sm.State
  37. // evidence from consensus is buffered to this slice, awaiting until the next height
  38. // before being flushed to the pool. This prevents broadcasting and proposing of
  39. // evidence before the height with which the evidence happened is finished.
  40. consensusBuffer []duplicateVoteSet
  41. pruningHeight int64
  42. pruningTime time.Time
  43. }
  44. // NewPool creates an evidence pool. If using an existing evidence store,
  45. // it will add all pending evidence to the concurrent list.
  46. func NewPool(logger log.Logger, evidenceDB dbm.DB, stateDB sm.Store, blockStore BlockStore) (*Pool, error) {
  47. state, err := stateDB.Load()
  48. if err != nil {
  49. return nil, fmt.Errorf("failed to load state: %w", err)
  50. }
  51. pool := &Pool{
  52. stateDB: stateDB,
  53. blockStore: blockStore,
  54. state: state,
  55. logger: logger,
  56. evidenceStore: evidenceDB,
  57. evidenceList: clist.New(),
  58. consensusBuffer: make([]duplicateVoteSet, 0),
  59. }
  60. // If pending evidence already in db, in event of prior failure, then check
  61. // for expiration, update the size and load it back to the evidenceList.
  62. pool.pruningHeight, pool.pruningTime = pool.removeExpiredPendingEvidence()
  63. evList, _, err := pool.listEvidence(prefixPending, -1)
  64. if err != nil {
  65. return nil, err
  66. }
  67. atomic.StoreUint32(&pool.evidenceSize, uint32(len(evList)))
  68. for _, ev := range evList {
  69. pool.evidenceList.PushBack(ev)
  70. }
  71. return pool, nil
  72. }
  73. // PendingEvidence is used primarily as part of block proposal and returns up to
  74. // maxNum of uncommitted evidence.
  75. func (evpool *Pool) PendingEvidence(maxBytes int64) ([]types.Evidence, int64) {
  76. if evpool.Size() == 0 {
  77. return []types.Evidence{}, 0
  78. }
  79. evidence, size, err := evpool.listEvidence(prefixPending, maxBytes)
  80. if err != nil {
  81. evpool.logger.Error("failed to retrieve pending evidence", "err", err)
  82. }
  83. return evidence, size
  84. }
  85. // Update takes both the new state and the evidence committed at that height and performs
  86. // the following operations:
  87. // 1. Take any conflicting votes from consensus and use the state's LastBlockTime to form
  88. // DuplicateVoteEvidence and add it to the pool.
  89. // 2. Update the pool's state which contains evidence params relating to expiry.
  90. // 3. Moves pending evidence that has now been committed into the committed pool.
  91. // 4. Removes any expired evidence based on both height and time.
  92. func (evpool *Pool) Update(state sm.State, ev types.EvidenceList) {
  93. // sanity check
  94. if state.LastBlockHeight <= evpool.state.LastBlockHeight {
  95. panic(fmt.Sprintf(
  96. "failed EvidencePool.Update new state height is less than or equal to previous state height: %d <= %d",
  97. state.LastBlockHeight,
  98. evpool.state.LastBlockHeight,
  99. ))
  100. }
  101. evpool.logger.Debug(
  102. "updating evidence pool",
  103. "last_block_height", state.LastBlockHeight,
  104. "last_block_time", state.LastBlockTime,
  105. )
  106. // flush conflicting vote pairs from the buffer, producing DuplicateVoteEvidence and
  107. // adding it to the pool
  108. evpool.processConsensusBuffer(state)
  109. // update state
  110. evpool.updateState(state)
  111. // move committed evidence out from the pending pool and into the committed pool
  112. evpool.markEvidenceAsCommitted(ev, state.LastBlockHeight)
  113. // Prune pending evidence when it has expired. This also updates when the next
  114. // evidence will expire.
  115. if evpool.Size() > 0 && state.LastBlockHeight > evpool.pruningHeight &&
  116. state.LastBlockTime.After(evpool.pruningTime) {
  117. evpool.pruningHeight, evpool.pruningTime = evpool.removeExpiredPendingEvidence()
  118. }
  119. }
  120. // AddEvidence checks the evidence is valid and adds it to the pool.
  121. func (evpool *Pool) AddEvidence(ev types.Evidence) error {
  122. evpool.logger.Debug("attempting to add evidence", "evidence", ev)
  123. // We have already verified this piece of evidence - no need to do it again
  124. if evpool.isPending(ev) {
  125. evpool.logger.Debug("evidence already pending; ignoring", "evidence", ev)
  126. return nil
  127. }
  128. // check that the evidence isn't already committed
  129. if evpool.isCommitted(ev) {
  130. // This can happen if the peer that sent us the evidence is behind so we
  131. // shouldn't punish the peer.
  132. evpool.logger.Debug("evidence was already committed; ignoring", "evidence", ev)
  133. return nil
  134. }
  135. // 1) Verify against state.
  136. if err := evpool.verify(ev); err != nil {
  137. return err
  138. }
  139. // 2) Save to store.
  140. if err := evpool.addPendingEvidence(ev); err != nil {
  141. return fmt.Errorf("failed to add evidence to pending list: %w", err)
  142. }
  143. // 3) Add evidence to clist.
  144. evpool.evidenceList.PushBack(ev)
  145. evpool.logger.Info("verified new evidence of byzantine behavior", "evidence", ev)
  146. return nil
  147. }
  148. // ReportConflictingVotes takes two conflicting votes and forms duplicate vote evidence,
  149. // adding it eventually to the evidence pool.
  150. //
  151. // Duplicate vote attacks happen before the block is committed and the timestamp is
  152. // finalized, thus the evidence pool holds these votes in a buffer, forming the
  153. // evidence from them once consensus at that height has been reached and `Update()` with
  154. // the new state called.
  155. //
  156. // Votes are not verified.
  157. func (evpool *Pool) ReportConflictingVotes(voteA, voteB *types.Vote) {
  158. evpool.mtx.Lock()
  159. defer evpool.mtx.Unlock()
  160. evpool.consensusBuffer = append(evpool.consensusBuffer, duplicateVoteSet{
  161. VoteA: voteA,
  162. VoteB: voteB,
  163. })
  164. }
  165. // CheckEvidence takes an array of evidence from a block and verifies all the evidence there.
  166. // If it has already verified the evidence then it jumps to the next one. It ensures that no
  167. // evidence has already been committed or is being proposed twice. It also adds any
  168. // evidence that it doesn't currently have so that it can quickly form ABCI Evidence later.
  169. func (evpool *Pool) CheckEvidence(evList types.EvidenceList) error {
  170. hashes := make([][]byte, len(evList))
  171. for idx, ev := range evList {
  172. _, isLightEv := ev.(*types.LightClientAttackEvidence)
  173. // We must verify light client attack evidence regardless because there could be a
  174. // different conflicting block with the same hash.
  175. if isLightEv || !evpool.isPending(ev) {
  176. // check that the evidence isn't already committed
  177. if evpool.isCommitted(ev) {
  178. return &types.ErrInvalidEvidence{Evidence: ev, Reason: errors.New("evidence was already committed")}
  179. }
  180. err := evpool.verify(ev)
  181. if err != nil {
  182. return err
  183. }
  184. if err := evpool.addPendingEvidence(ev); err != nil {
  185. // Something went wrong with adding the evidence but we already know it is valid
  186. // hence we log an error and continue
  187. evpool.logger.Error("failed to add evidence to pending list", "err", err, "evidence", ev)
  188. }
  189. evpool.logger.Info("check evidence: verified evidence of byzantine behavior", "evidence", ev)
  190. }
  191. // check for duplicate evidence. We cache hashes so we don't have to work them out again.
  192. hashes[idx] = ev.Hash()
  193. for i := idx - 1; i >= 0; i-- {
  194. if bytes.Equal(hashes[i], hashes[idx]) {
  195. return &types.ErrInvalidEvidence{Evidence: ev, Reason: errors.New("duplicate evidence")}
  196. }
  197. }
  198. }
  199. return nil
  200. }
  201. // EvidenceFront goes to the first evidence in the clist
  202. func (evpool *Pool) EvidenceFront() *clist.CElement {
  203. return evpool.evidenceList.Front()
  204. }
  205. // EvidenceWaitChan is a channel that closes once the first evidence in the list
  206. // is there. i.e Front is not nil.
  207. func (evpool *Pool) EvidenceWaitChan() <-chan struct{} {
  208. return evpool.evidenceList.WaitChan()
  209. }
  210. // Size returns the number of evidence in the pool.
  211. func (evpool *Pool) Size() uint32 {
  212. return atomic.LoadUint32(&evpool.evidenceSize)
  213. }
  214. // State returns the current state of the evpool.
  215. func (evpool *Pool) State() sm.State {
  216. evpool.mtx.Lock()
  217. defer evpool.mtx.Unlock()
  218. return evpool.state
  219. }
  220. // IsExpired checks whether evidence or a polc is expired by checking whether a height and time is older
  221. // than set by the evidence consensus parameters
  222. func (evpool *Pool) isExpired(height int64, time time.Time) bool {
  223. var (
  224. params = evpool.State().ConsensusParams.Evidence
  225. ageDuration = evpool.State().LastBlockTime.Sub(time)
  226. ageNumBlocks = evpool.State().LastBlockHeight - height
  227. )
  228. return ageNumBlocks > params.MaxAgeNumBlocks &&
  229. ageDuration > params.MaxAgeDuration
  230. }
  231. // IsCommitted returns true if we have already seen this exact evidence and it is already marked as committed.
  232. func (evpool *Pool) isCommitted(evidence types.Evidence) bool {
  233. key := keyCommitted(evidence)
  234. ok, err := evpool.evidenceStore.Has(key)
  235. if err != nil {
  236. evpool.logger.Error("failed to find committed evidence", "err", err)
  237. }
  238. return ok
  239. }
  240. // IsPending checks whether the evidence is already pending. DB errors are passed to the logger.
  241. func (evpool *Pool) isPending(evidence types.Evidence) bool {
  242. key := keyPending(evidence)
  243. ok, err := evpool.evidenceStore.Has(key)
  244. if err != nil {
  245. evpool.logger.Error("failed to find pending evidence", "err", err)
  246. }
  247. return ok
  248. }
  249. func (evpool *Pool) addPendingEvidence(ev types.Evidence) error {
  250. evpb, err := types.EvidenceToProto(ev)
  251. if err != nil {
  252. return fmt.Errorf("failed to convert to proto: %w", err)
  253. }
  254. evBytes, err := evpb.Marshal()
  255. if err != nil {
  256. return fmt.Errorf("failed to marshal evidence: %w", err)
  257. }
  258. key := keyPending(ev)
  259. err = evpool.evidenceStore.Set(key, evBytes)
  260. if err != nil {
  261. return fmt.Errorf("failed to persist evidence: %w", err)
  262. }
  263. atomic.AddUint32(&evpool.evidenceSize, 1)
  264. return nil
  265. }
  266. // markEvidenceAsCommitted processes all the evidence in the block, marking it as
  267. // committed and removing it from the pending database.
  268. func (evpool *Pool) markEvidenceAsCommitted(evidence types.EvidenceList, height int64) {
  269. blockEvidenceMap := make(map[string]struct{}, len(evidence))
  270. batch := evpool.evidenceStore.NewBatch()
  271. defer batch.Close()
  272. for _, ev := range evidence {
  273. if evpool.isPending(ev) {
  274. if err := batch.Delete(keyPending(ev)); err != nil {
  275. evpool.logger.Error("failed to batch delete pending evidence", "err", err)
  276. }
  277. blockEvidenceMap[evMapKey(ev)] = struct{}{}
  278. }
  279. // Add evidence to the committed list. As the evidence is stored in the block store
  280. // we only need to record the height that it was saved at.
  281. key := keyCommitted(ev)
  282. h := gogotypes.Int64Value{Value: height}
  283. evBytes, err := proto.Marshal(&h)
  284. if err != nil {
  285. evpool.logger.Error("failed to marshal committed evidence", "key(height/hash)", key, "err", err)
  286. continue
  287. }
  288. if err := evpool.evidenceStore.Set(key, evBytes); err != nil {
  289. evpool.logger.Error("failed to save committed evidence", "key(height/hash)", key, "err", err)
  290. }
  291. evpool.logger.Debug("marked evidence as committed", "evidence", ev)
  292. }
  293. // check if we need to remove any pending evidence
  294. if len(blockEvidenceMap) == 0 {
  295. return
  296. }
  297. // remove committed evidence from pending bucket
  298. if err := batch.WriteSync(); err != nil {
  299. evpool.logger.Error("failed to batch delete pending evidence", "err", err)
  300. return
  301. }
  302. // remove committed evidence from the clist
  303. evpool.removeEvidenceFromList(blockEvidenceMap)
  304. // update the evidence size
  305. atomic.AddUint32(&evpool.evidenceSize, ^uint32(len(blockEvidenceMap)-1))
  306. }
  307. // listEvidence retrieves lists evidence from oldest to newest within maxBytes.
  308. // If maxBytes is -1, there's no cap on the size of returned evidence.
  309. func (evpool *Pool) listEvidence(prefixKey int64, maxBytes int64) ([]types.Evidence, int64, error) {
  310. var (
  311. evSize int64
  312. totalSize int64
  313. evidence []types.Evidence
  314. evList tmproto.EvidenceList // used for calculating the bytes size
  315. )
  316. iter, err := dbm.IteratePrefix(evpool.evidenceStore, prefixToBytes(prefixKey))
  317. if err != nil {
  318. return nil, totalSize, fmt.Errorf("database error: %v", err)
  319. }
  320. defer iter.Close()
  321. for ; iter.Valid(); iter.Next() {
  322. var evpb tmproto.Evidence
  323. if err := evpb.Unmarshal(iter.Value()); err != nil {
  324. return evidence, totalSize, err
  325. }
  326. evList.Evidence = append(evList.Evidence, evpb)
  327. evSize = int64(evList.Size())
  328. if maxBytes != -1 && evSize > maxBytes {
  329. if err := iter.Error(); err != nil {
  330. return evidence, totalSize, err
  331. }
  332. return evidence, totalSize, nil
  333. }
  334. ev, err := types.EvidenceFromProto(&evpb)
  335. if err != nil {
  336. return nil, totalSize, err
  337. }
  338. totalSize = evSize
  339. evidence = append(evidence, ev)
  340. }
  341. if err := iter.Error(); err != nil {
  342. return evidence, totalSize, err
  343. }
  344. return evidence, totalSize, nil
  345. }
  346. func (evpool *Pool) removeExpiredPendingEvidence() (int64, time.Time) {
  347. batch := evpool.evidenceStore.NewBatch()
  348. defer batch.Close()
  349. height, time, blockEvidenceMap := evpool.batchExpiredPendingEvidence(batch)
  350. // if we haven't removed any evidence then return early
  351. if len(blockEvidenceMap) == 0 {
  352. return height, time
  353. }
  354. evpool.logger.Debug("removing expired evidence",
  355. "height", evpool.State().LastBlockHeight,
  356. "time", evpool.State().LastBlockTime,
  357. "expired evidence", len(blockEvidenceMap),
  358. )
  359. // remove expired evidence from pending bucket
  360. if err := batch.WriteSync(); err != nil {
  361. evpool.logger.Error("failed to batch delete pending evidence", "err", err)
  362. return evpool.State().LastBlockHeight, evpool.State().LastBlockTime
  363. }
  364. // remove evidence from the clist
  365. evpool.removeEvidenceFromList(blockEvidenceMap)
  366. // update the evidence size
  367. atomic.AddUint32(&evpool.evidenceSize, ^uint32(len(blockEvidenceMap)-1))
  368. return height, time
  369. }
  370. func (evpool *Pool) batchExpiredPendingEvidence(batch dbm.Batch) (int64, time.Time, map[string]struct{}) {
  371. blockEvidenceMap := make(map[string]struct{})
  372. iter, err := dbm.IteratePrefix(evpool.evidenceStore, prefixToBytes(prefixPending))
  373. if err != nil {
  374. evpool.logger.Error("failed to iterate over pending evidence", "err", err)
  375. return evpool.State().LastBlockHeight, evpool.State().LastBlockTime, blockEvidenceMap
  376. }
  377. defer iter.Close()
  378. for ; iter.Valid(); iter.Next() {
  379. ev, err := bytesToEv(iter.Value())
  380. if err != nil {
  381. evpool.logger.Error("failed to transition evidence from protobuf", "err", err, "ev", ev)
  382. continue
  383. }
  384. // if true, we have looped through all expired evidence
  385. if !evpool.isExpired(ev.Height(), ev.Time()) {
  386. // Return the height and time with which this evidence will have expired
  387. // so we know when to prune next.
  388. return ev.Height() + evpool.State().ConsensusParams.Evidence.MaxAgeNumBlocks + 1,
  389. ev.Time().Add(evpool.State().ConsensusParams.Evidence.MaxAgeDuration).Add(time.Second),
  390. blockEvidenceMap
  391. }
  392. // else add to the batch
  393. if err := batch.Delete(iter.Key()); err != nil {
  394. evpool.logger.Error("failed to batch delete evidence", "err", err, "ev", ev)
  395. continue
  396. }
  397. // and add to the map to remove the evidence from the clist
  398. blockEvidenceMap[evMapKey(ev)] = struct{}{}
  399. }
  400. return evpool.State().LastBlockHeight, evpool.State().LastBlockTime, blockEvidenceMap
  401. }
  402. func (evpool *Pool) removeEvidenceFromList(
  403. blockEvidenceMap map[string]struct{}) {
  404. for e := evpool.evidenceList.Front(); e != nil; e = e.Next() {
  405. // Remove from clist
  406. ev := e.Value.(types.Evidence)
  407. if _, ok := blockEvidenceMap[evMapKey(ev)]; ok {
  408. evpool.evidenceList.Remove(e)
  409. e.DetachPrev()
  410. }
  411. }
  412. }
  413. func (evpool *Pool) updateState(state sm.State) {
  414. evpool.mtx.Lock()
  415. defer evpool.mtx.Unlock()
  416. evpool.state = state
  417. }
  418. // processConsensusBuffer converts all the duplicate votes witnessed from consensus
  419. // into DuplicateVoteEvidence. It sets the evidence timestamp to the block height
  420. // from the most recently committed block.
  421. // Evidence is then added to the pool so as to be ready to be broadcasted and proposed.
  422. func (evpool *Pool) processConsensusBuffer(state sm.State) {
  423. evpool.mtx.Lock()
  424. defer evpool.mtx.Unlock()
  425. for _, voteSet := range evpool.consensusBuffer {
  426. // Check the height of the conflicting votes and fetch the corresponding time and validator set
  427. // to produce the valid evidence
  428. var (
  429. dve *types.DuplicateVoteEvidence
  430. err error
  431. )
  432. switch {
  433. case voteSet.VoteA.Height == state.LastBlockHeight:
  434. dve, err = types.NewDuplicateVoteEvidence(
  435. voteSet.VoteA,
  436. voteSet.VoteB,
  437. state.LastBlockTime,
  438. state.LastValidators,
  439. )
  440. case voteSet.VoteA.Height < state.LastBlockHeight:
  441. valSet, dbErr := evpool.stateDB.LoadValidators(voteSet.VoteA.Height)
  442. if dbErr != nil {
  443. evpool.logger.Error("failed to load validator set for conflicting votes",
  444. "height", voteSet.VoteA.Height, "err", err)
  445. continue
  446. }
  447. blockMeta := evpool.blockStore.LoadBlockMeta(voteSet.VoteA.Height)
  448. if blockMeta == nil {
  449. evpool.logger.Error("failed to load block time for conflicting votes", "height", voteSet.VoteA.Height)
  450. continue
  451. }
  452. dve, err = types.NewDuplicateVoteEvidence(
  453. voteSet.VoteA,
  454. voteSet.VoteB,
  455. blockMeta.Header.Time,
  456. valSet,
  457. )
  458. default:
  459. // evidence pool shouldn't expect to get votes from consensus of a height that is above the current
  460. // state. If this error is seen then perhaps consider keeping the votes in the buffer and retry
  461. // in following heights
  462. evpool.logger.Error("inbound duplicate votes from consensus are of a greater height than current state",
  463. "duplicate vote height", voteSet.VoteA.Height,
  464. "state.LastBlockHeight", state.LastBlockHeight)
  465. continue
  466. }
  467. if err != nil {
  468. evpool.logger.Error("error in generating evidence from votes", "err", err)
  469. continue
  470. }
  471. // check if we already have this evidence
  472. if evpool.isPending(dve) {
  473. evpool.logger.Debug("evidence already pending; ignoring", "evidence", dve)
  474. continue
  475. }
  476. // check that the evidence is not already committed on chain
  477. if evpool.isCommitted(dve) {
  478. evpool.logger.Debug("evidence already committed; ignoring", "evidence", dve)
  479. continue
  480. }
  481. if err := evpool.addPendingEvidence(dve); err != nil {
  482. evpool.logger.Error("failed to flush evidence from consensus buffer to pending list: %w", err)
  483. continue
  484. }
  485. evpool.evidenceList.PushBack(dve)
  486. evpool.logger.Info("verified new evidence of byzantine behavior", "evidence", dve)
  487. }
  488. // reset consensus buffer
  489. evpool.consensusBuffer = make([]duplicateVoteSet, 0)
  490. }
  491. type duplicateVoteSet struct {
  492. VoteA *types.Vote
  493. VoteB *types.Vote
  494. }
  495. func bytesToEv(evBytes []byte) (types.Evidence, error) {
  496. var evpb tmproto.Evidence
  497. err := evpb.Unmarshal(evBytes)
  498. if err != nil {
  499. return &types.DuplicateVoteEvidence{}, err
  500. }
  501. return types.EvidenceFromProto(&evpb)
  502. }
  503. func evMapKey(ev types.Evidence) string {
  504. return string(ev.Hash())
  505. }
  506. func prefixToBytes(prefix int64) []byte {
  507. key, err := orderedcode.Append(nil, prefix)
  508. if err != nil {
  509. panic(err)
  510. }
  511. return key
  512. }
  513. func keyCommitted(evidence types.Evidence) []byte {
  514. height := evidence.Height()
  515. key, err := orderedcode.Append(nil, prefixCommitted, height, string(evidence.Hash()))
  516. if err != nil {
  517. panic(err)
  518. }
  519. return key
  520. }
  521. func keyPending(evidence types.Evidence) []byte {
  522. height := evidence.Height()
  523. key, err := orderedcode.Append(nil, prefixPending, height, string(evidence.Hash()))
  524. if err != nil {
  525. panic(err)
  526. }
  527. return key
  528. }