A Cosmos SDK module to add payment channels to any blockchain built using the SDK.
Payment Channels are a technology to speed up payments on blockchains while retaining strong security guarantees. They work by moving payments 'off-chain' to sidestep the bottleneck of blockchain throughput.
The Cosmos SDK is a modular framework for developers to quickly and easily build custom blockchains in Go. Blockchains can be built from modules containing specific functionality, such as this one.
Note: This project is new and unstable. Get involved!
This module currently implements unidirectional channels. Channels can be opened by a sender and closed immediately by the receiver, or by the sender subject to a dispute period. There are no top-ups or partial withdrawals (yet).
gaiacli tx paychan create cosmos1zls5y0yd9wvh86ceh9tz93eehvesa6d7p8qge8 100atom --from <sender's account name>
Send a payment for 10 atom.
gaiacli tx paychan pay <channel ID> 90atom 10atom --filename payment.json
Send the file payment.json
to your receiver. They can run the following to verify it.
gaiacli tx paychan close --dry-run --payment payment.json
The receiver can close immediately at any time.
gaiacli tx paychan close --from <receiver's account name> --payment payment.json
The sender can submit a close request, closing the channel after a dispute period. During this period a receiver can still close immediately, overruling the sender's request.
gaiacli tx paychan close --from <sender's account name> --payment payment.json
The aim is for this module to be usable in any cosmos sdk based blockchain. However the module interface in the sdk is currently being refactored so using this module may require some tweaks. See
go.mod
for the sdk version this was built against.
This module can be included in an sdk app in the same way the standard modules are (staking
, gov
, etc). It uses the module interface pattern introduced in sdk v0.35.0.
It includes:
- cli and rest interfaces
- tx types and handler
- endblocker to close payment channels
- layer 2 utilities - receiver http server and channel watcher
- configurable channel timeouts
- use BFT time rather than block height for chanel timeouts
- allow channel signing key to be different from account key
- sender slashing on early close
- channel top ups and partial withdrawals
- bidirectional channels (with cooperative close)
- multiparty channels
- integration test
- possible bug in submitting same update repeatedly
- test cli and rest
- verify doesn’t throw json parsing error on invalid json
- can’t submit an update from an uninitialised account
- add querier
- pin to cosmos-sdk v0.36.0 once released
- change channel id to unit64
- split participants into sender and receiver
- use iterator for channels for efficiency - rename queue
- tidy up channel signatures - split off signatures from update as with txs/msgs, can auth sigs be used?
- custom errors, codespace
- tags
- clarify naming - paychan vs channel, rename update