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
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. // Atomic integers
  28. height int64 // the last block Update()'d to
  29. txsBytes int64 // total size of mempool, in bytes
  30. rechecking int32 // for re-checking filtered txs on Update()
  31. // notify listeners (ie. consensus) when txs are available
  32. notifiedTxsAvailable bool
  33. txsAvailable chan struct{} // fires once for each height, when the mempool is not empty
  34. config *cfg.MempoolConfig
  35. proxyMtx sync.Mutex
  36. proxyAppConn proxy.AppConnMempool
  37. txs *clist.CList // concurrent linked-list of good txs
  38. preCheck PreCheckFunc
  39. postCheck PostCheckFunc
  40. // Track whether we're rechecking txs.
  41. // These are not protected by a mutex and are expected to be mutated
  42. // in serial (ie. by abci responses which are called in serial).
  43. recheckCursor *clist.CElement // next expected response
  44. recheckEnd *clist.CElement // re-checking stops here
  45. // Map for quick access to txs to record sender in CheckTx.
  46. // txsMap: txKey -> CElement
  47. txsMap sync.Map
  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 txSize > mem.config.MaxTxBytes {
  196. return ErrTxTooLarge{mem.config.MaxTxBytes, 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. memTx.senders.LoadOrStore(txInfo.SenderID, true)
  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. return ErrTxInCache
  217. }
  218. // END CACHE
  219. // WAL
  220. if mem.wal != nil {
  221. // TODO: Notify administrators when WAL fails
  222. _, err := mem.wal.Write([]byte(tx))
  223. if err != nil {
  224. mem.logger.Error("Error writing to WAL", "err", err)
  225. }
  226. _, err = mem.wal.Write([]byte("\n"))
  227. if err != nil {
  228. mem.logger.Error("Error writing to WAL", "err", err)
  229. }
  230. }
  231. // END WAL
  232. // NOTE: proxyAppConn may error if tx buffer is full
  233. if err = mem.proxyAppConn.Error(); err != nil {
  234. return err
  235. }
  236. reqRes := mem.proxyAppConn.CheckTxAsync(abci.RequestCheckTx{Tx: tx})
  237. reqRes.SetCallback(mem.reqResCb(tx, txInfo.SenderID, cb))
  238. return nil
  239. }
  240. // Global callback that will be called after every ABCI response.
  241. // Having a single global callback avoids needing to set a callback for each request.
  242. // However, processing the checkTx response requires the peerID (so we can track which txs we heard from who),
  243. // and peerID is not included in the ABCI request, so we have to set request-specific callbacks that
  244. // include this information. If we're not in the midst of a recheck, this function will just return,
  245. // so the request specific callback can do the work.
  246. // When rechecking, we don't need the peerID, so the recheck callback happens here.
  247. func (mem *CListMempool) globalCb(req *abci.Request, res *abci.Response) {
  248. if mem.recheckCursor == nil {
  249. return
  250. }
  251. mem.metrics.RecheckTimes.Add(1)
  252. mem.resCbRecheck(req, res)
  253. // update metrics
  254. mem.metrics.Size.Set(float64(mem.Size()))
  255. }
  256. // Request specific callback that should be set on individual reqRes objects
  257. // to incorporate local information when processing the response.
  258. // This allows us to track the peer that sent us this tx, so we can avoid sending it back to them.
  259. // NOTE: alternatively, we could include this information in the ABCI request itself.
  260. //
  261. // External callers of CheckTx, like the RPC, can also pass an externalCb through here that is called
  262. // when all other response processing is complete.
  263. //
  264. // Used in CheckTxWithInfo to record PeerID who sent us the tx.
  265. func (mem *CListMempool) reqResCb(tx []byte, peerID uint16, externalCb func(*abci.Response)) func(res *abci.Response) {
  266. return func(res *abci.Response) {
  267. if mem.recheckCursor != nil {
  268. // this should never happen
  269. panic("recheck cursor is not nil in reqResCb")
  270. }
  271. mem.resCbFirstTime(tx, peerID, res)
  272. // update metrics
  273. mem.metrics.Size.Set(float64(mem.Size()))
  274. // passed in by the caller of CheckTx, eg. the RPC
  275. if externalCb != nil {
  276. externalCb(res)
  277. }
  278. }
  279. }
  280. // Called from:
  281. // - resCbFirstTime (lock not held) if tx is valid
  282. func (mem *CListMempool) addTx(memTx *mempoolTx) {
  283. e := mem.txs.PushBack(memTx)
  284. mem.txsMap.Store(txKey(memTx.tx), e)
  285. atomic.AddInt64(&mem.txsBytes, int64(len(memTx.tx)))
  286. mem.metrics.TxSizeBytes.Observe(float64(len(memTx.tx)))
  287. }
  288. // Called from:
  289. // - Update (lock held) if tx was committed
  290. // - resCbRecheck (lock not held) if tx was invalidated
  291. func (mem *CListMempool) removeTx(tx types.Tx, elem *clist.CElement, removeFromCache bool) {
  292. mem.txs.Remove(elem)
  293. elem.DetachPrev()
  294. mem.txsMap.Delete(txKey(tx))
  295. atomic.AddInt64(&mem.txsBytes, int64(-len(tx)))
  296. if removeFromCache {
  297. mem.cache.Remove(tx)
  298. }
  299. }
  300. // callback, which is called after the app checked the tx for the first time.
  301. //
  302. // The case where the app checks the tx for the second and subsequent times is
  303. // handled by the resCbRecheck callback.
  304. func (mem *CListMempool) resCbFirstTime(tx []byte, peerID uint16, res *abci.Response) {
  305. switch r := res.Value.(type) {
  306. case *abci.Response_CheckTx:
  307. var postCheckErr error
  308. if mem.postCheck != nil {
  309. postCheckErr = mem.postCheck(tx, r.CheckTx)
  310. }
  311. if (r.CheckTx.Code == abci.CodeTypeOK) && postCheckErr == nil {
  312. memTx := &mempoolTx{
  313. height: mem.height,
  314. gasWanted: r.CheckTx.GasWanted,
  315. tx: tx,
  316. }
  317. memTx.senders.Store(peerID, true)
  318. mem.addTx(memTx)
  319. mem.logger.Info("Added good transaction",
  320. "tx", txID(tx),
  321. "res", r,
  322. "height", memTx.height,
  323. "total", mem.Size(),
  324. )
  325. mem.notifyTxsAvailable()
  326. } else {
  327. // ignore bad transaction
  328. mem.logger.Info("Rejected bad transaction", "tx", txID(tx), "res", r, "err", postCheckErr)
  329. mem.metrics.FailedTxs.Add(1)
  330. // remove from cache (it might be good later)
  331. mem.cache.Remove(tx)
  332. }
  333. default:
  334. // ignore other messages
  335. }
  336. }
  337. // callback, which is called after the app rechecked the tx.
  338. //
  339. // The case where the app checks the tx for the first time is handled by the
  340. // resCbFirstTime callback.
  341. func (mem *CListMempool) resCbRecheck(req *abci.Request, res *abci.Response) {
  342. switch r := res.Value.(type) {
  343. case *abci.Response_CheckTx:
  344. tx := req.GetCheckTx().Tx
  345. memTx := mem.recheckCursor.Value.(*mempoolTx)
  346. if !bytes.Equal(tx, memTx.tx) {
  347. panic(fmt.Sprintf(
  348. "Unexpected tx response from proxy during recheck\nExpected %X, got %X",
  349. memTx.tx,
  350. tx))
  351. }
  352. var postCheckErr error
  353. if mem.postCheck != nil {
  354. postCheckErr = mem.postCheck(tx, r.CheckTx)
  355. }
  356. if (r.CheckTx.Code == abci.CodeTypeOK) && postCheckErr == nil {
  357. // Good, nothing to do.
  358. } else {
  359. // Tx became invalidated due to newly committed block.
  360. mem.logger.Info("Tx is no longer valid", "tx", txID(tx), "res", r, "err", postCheckErr)
  361. // NOTE: we remove tx from the cache because it might be good later
  362. mem.removeTx(tx, mem.recheckCursor, true)
  363. }
  364. if mem.recheckCursor == mem.recheckEnd {
  365. mem.recheckCursor = nil
  366. } else {
  367. mem.recheckCursor = mem.recheckCursor.Next()
  368. }
  369. if mem.recheckCursor == nil {
  370. // Done!
  371. atomic.StoreInt32(&mem.rechecking, 0)
  372. mem.logger.Info("Done rechecking txs")
  373. // incase the recheck removed all txs
  374. if mem.Size() > 0 {
  375. mem.notifyTxsAvailable()
  376. }
  377. }
  378. default:
  379. // ignore other messages
  380. }
  381. }
  382. func (mem *CListMempool) TxsAvailable() <-chan struct{} {
  383. return mem.txsAvailable
  384. }
  385. func (mem *CListMempool) notifyTxsAvailable() {
  386. if mem.Size() == 0 {
  387. panic("notified txs available but mempool is empty!")
  388. }
  389. if mem.txsAvailable != nil && !mem.notifiedTxsAvailable {
  390. // channel cap is 1, so this will send once
  391. mem.notifiedTxsAvailable = true
  392. select {
  393. case mem.txsAvailable <- struct{}{}:
  394. default:
  395. }
  396. }
  397. }
  398. func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
  399. mem.proxyMtx.Lock()
  400. defer mem.proxyMtx.Unlock()
  401. for atomic.LoadInt32(&mem.rechecking) > 0 {
  402. // TODO: Something better?
  403. time.Sleep(time.Millisecond * 10)
  404. }
  405. var totalBytes int64
  406. var totalGas int64
  407. // TODO: we will get a performance boost if we have a good estimate of avg
  408. // size per tx, and set the initial capacity based off of that.
  409. // txs := make([]types.Tx, 0, cmn.MinInt(mem.txs.Len(), max/mem.avgTxSize))
  410. txs := make([]types.Tx, 0, mem.txs.Len())
  411. for e := mem.txs.Front(); e != nil; e = e.Next() {
  412. memTx := e.Value.(*mempoolTx)
  413. // Check total size requirement
  414. aminoOverhead := types.ComputeAminoOverhead(memTx.tx, 1)
  415. if maxBytes > -1 && totalBytes+int64(len(memTx.tx))+aminoOverhead > maxBytes {
  416. return txs
  417. }
  418. totalBytes += int64(len(memTx.tx)) + aminoOverhead
  419. // Check total gas requirement.
  420. // If maxGas is negative, skip this check.
  421. // Since newTotalGas < masGas, which
  422. // must be non-negative, it follows that this won't overflow.
  423. newTotalGas := totalGas + memTx.gasWanted
  424. if maxGas > -1 && newTotalGas > maxGas {
  425. return txs
  426. }
  427. totalGas = newTotalGas
  428. txs = append(txs, memTx.tx)
  429. }
  430. return txs
  431. }
  432. func (mem *CListMempool) ReapMaxTxs(max int) types.Txs {
  433. mem.proxyMtx.Lock()
  434. defer mem.proxyMtx.Unlock()
  435. if max < 0 {
  436. max = mem.txs.Len()
  437. }
  438. for atomic.LoadInt32(&mem.rechecking) > 0 {
  439. // TODO: Something better?
  440. time.Sleep(time.Millisecond * 10)
  441. }
  442. txs := make([]types.Tx, 0, cmn.MinInt(mem.txs.Len(), max))
  443. for e := mem.txs.Front(); e != nil && len(txs) <= max; e = e.Next() {
  444. memTx := e.Value.(*mempoolTx)
  445. txs = append(txs, memTx.tx)
  446. }
  447. return txs
  448. }
  449. func (mem *CListMempool) Update(
  450. height int64,
  451. txs types.Txs,
  452. deliverTxResponses []*abci.ResponseDeliverTx,
  453. preCheck PreCheckFunc,
  454. postCheck PostCheckFunc,
  455. ) error {
  456. // Set height
  457. mem.height = height
  458. mem.notifiedTxsAvailable = false
  459. if preCheck != nil {
  460. mem.preCheck = preCheck
  461. }
  462. if postCheck != nil {
  463. mem.postCheck = postCheck
  464. }
  465. for i, tx := range txs {
  466. if deliverTxResponses[i].Code == abci.CodeTypeOK {
  467. // Add valid committed tx to the cache (if missing).
  468. _ = mem.cache.Push(tx)
  469. } else {
  470. // Allow invalid transactions to be resubmitted.
  471. mem.cache.Remove(tx)
  472. }
  473. // Remove committed tx from the mempool.
  474. //
  475. // Note an evil proposer can drop valid txs!
  476. // Mempool before:
  477. // 100 -> 101 -> 102
  478. // Block, proposed by an evil proposer:
  479. // 101 -> 102
  480. // Mempool after:
  481. // 100
  482. // https://github.com/tendermint/tendermint/issues/3322.
  483. if e, ok := mem.txsMap.Load(txKey(tx)); ok {
  484. mem.removeTx(tx, e.(*clist.CElement), false)
  485. }
  486. }
  487. // Either recheck non-committed txs to see if they became invalid
  488. // or just notify there're some txs left.
  489. if mem.Size() > 0 {
  490. if mem.config.Recheck {
  491. mem.logger.Info("Recheck txs", "numtxs", mem.Size(), "height", height)
  492. mem.recheckTxs()
  493. // At this point, mem.txs are being rechecked.
  494. // mem.recheckCursor re-scans mem.txs and possibly removes some txs.
  495. // Before mem.Reap(), we should wait for mem.recheckCursor to be nil.
  496. } else {
  497. mem.notifyTxsAvailable()
  498. }
  499. }
  500. // Update metrics
  501. mem.metrics.Size.Set(float64(mem.Size()))
  502. return nil
  503. }
  504. func (mem *CListMempool) recheckTxs() {
  505. if mem.Size() == 0 {
  506. panic("recheckTxs is called, but the mempool is empty")
  507. }
  508. atomic.StoreInt32(&mem.rechecking, 1)
  509. mem.recheckCursor = mem.txs.Front()
  510. mem.recheckEnd = mem.txs.Back()
  511. // Push txs to proxyAppConn
  512. // NOTE: globalCb may be called concurrently.
  513. for e := mem.txs.Front(); e != nil; e = e.Next() {
  514. memTx := e.Value.(*mempoolTx)
  515. mem.proxyAppConn.CheckTxAsync(abci.RequestCheckTx{
  516. Tx: memTx.tx,
  517. Type: abci.CheckTxType_Recheck,
  518. })
  519. }
  520. mem.proxyAppConn.FlushAsync()
  521. }
  522. //--------------------------------------------------------------------------------
  523. // mempoolTx is a transaction that successfully ran
  524. type mempoolTx struct {
  525. height int64 // height that this tx had been validated in
  526. gasWanted int64 // amount of gas this tx states it will require
  527. tx types.Tx //
  528. // ids of peers who've sent us this tx (as a map for quick lookups).
  529. // senders: PeerID -> bool
  530. senders sync.Map
  531. }
  532. // Height returns the height for this transaction
  533. func (memTx *mempoolTx) Height() int64 {
  534. return atomic.LoadInt64(&memTx.height)
  535. }
  536. //--------------------------------------------------------------------------------
  537. type txCache interface {
  538. Reset()
  539. Push(tx types.Tx) bool
  540. Remove(tx types.Tx)
  541. }
  542. // mapTxCache maintains a LRU cache of transactions. This only stores the hash
  543. // of the tx, due to memory concerns.
  544. type mapTxCache struct {
  545. mtx sync.Mutex
  546. size int
  547. map_ map[[sha256.Size]byte]*list.Element
  548. list *list.List
  549. }
  550. var _ txCache = (*mapTxCache)(nil)
  551. // newMapTxCache returns a new mapTxCache.
  552. func newMapTxCache(cacheSize int) *mapTxCache {
  553. return &mapTxCache{
  554. size: cacheSize,
  555. map_: make(map[[sha256.Size]byte]*list.Element, cacheSize),
  556. list: list.New(),
  557. }
  558. }
  559. // Reset resets the cache to an empty state.
  560. func (cache *mapTxCache) Reset() {
  561. cache.mtx.Lock()
  562. cache.map_ = make(map[[sha256.Size]byte]*list.Element, cache.size)
  563. cache.list.Init()
  564. cache.mtx.Unlock()
  565. }
  566. // Push adds the given tx to the cache and returns true. It returns
  567. // false if tx is already in the cache.
  568. func (cache *mapTxCache) Push(tx types.Tx) bool {
  569. cache.mtx.Lock()
  570. defer cache.mtx.Unlock()
  571. // Use the tx hash in the cache
  572. txHash := txKey(tx)
  573. if moved, exists := cache.map_[txHash]; exists {
  574. cache.list.MoveToBack(moved)
  575. return false
  576. }
  577. if cache.list.Len() >= cache.size {
  578. popped := cache.list.Front()
  579. poppedTxHash := popped.Value.([sha256.Size]byte)
  580. delete(cache.map_, poppedTxHash)
  581. if popped != nil {
  582. cache.list.Remove(popped)
  583. }
  584. }
  585. e := cache.list.PushBack(txHash)
  586. cache.map_[txHash] = e
  587. return true
  588. }
  589. // Remove removes the given tx from the cache.
  590. func (cache *mapTxCache) Remove(tx types.Tx) {
  591. cache.mtx.Lock()
  592. txHash := txKey(tx)
  593. popped := cache.map_[txHash]
  594. delete(cache.map_, txHash)
  595. if popped != nil {
  596. cache.list.Remove(popped)
  597. }
  598. cache.mtx.Unlock()
  599. }
  600. type nopTxCache struct{}
  601. var _ txCache = (*nopTxCache)(nil)
  602. func (nopTxCache) Reset() {}
  603. func (nopTxCache) Push(types.Tx) bool { return true }
  604. func (nopTxCache) Remove(types.Tx) {}
  605. //--------------------------------------------------------------------------------
  606. // txKey is the fixed length array sha256 hash used as the key in maps.
  607. func txKey(tx types.Tx) [sha256.Size]byte {
  608. return sha256.Sum256(tx)
  609. }
  610. // txID is the hex encoded hash of the bytes as a types.Tx.
  611. func txID(tx []byte) string {
  612. return fmt.Sprintf("%X", types.Tx(tx).Hash())
  613. }