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.

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