~login@TTBP



14 june 2018

updates to pcoin

I decided to create pcoin because there was a need for tcoin to be more than just sending digital coins from one person to another. Programs had to have their own accounts. The goal was to create the components that would make it easy to create automated-dealer casino-style games like poker (Texas Hold'em) and blacjack.

First, there had to be a digital currency. At tilde.town's scale, there was no need for a decentralised cryptocurrency. Since the digital currency had to be local to tilde.town, and townies trust ~vilmibm (our fantastic admin and benevolent overlord) not to mess with things, it was not hard to realise that a model based on trusting a centralised party to keep transactions safe and secure from tampering would be a perfect fit.

After tcoin was done and all the bugs were ironed out (at least, the obvious ones and the ones brought to my attention were), I waited some time trying to come up with a model for authenticating programs. After talking to several townies about it, we came to the conclusion that a long key is the simplest solution. So pcoin was just a fork of tcoin with the method of authentication changed. This didn't mean pcoin was particularly suited to the kind of things programs would need it to do, as I realised during the development of chin.

After some naive design decisions with chin that led to the subsequent killing of the chin server process because it put too much load on the server by copying and reading a 3 MB file on every run, I realised that pcoin wasn't suited to the needs of programs. I had two paths I could take: I could modify chin's code to extract useful information from pcoin's message log (which was enough for chin's needs, but horribly inefficient), or I could modify pcoin to make it easier to code chin and make it easier for future programs as well.

I chose the second path, because improvements to pcoin would benefit future programs as well.

There were several realisations that I came to while developing chin, and in retrospect, making a game that used pcoin was the right approach to finding out what program-specific features pcoin could implement that made it easier for programs to implement tildecoin integration.

  1. tcoin is like a bank, but each program is like its own mini-bank. Transferring tildecoin to a program doesn't mean the program owns the amount. It is owed to the user, and the latter should always be able to take their balance back.

  2. During the process of running the program, the user may win or lose tildecoin. This means that more tildecoin (or less) is owed to the user than the amount that was transferred to the program originally.

Each program would have had to develop its own means of storing transaction data from users and paying them out when the user wanted. Each program would have had to write the same kind of business logic that is used in tcoin (or pcoin, for that matter). The best way to solve this problem, I came to realise, was to make it pcoin's responsibility instead of each individual program's.

Thus, programs now have a special data store in pcoin called "program_accounting". This data store contains the amount of tildecoin owed to each user, and the total amount owed to all users. Whenever a user sends tildecoin to a program, the amount of tildecoin owed to that user and the total amount owed to all users is automatically updated (by tcoin) in the program's data store. Thus, the program doesn't need to read through its transactions to figure out what it owes each user. That data is already available in this data store, although its integrity can be confirmed using the program's message log.

In addition, a program can increase or decrease what it owes each user using pcoin. This means it can make it pcoin's responsibility to determine what the program owes each user after the program's operation. For example, if you win tildecoin in chin, the amount owed to you is increased using pcoin. It is decreased if you lose tildecoin in chin. Thus, if a program wants to take donations, it will have to decrease the amount it owes the user to 0. The default behaviour is that tildecoin sent to programs is not their own, but is owed to the user who sent it.

The program is not allowed to increase the amount it owes a user beyond what it can immediately fulfil, and is not allowed to decrease the amount owed to a user below 0. This is enforced in pcoin's code.

For the program to find out how much it owes vilmibm, the command is pcoin internal_balance vilmibm. For the program to find out how much it owes to all users/programs, the command is pcoin total_owed. For the program to store the information that it owes vilmibm <amount> tildecoin more, the command is pcoin add_internal_balance vilmibm <amount>. For the program to store the information that it owes vilmibm <amount> tildecoin less, the command is pcoin add_internal_balance vilmibm -⁠<amount>.

When the program sends tildecoin back to the user it owed, the program's data store (in addition to tcoin's data store) is updated so that the total amount owed and the amount owed to that user is decreased by the amount sent back to the user.

I hope these changes to pcoin will encourage townies to look into getting a tildecoin account for their program (email login@tilde.town (tilde-town's local email) with the program name, and I'll reply with the key and some instructions to get started with pcoin) and integrating tildecoin into their programs. As always, I seek advice on how to make pcoin better (or less worse). You can send your suggestions, advice and feedback through login@tilde.town or irc.

Thank you for taking the time to read this far :) Have a wonderful day!