The Lehman Brothers' bankruptcy triggered the failure of the collateralized debt markets, which was a major contributor of the financial crisis in 2008. Such collateralized debt markets have both collateral price channel and counterparty (borrower and lender) channel of contagion. I propose a general equilibrium network model, which incorporates the two channels of contagion by endogenizing leverage (margin), asset prices, and network formation. Agents face a tradeoff between leverage and counterparty risk. Diversification of counterparty risk generates positive externalities by reducing systemic risk, but comes at the cost of lower leverage. Thus, any decentralized equilibrium is inefficient due to under-diversification. I use this framework to show that the loss coverage by a central counterparty (CCP) exacerbates the externality problem and the introduction of CCP can rather increase systemic risk.