  Peer-to-Peer (P2P) content delivery, known for scalability and resilience,
offers a decentralized alternative to traditional centralized Content Delivery
Networks (CDNs). A significant challenge in P2P content delivery remains: the
fair compensation of relayers for their bandwidth contributions. Existing
solutions employ blockchains for payment settlements, however, they are not
practical due to high on-chain costs and over-simplified network assumptions.
In this paper, we introduce FairRelay, a fair and cost-efficient protocol that
ensures all participants get fair payoff in complex content delivery network
settings. We introduce a novel primitive, Enforceable Accumulative Hashed
TimeLock Contract (Enforceable A-HTLC), designed to guarantee payment atomicity
- ensuring all participants receive their payments upon successful content
delivery.
  The fairness of FairRelay is proved using the Universal Composability (UC)
framework. Our evaluation demonstrates that, in optimistic scenarios, FairRelay
employs zero on-chain costs. In pessimistic scenarios, the on-chain dispute
costs for relayers and customers are constant, irrespective of the network
complexity. Specifically, empirical results indicate that the on-chain dispute
costs for relayers and customers are 24,902 gas (equivalent to 0.01 USD on
Optimism L2) and 290,797 gas (0.07 USD), respectively. In a 10-hop relay path,
FairRelay introduces less than 1.5% additional overhead compared to pure data
transmission, showcasing the efficiency of FairRelay.
