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.

715 lines
20 KiB

mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
6 years ago
  1. package mempool
  2. import (
  3. "bytes"
  4. "container/list"
  5. "crypto/sha256"
  6. "fmt"
  7. "sync"
  8. "sync/atomic"
  9. "time"
  10. "github.com/pkg/errors"
  11. abci "github.com/tendermint/tendermint/abci/types"
  12. cfg "github.com/tendermint/tendermint/config"
  13. auto "github.com/tendermint/tendermint/libs/autofile"
  14. "github.com/tendermint/tendermint/libs/clist"
  15. cmn "github.com/tendermint/tendermint/libs/common"
  16. "github.com/tendermint/tendermint/libs/log"
  17. "github.com/tendermint/tendermint/proxy"
  18. "github.com/tendermint/tendermint/types"
  19. )
  20. //--------------------------------------------------------------------------------
  21. // CListMempool is an ordered in-memory pool for transactions before they are
  22. // proposed in a consensus round. Transaction validity is checked using the
  23. // CheckTx abci message before the transaction is added to the pool. The
  24. // mempool uses a concurrent list structure for storing transactions that can
  25. // be efficiently accessed by multiple concurrent readers.
  26. type CListMempool struct {
  27. config *cfg.MempoolConfig
  28. proxyMtx sync.Mutex
  29. proxyAppConn proxy.AppConnMempool
  30. txs *clist.CList // concurrent linked-list of good txs
  31. preCheck PreCheckFunc
  32. postCheck PostCheckFunc
  33. // Track whether we're rechecking txs.
  34. // These are not protected by a mutex and are expected to be mutated
  35. // in serial (ie. by abci responses which are called in serial).
  36. recheckCursor *clist.CElement // next expected response
  37. recheckEnd *clist.CElement // re-checking stops here
  38. // notify listeners (ie. consensus) when txs are available
  39. notifiedTxsAvailable bool
  40. txsAvailable chan struct{} // fires once for each height, when the mempool is not empty
  41. // Map for quick access to txs to record sender in CheckTx.
  42. // txsMap: txKey -> CElement
  43. txsMap sync.Map
  44. // Atomic integers
  45. height int64 // the last block Update()'d to
  46. rechecking int32 // for re-checking filtered txs on Update()
  47. txsBytes int64 // total size of mempool, in bytes
  48. // Keep a cache of already-seen txs.
  49. // This reduces the pressure on the proxyApp.
  50. cache txCache
  51. // A log of mempool txs
  52. wal *auto.AutoFile
  53. logger log.Logger
  54. metrics *Metrics
  55. }
  56. var _ Mempool = &CListMempool{}
  57. // CListMempoolOption sets an optional parameter on the mempool.
  58. type CListMempoolOption func(*CListMempool)
  59. // NewCListMempool returns a new mempool with the given configuration and connection to an application.
  60. func NewCListMempool(
  61. config *cfg.MempoolConfig,
  62. proxyAppConn proxy.AppConnMempool,
  63. height int64,
  64. options ...CListMempoolOption,
  65. ) *CListMempool {
  66. mempool := &CListMempool{
  67. config: config,
  68. proxyAppConn: proxyAppConn,
  69. txs: clist.New(),
  70. height: height,
  71. rechecking: 0,
  72. recheckCursor: nil,
  73. recheckEnd: nil,
  74. logger: log.NewNopLogger(),
  75. metrics: NopMetrics(),
  76. }
  77. if config.CacheSize > 0 {
  78. mempool.cache = newMapTxCache(config.CacheSize)
  79. } else {
  80. mempool.cache = nopTxCache{}
  81. }
  82. proxyAppConn.SetResponseCallback(mempool.globalCb)
  83. for _, option := range options {
  84. option(mempool)
  85. }
  86. return mempool
  87. }
  88. // NOTE: not thread safe - should only be called once, on startup
  89. func (mem *CListMempool) EnableTxsAvailable() {
  90. mem.txsAvailable = make(chan struct{}, 1)
  91. }
  92. // SetLogger sets the Logger.
  93. func (mem *CListMempool) SetLogger(l log.Logger) {
  94. mem.logger = l
  95. }
  96. // WithPreCheck sets a filter for the mempool to reject a tx if f(tx) returns
  97. // false. This is ran before CheckTx.
  98. func WithPreCheck(f PreCheckFunc) CListMempoolOption {
  99. return func(mem *CListMempool) { mem.preCheck = f }
  100. }
  101. // WithPostCheck sets a filter for the mempool to reject a tx if f(tx) returns
  102. // false. This is ran after CheckTx.
  103. func WithPostCheck(f PostCheckFunc) CListMempoolOption {
  104. return func(mem *CListMempool) { mem.postCheck = f }
  105. }
  106. // WithMetrics sets the metrics.
  107. func WithMetrics(metrics *Metrics) CListMempoolOption {
  108. return func(mem *CListMempool) { mem.metrics = metrics }
  109. }
  110. // *panics* if can't create directory or open file.
  111. // *not thread safe*
  112. func (mem *CListMempool) InitWAL() {
  113. walDir := mem.config.WalDir()
  114. err := cmn.EnsureDir(walDir, 0700)
  115. if err != nil {
  116. panic(errors.Wrap(err, "Error ensuring WAL dir"))
  117. }
  118. af, err := auto.OpenAutoFile(walDir + "/wal")
  119. if err != nil {
  120. panic(errors.Wrap(err, "Error opening WAL file"))
  121. }
  122. mem.wal = af
  123. }
  124. func (mem *CListMempool) CloseWAL() {
  125. mem.proxyMtx.Lock()
  126. defer mem.proxyMtx.Unlock()
  127. if err := mem.wal.Close(); err != nil {
  128. mem.logger.Error("Error closing WAL", "err", err)
  129. }
  130. mem.wal = nil
  131. }
  132. func (mem *CListMempool) Lock() {
  133. mem.proxyMtx.Lock()
  134. }
  135. func (mem *CListMempool) Unlock() {
  136. mem.proxyMtx.Unlock()
  137. }
  138. func (mem *CListMempool) Size() int {
  139. return mem.txs.Len()
  140. }
  141. func (mem *CListMempool) TxsBytes() int64 {
  142. return atomic.LoadInt64(&mem.txsBytes)
  143. }
  144. func (mem *CListMempool) FlushAppConn() error {
  145. return mem.proxyAppConn.FlushSync()
  146. }
  147. func (mem *CListMempool) Flush() {
  148. mem.proxyMtx.Lock()
  149. defer mem.proxyMtx.Unlock()
  150. mem.cache.Reset()
  151. for e := mem.txs.Front(); e != nil; e = e.Next() {
  152. mem.txs.Remove(e)
  153. e.DetachPrev()
  154. }
  155. mem.txsMap = sync.Map{}
  156. _ = atomic.SwapInt64(&mem.txsBytes, 0)
  157. }
  158. // TxsFront returns the first transaction in the ordered list for peer
  159. // goroutines to call .NextWait() on.
  160. // FIXME: leaking implementation details!
  161. func (mem *CListMempool) TxsFront() *clist.CElement {
  162. return mem.txs.Front()
  163. }
  164. // TxsWaitChan returns a channel to wait on transactions. It will be closed
  165. // once the mempool is not empty (ie. the internal `mem.txs` has at least one
  166. // element)
  167. func (mem *CListMempool) TxsWaitChan() <-chan struct{} {
  168. return mem.txs.WaitChan()
  169. }
  170. // It blocks if we're waiting on Update() or Reap().
  171. // cb: A callback from the CheckTx command.
  172. // It gets called from another goroutine.
  173. // CONTRACT: Either cb will get called, or err returned.
  174. func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error) {
  175. return mem.CheckTxWithInfo(tx, cb, TxInfo{SenderID: UnknownPeerID})
  176. }
  177. func (mem *CListMempool) CheckTxWithInfo(tx types.Tx, cb func(*abci.Response), txInfo TxInfo) (err error) {
  178. mem.proxyMtx.Lock()
  179. // use defer to unlock mutex because application (*local client*) might panic
  180. defer mem.proxyMtx.Unlock()
  181. var (
  182. memSize = mem.Size()
  183. txsBytes = mem.TxsBytes()
  184. txSize = len(tx)
  185. )
  186. if memSize >= mem.config.Size ||
  187. int64(txSize)+txsBytes > mem.config.MaxTxsBytes {
  188. return ErrMempoolIsFull{
  189. memSize, mem.config.Size,
  190. txsBytes, mem.config.MaxTxsBytes}
  191. }
  192. // The size of the corresponding amino-encoded TxMessage
  193. // can't be larger than the maxMsgSize, otherwise we can't
  194. // relay it to peers.
  195. if max := calcMaxTxSize(mem.config.MaxMsgBytes); txSize > max {
  196. return ErrTxTooLarge{max, txSize}
  197. }
  198. if mem.preCheck != nil {
  199. if err := mem.preCheck(tx); err != nil {
  200. return ErrPreCheck{err}
  201. }
  202. }
  203. // CACHE
  204. if !mem.cache.Push(tx) {
  205. // Record a new sender for a tx we've already seen.
  206. // Note it's possible a tx is still in the cache but no longer in the mempool
  207. // (eg. after committing a block, txs are removed from mempool but not cache),
  208. // so we only record the sender for txs still in the mempool.
  209. if e, ok := mem.txsMap.Load(txKey(tx)); ok {
  210. memTx := e.(*clist.CElement).Value.(*mempoolTx)
  211. if _, loaded := memTx.senders.LoadOrStore(txInfo.SenderID, true); loaded {
  212. // TODO: consider punishing peer for dups,
  213. // its non-trivial since invalid txs can become valid,
  214. // but they can spam the same tx with little cost to them atm.
  215. }
  216. }
  217. return ErrTxInCache
  218. }
  219. // END CACHE
  220. // WAL
  221. if mem.wal != nil {
  222. // TODO: Notify administrators when WAL fails
  223. _, err := mem.wal.Write([]byte(tx))
  224. if err != nil {
  225. mem.logger.Error("Error writing to WAL", "err", err)
  226. }
  227. _, err = mem.wal.Write([]byte("\n"))
  228. if err != nil {
  229. mem.logger.Error("Error writing to WAL", "err", err)
  230. }
  231. }
  232. // END WAL
  233. // NOTE: proxyAppConn may error if tx buffer is full
  234. if err = mem.proxyAppConn.Error(); err != nil {
  235. return err
  236. }
  237. reqRes := mem.proxyAppConn.CheckTxAsync(abci.RequestCheckTx{Tx: tx})
  238. reqRes.SetCallback(mem.reqResCb(tx, txInfo.SenderID, cb))
  239. return nil
  240. }
  241. // Global callback that will be called after every ABCI response.
  242. // Having a single global callback avoids needing to set a callback for each request.
  243. // However, processing the checkTx response requires the peerID (so we can track which txs we heard from who),
  244. // and peerID is not included in the ABCI request, so we have to set request-specific callbacks that
  245. // include this information. If we're not in the midst of a recheck, this function will just return,
  246. // so the request specific callback can do the work.
  247. // When rechecking, we don't need the peerID, so the recheck callback happens here.
  248. func (mem *CListMempool) globalCb(req *abci.Request, res *abci.Response) {
  249. if mem.recheckCursor == nil {
  250. return
  251. }
  252. mem.metrics.RecheckTimes.Add(1)
  253. mem.resCbRecheck(req, res)
  254. // update metrics
  255. mem.metrics.Size.Set(float64(mem.Size()))
  256. }
  257. // Request specific callback that should be set on individual reqRes objects
  258. // to incorporate local information when processing the response.
  259. // This allows us to track the peer that sent us this tx, so we can avoid sending it back to them.
  260. // NOTE: alternatively, we could include this information in the ABCI request itself.
  261. //
  262. // External callers of CheckTx, like the RPC, can also pass an externalCb through here that is called
  263. // when all other response processing is complete.
  264. //
  265. // Used in CheckTxWithInfo to record PeerID who sent us the tx.
  266. func (mem *CListMempool) reqResCb(tx []byte, peerID uint16, externalCb func(*abci.Response)) func(res *abci.Response) {
  267. return func(res *abci.Response) {
  268. if mem.recheckCursor != nil {
  269. // this should never happen
  270. panic("recheck cursor is not nil in reqResCb")
  271. }
  272. mem.resCbFirstTime(tx, peerID, res)
  273. // update metrics
  274. mem.metrics.Size.Set(float64(mem.Size()))
  275. // passed in by the caller of CheckTx, eg. the RPC
  276. if externalCb != nil {
  277. externalCb(res)
  278. }
  279. }
  280. }
  281. // Called from:
  282. // - resCbFirstTime (lock not held) if tx is valid
  283. func (mem *CListMempool) addTx(memTx *mempoolTx) {
  284. e := mem.txs.PushBack(memTx)
  285. mem.txsMap.Store(txKey(memTx.tx), e)
  286. atomic.AddInt64(&mem.txsBytes, int64(len(memTx.tx)))
  287. mem.metrics.TxSizeBytes.Observe(float64(len(memTx.tx)))
  288. }
  289. // Called from:
  290. // - Update (lock held) if tx was committed
  291. // - resCbRecheck (lock not held) if tx was invalidated
  292. func (mem *CListMempool) removeTx(tx types.Tx, elem *clist.CElement, removeFromCache bool) {
  293. mem.txs.Remove(elem)
  294. elem.DetachPrev()
  295. mem.txsMap.Delete(txKey(tx))
  296. atomic.AddInt64(&mem.txsBytes, int64(-len(tx)))
  297. if removeFromCache {
  298. mem.cache.Remove(tx)
  299. }
  300. }
  301. // callback, which is called after the app checked the tx for the first time.
  302. //
  303. // The case where the app checks the tx for the second and subsequent times is
  304. // handled by the resCbRecheck callback.
  305. func (mem *CListMempool) resCbFirstTime(tx []byte, peerID uint16, res *abci.Response) {
  306. switch r := res.Value.(type) {
  307. case *abci.Response_CheckTx:
  308. var postCheckErr error
  309. if mem.postCheck != nil {
  310. postCheckErr = mem.postCheck(tx, r.CheckTx)
  311. }
  312. if (r.CheckTx.Code == abci.CodeTypeOK) && postCheckErr == nil {
  313. memTx := &mempoolTx{
  314. height: mem.height,
  315. gasWanted: r.CheckTx.GasWanted,
  316. tx: tx,
  317. }
  318. memTx.senders.Store(peerID, true)
  319. mem.addTx(memTx)
  320. mem.logger.Info("Added good transaction",
  321. "tx", txID(tx),
  322. "res", r,
  323. "height", memTx.height,
  324. "total", mem.Size(),
  325. )
  326. mem.notifyTxsAvailable()
  327. } else {
  328. // ignore bad transaction
  329. mem.logger.Info("Rejected bad transaction", "tx", txID(tx), "res", r, "err", postCheckErr)
  330. mem.metrics.FailedTxs.Add(1)
  331. // remove from cache (it might be good later)
  332. mem.cache.Remove(tx)
  333. }
  334. default:
  335. // ignore other messages
  336. }
  337. }
  338. // callback, which is called after the app rechecked the tx.
  339. //
  340. // The case where the app checks the tx for the first time is handled by the
  341. // resCbFirstTime callback.
  342. func (mem *CListMempool) resCbRecheck(req *abci.Request, res *abci.Response) {
  343. switch r := res.Value.(type) {
  344. case *abci.Response_CheckTx:
  345. tx := req.GetCheckTx().Tx
  346. memTx := mem.recheckCursor.Value.(*mempoolTx)
  347. if !bytes.Equal(tx, memTx.tx) {
  348. panic(fmt.Sprintf(
  349. "Unexpected tx response from proxy during recheck\nExpected %X, got %X",
  350. memTx.tx,
  351. tx))
  352. }
  353. var postCheckErr error
  354. if mem.postCheck != nil {
  355. postCheckErr = mem.postCheck(tx, r.CheckTx)
  356. }
  357. if (r.CheckTx.Code == abci.CodeTypeOK) && postCheckErr == nil {
  358. // Good, nothing to do.
  359. } else {
  360. // Tx became invalidated due to newly committed block.
  361. mem.logger.Info("Tx is no longer valid", "tx", txID(tx), "res", r, "err", postCheckErr)
  362. // NOTE: we remove tx from the cache because it might be good later
  363. mem.removeTx(tx, mem.recheckCursor, true)
  364. }
  365. if mem.recheckCursor == mem.recheckEnd {
  366. mem.recheckCursor = nil
  367. } else {
  368. mem.recheckCursor = mem.recheckCursor.Next()
  369. }
  370. if mem.recheckCursor == nil {
  371. // Done!
  372. atomic.StoreInt32(&mem.rechecking, 0)
  373. mem.logger.Info("Done rechecking txs")
  374. // incase the recheck removed all txs
  375. if mem.Size() > 0 {
  376. mem.notifyTxsAvailable()
  377. }
  378. }
  379. default:
  380. // ignore other messages
  381. }
  382. }
  383. func (mem *CListMempool) TxsAvailable() <-chan struct{} {
  384. return mem.txsAvailable
  385. }
  386. func (mem *CListMempool) notifyTxsAvailable() {
  387. if mem.Size() == 0 {
  388. panic("notified txs available but mempool is empty!")
  389. }
  390. if mem.txsAvailable != nil && !mem.notifiedTxsAvailable {
  391. // channel cap is 1, so this will send once
  392. mem.notifiedTxsAvailable = true
  393. select {
  394. case mem.txsAvailable <- struct{}{}:
  395. default:
  396. }
  397. }
  398. }
  399. func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
  400. mem.proxyMtx.Lock()
  401. defer mem.proxyMtx.Unlock()
  402. for atomic.LoadInt32(&mem.rechecking) > 0 {
  403. // TODO: Something better?
  404. time.Sleep(time.Millisecond * 10)
  405. }
  406. var totalBytes int64
  407. var totalGas int64
  408. // TODO: we will get a performance boost if we have a good estimate of avg
  409. // size per tx, and set the initial capacity based off of that.
  410. // txs := make([]types.Tx, 0, cmn.MinInt(mem.txs.Len(), max/mem.avgTxSize))
  411. txs := make([]types.Tx, 0, mem.txs.Len())
  412. for e := mem.txs.Front(); e != nil; e = e.Next() {
  413. memTx := e.Value.(*mempoolTx)
  414. // Check total size requirement
  415. aminoOverhead := types.ComputeAminoOverhead(memTx.tx, 1)
  416. if maxBytes > -1 && totalBytes+int64(len(memTx.tx))+aminoOverhead > maxBytes {
  417. return txs
  418. }
  419. totalBytes += int64(len(memTx.tx)) + aminoOverhead
  420. // Check total gas requirement.
  421. // If maxGas is negative, skip this check.
  422. // Since newTotalGas < masGas, which
  423. // must be non-negative, it follows that this won't overflow.
  424. newTotalGas := totalGas + memTx.gasWanted
  425. if maxGas > -1 && newTotalGas > maxGas {
  426. return txs
  427. }
  428. totalGas = newTotalGas
  429. txs = append(txs, memTx.tx)
  430. }
  431. return txs
  432. }
  433. func (mem *CListMempool) ReapMaxTxs(max int) types.Txs {
  434. mem.proxyMtx.Lock()
  435. defer mem.proxyMtx.Unlock()
  436. if max < 0 {
  437. max = mem.txs.Len()
  438. }
  439. for atomic.LoadInt32(&mem.rechecking) > 0 {
  440. // TODO: Something better?
  441. time.Sleep(time.Millisecond * 10)
  442. }
  443. txs := make([]types.Tx, 0, cmn.MinInt(mem.txs.Len(), max))
  444. for e := mem.txs.Front(); e != nil && len(txs) <= max; e = e.Next() {
  445. memTx := e.Value.(*mempoolTx)
  446. txs = append(txs, memTx.tx)
  447. }
  448. return txs
  449. }
  450. func (mem *CListMempool) Update(
  451. height int64,
  452. txs types.Txs,
  453. deliverTxResponses []*abci.ResponseDeliverTx,
  454. preCheck PreCheckFunc,
  455. postCheck PostCheckFunc,
  456. ) error {
  457. // Set height
  458. mem.height = height
  459. mem.notifiedTxsAvailable = false
  460. if preCheck != nil {
  461. mem.preCheck = preCheck
  462. }
  463. if postCheck != nil {
  464. mem.postCheck = postCheck
  465. }
  466. for i, tx := range txs {
  467. if deliverTxResponses[i].Code == abci.CodeTypeOK {
  468. // Add valid committed tx to the cache (if missing).
  469. _ = mem.cache.Push(tx)
  470. } else {
  471. // Allow invalid transactions to be resubmitted.
  472. mem.cache.Remove(tx)
  473. }
  474. // Remove committed tx from the mempool.
  475. //
  476. // Note an evil proposer can drop valid txs!
  477. // Mempool before:
  478. // 100 -> 101 -> 102
  479. // Block, proposed by an evil proposer:
  480. // 101 -> 102
  481. // Mempool after:
  482. // 100
  483. // https://github.com/tendermint/tendermint/issues/3322.
  484. if e, ok := mem.txsMap.Load(txKey(tx)); ok {
  485. mem.removeTx(tx, e.(*clist.CElement), false)
  486. }
  487. }
  488. // Either recheck non-committed txs to see if they became invalid
  489. // or just notify there're some txs left.
  490. if mem.Size() > 0 {
  491. if mem.config.Recheck {
  492. mem.logger.Info("Recheck txs", "numtxs", mem.Size(), "height", height)
  493. mem.recheckTxs()
  494. // At this point, mem.txs are being rechecked.
  495. // mem.recheckCursor re-scans mem.txs and possibly removes some txs.
  496. // Before mem.Reap(), we should wait for mem.recheckCursor to be nil.
  497. } else {
  498. mem.notifyTxsAvailable()
  499. }
  500. }
  501. // Update metrics
  502. mem.metrics.Size.Set(float64(mem.Size()))
  503. return nil
  504. }
  505. func (mem *CListMempool) recheckTxs() {
  506. if mem.Size() == 0 {
  507. panic("recheckTxs is called, but the mempool is empty")
  508. }
  509. atomic.StoreInt32(&mem.rechecking, 1)
  510. mem.recheckCursor = mem.txs.Front()
  511. mem.recheckEnd = mem.txs.Back()
  512. // Push txs to proxyAppConn
  513. // NOTE: globalCb may be called concurrently.
  514. for e := mem.txs.Front(); e != nil; e = e.Next() {
  515. memTx := e.Value.(*mempoolTx)
  516. mem.proxyAppConn.CheckTxAsync(abci.RequestCheckTx{
  517. Tx: memTx.tx,
  518. Type: abci.CheckTxType_Recheck,
  519. })
  520. }
  521. mem.proxyAppConn.FlushAsync()
  522. }
  523. //--------------------------------------------------------------------------------
  524. // mempoolTx is a transaction that successfully ran
  525. type mempoolTx struct {
  526. height int64 // height that this tx had been validated in
  527. gasWanted int64 // amount of gas this tx states it will require
  528. tx types.Tx //
  529. // ids of peers who've sent us this tx (as a map for quick lookups).
  530. // senders: PeerID -> bool
  531. senders sync.Map
  532. }
  533. // Height returns the height for this transaction
  534. func (memTx *mempoolTx) Height() int64 {
  535. return atomic.LoadInt64(&memTx.height)
  536. }
  537. //--------------------------------------------------------------------------------
  538. type txCache interface {
  539. Reset()
  540. Push(tx types.Tx) bool
  541. Remove(tx types.Tx)
  542. }
  543. // mapTxCache maintains a LRU cache of transactions. This only stores the hash
  544. // of the tx, due to memory concerns.
  545. type mapTxCache struct {
  546. mtx sync.Mutex
  547. size int
  548. map_ map[[sha256.Size]byte]*list.Element
  549. list *list.List
  550. }
  551. var _ txCache = (*mapTxCache)(nil)
  552. // newMapTxCache returns a new mapTxCache.
  553. func newMapTxCache(cacheSize int) *mapTxCache {
  554. return &mapTxCache{
  555. size: cacheSize,
  556. map_: make(map[[sha256.Size]byte]*list.Element, cacheSize),
  557. list: list.New(),
  558. }
  559. }
  560. // Reset resets the cache to an empty state.
  561. func (cache *mapTxCache) Reset() {
  562. cache.mtx.Lock()
  563. cache.map_ = make(map[[sha256.Size]byte]*list.Element, cache.size)
  564. cache.list.Init()
  565. cache.mtx.Unlock()
  566. }
  567. // Push adds the given tx to the cache and returns true. It returns
  568. // false if tx is already in the cache.
  569. func (cache *mapTxCache) Push(tx types.Tx) bool {
  570. cache.mtx.Lock()
  571. defer cache.mtx.Unlock()
  572. // Use the tx hash in the cache
  573. txHash := txKey(tx)
  574. if moved, exists := cache.map_[txHash]; exists {
  575. cache.list.MoveToBack(moved)
  576. return false
  577. }
  578. if cache.list.Len() >= cache.size {
  579. popped := cache.list.Front()
  580. poppedTxHash := popped.Value.([sha256.Size]byte)
  581. delete(cache.map_, poppedTxHash)
  582. if popped != nil {
  583. cache.list.Remove(popped)
  584. }
  585. }
  586. e := cache.list.PushBack(txHash)
  587. cache.map_[txHash] = e
  588. return true
  589. }
  590. // Remove removes the given tx from the cache.
  591. func (cache *mapTxCache) Remove(tx types.Tx) {
  592. cache.mtx.Lock()
  593. txHash := txKey(tx)
  594. popped := cache.map_[txHash]
  595. delete(cache.map_, txHash)
  596. if popped != nil {
  597. cache.list.Remove(popped)
  598. }
  599. cache.mtx.Unlock()
  600. }
  601. type nopTxCache struct{}
  602. var _ txCache = (*nopTxCache)(nil)
  603. func (nopTxCache) Reset() {}
  604. func (nopTxCache) Push(types.Tx) bool { return true }
  605. func (nopTxCache) Remove(types.Tx) {}
  606. //--------------------------------------------------------------------------------
  607. // txKey is the fixed length array sha256 hash used as the key in maps.
  608. func txKey(tx types.Tx) [sha256.Size]byte {
  609. return sha256.Sum256(tx)
  610. }
  611. // txID is the hex encoded hash of the bytes as a types.Tx.
  612. func txID(tx []byte) string {
  613. return fmt.Sprintf("%X", types.Tx(tx).Hash())
  614. }