message: Map the headers by service in the spam filter
diff: @@ -371,8 +371,6 @@ struct CNodeState {
  ChainSyncTimeoutState m_chain_sync;
  - CNodeHeaders headers;
  -
  //! Time of last new block announcement
  int64_t m_last_block_announcement;
  @@ -405,6 +403,7 @@ struct CNodeState {
  /** Map maintaining per-node state. */
  static std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main);
  +static std::map<CService, CNodeHeaders> mapServiceHeaders GUARDED_BY(cs_main);
  static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
  std::map<NodeId, CNodeState>::iterator it = mapNodeState.find(pnode);
  @@ -413,6 +412,10 @@ static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
  return &it->second;
  }
  +static CNodeHeaders &ServiceHeaders(const CService& address) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
  + return mapServiceHeaders[address];
  +}
  +
  bool ProcessNetBlockHeaders(CNode* pfrom, const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr)
  {
  const CBlockIndex *pindexFirst = nullptr;
  @@ -421,9 +424,10 @@ bool ProcessNetBlockHeaders(CNode* pfrom, const std::vector<CBlockHeader>& block
  {
  LOCK(cs_main);
  CNodeState *nodestate = State(pfrom->GetId());
  + CNodeHeaders& headers = ServiceHeaders(nodestate->address);
  const CBlockIndex *pindexLast = ppindex == nullptr ? nullptr : *ppindex;
  - nodestate->headers.addHeaders(pindexFirst, pindexLast);
  - return nodestate->headers.updateState(state, ret);
  + headers.addHeaders(pindexFirst, pindexLast);
  + return headers.updateState(state, ret);
  }
  return ret;
  }
  