I've been thinking for some time now that a concept like payment channels could be used to implement a "real-time aspect" in Huntercoin or a related system. Now I've had some time to think about it and I will describe a rough idea below. I welcome any comments!
Game Channels for Near Real-Time Interaction among PlayersFor this post, let us assume that we want to add a simple "fighting arena" to Huntercoin. Two peers on the network mutually agree to put up a HUC price and then enter a (possibly private) fight for the price based on some rules. Using an idea similar to payment channels and the Lightning Network, this can be done in such a way that everything is off the blockchain (avoiding bloat as well as allowing for fast interaction not waiting for confirmations) as long as the peers agree. In case that one of them drops out or disagrees, the other one can claim the price on the blockchain. This makes everything trustless but still efficient.
Turn-Based GamesWe consider a game that is
turn based, with the peers taking turns to make a move and modify a shared game state. This can also be done with more than two players if some order of turns is defined (round-robin or whatever suits the actual game rules). To initiate the game channel, both peers create a transaction spending coins to some locked output (multisig or based on some new consensus rules in Huntercoin). This transaction can contain additional details about the planned game negotiated by the players. It also contains, at least, a public key identifying each player during the game. The locked coins can only be spent by providing the Huntercoin network with a proof of who won the game. As soon as this transaction is sufficiently confirmed, the game can start.
If no disagreement happens and no player drops out, the basic idea is that all players build a "private blockchain" similar to how Huntercoin works itself: Starting from some predefined initial game state (which can be determined by the game rules alone and the initiating transaction on the blockchain), each turn taken by some player constructs a "miniblock" that contains the move signed by this player's private key. This allows everyone with access to the private blockchain to compute the current game state; in particular, the player whose turn is next can continue to build a new block upon the current blockchain, and each participant of the game can verify that all rules are being followed. Ideally, at some point the game reaches a state where someone won. If each player is still fair and does not claim a dispute, all together can construct and sign a transaction unlocking the price and paying to the respective winners. This is the only thing that needs to be put again on the real Huntercoin blockchain in this case.
However, of course the more interesting situation is what happens if someone disagrees with the game or stops to respond. It seems not unrealistic that a losing player may choose to do that on purpose; or it could be due to a network failure or some other unintentional issue. In this case, there needs to be a way for the other(s) to claim the price in a secure fashion. For this, I propose the following mechanism:
- When a player stops to respond (after, e. g., some timeout has been reached), the remaining player may escalate the situation and claim a dispute. This is done by publishing the current private blockchain including all signed moves made so far to the Huntercoin network in a special transaction.
- If this transaction gets a sufficient number of confirmations and/or has been on the network for a sufficiently long time (compare the locktime of Bitcoin transactions), the player may unilaterally spend the locked price output.
- Unless the contrahent actually starts to respond again: When they see the claim on the network, they have the possibility (until the timelock threshold runs out) to post their next move publicly on the network. This transaction, when confirmed, invalidates the claim; this is not a problem since there now is a next move and the game continues. If the contrahent stops to respond again in the future, a new claim can be filed.
This procedure ensures that the game continues with at least a certain minimum frequency of moves, even if one of the players may prefer to drop out. If it does not, then the non-dropped-out player is able to claim the price anyway.
Shared TurnsThis situation of a turn-based game can also be extended to "shared turns" as it is the case with Huntercoin currently. I. e., we do not want the players to take a turn after each other, but instead we want them all to perform some move
at the same time but without learning their opponents' moves before they make their own. This can be achieved by introducing "pseudoturns": We define some order of the players, and each one publishes a hash commitment of their move in this order as "their" turn. Afterwards, in a new round of pseudoturns, each player reveals the move. This reduces the situation of shared turns to a pure turn-based game as discussed above.
Near Real-Time InteractionSimilarly, one can also reduce a "near real-time" interation to a turn-based game: We allow "do nothing" as a valid turn, so that each player's client may immediately respond to the other's turn by posting a "do nothing" turn unless a "real-time player action" was initiated at this moment. This allows for a rapid succession of moves, as fast as the network and processing power of the clients allows. Of course, it is not clear how useful such a situation really is -- after all, by claiming a dispute the moves can be delayed in case of disagreement, so that no enjoyable real-time playing can happen.
ConclusionUsing the ideas introduced above, one can really implement private games between players (fights based on some rules to extend Huntercoin, but the same protocol can also be used to define, for instance, a blockchain-based chess game). They are trustless but unless a real disagreement happens, they can be played off the blockchain and faster than the block confirmation times (as well as without causing blockchain bloat or requiring transaction fees).
The ideas described are still rough, and I'm pretty sure that one can work on minimising the "blockchain fingerprint". For instance, one could try to construct a suitable set of proofs (based on, e. g., Merkle trees) that can be used to claim disputes without requiring to post the full (possibly long) sequence of moves so far. This is, for now, out-of-scope, though.
I believe that this concept may even be used not only to add a "fighting arena" to Huntercoin, but even to scale the game for much larger (or possibly infinite) worlds. This idea here could be the following: The game state of each part of the world is only propagated in time if there are players nearby. These players could then for themselves create a game channel and process their moves privately without causing growth of the Huntercoin blockchain, unless a dispute happens. Of course, there are still a lot of issues to resolve for such an approach -- not least how to spawn coins there in such a way that everyone (not just the players interested currently in the game part) can verify that the total (and global) rewards are correct. But this is, as well, a separate issue out-of-scope for now and can be addressed by a follow-up design.