Author Topic: Python implementation  (Read 5002 times)

zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Python implementation
« on: September 17, 2014, 01:38:17 am »
https://github.com/zack-bitcoin/Truthcoin-POW

This is a minimal viable product. It still has bugs and is not ready for serious investment with money.
It only supports binary markets, not scalars.
It works on Mac OSX now too!
I am currently looking for testers to go through the steps of making a prediction market, and testing the consensus mechanism.
If you can find a bug that I am able to reproduce, then I will put your name on the Scoreboard. Bug finders are the very best people, they deserve to be celebrated.
« Last Edit: September 25, 2014, 10:08:46 pm by zack »

zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Re: Python implementation
« Reply #1 on: September 25, 2014, 10:08:59 pm »
bump

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #2 on: September 26, 2014, 02:25:34 am »
I will soon write a script to replicate everything that happens on fairlay.com on your truthcoin implementation.

I think this is a good method to test things with some real events.

(We are just developing our API - http://188.165.246.217/api/)
« Last Edit: September 26, 2014, 04:44:29 pm by koeppelmann »

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #3 on: September 30, 2014, 05:08:12 am »
I tried to do more testing.
Actually I created a jury, and decision and a PM - however, I can not buy shares...

Code: [Select]
martin@martin-VirtualBox:~/Truthcoin-POW-master$ ./truth_cli.py make_PM
What is the address or pubkey of the owner of the PM?
>113dARdhbwSrbohSWoahQhKEyDZcoas
What is the unique name for this new prediction market?
>HillaryPM
how big should B be? Initial investment is B*ln(n) where n is the number of states
>10
how many decisions is this prediction market to be based upon?
>1
What is the unique name of the 0 decision?
>Hillary
how many states can this PM result in?
>2
what is the text title of the 0 state?
>YES
how does the 0 state depend upon the outcome of the decisions? For example: if there are 2 decisions, and this market only comes true when the first is "yes" and the second is "no", then you would put: "1 0" here.
>1
what is the text title of the 1 state?
>NO
added tx: {'count': 1324, u'B': 10, u'type': u'prediction_market', u'states': [u'YES', u'NO'], u'PM_id': u'HillaryPM', 'signatures': ['HMcYRbjderROjQjTZaOlE6MTQP5YPe8OeMx2g1Ij6jpRFiP2xn3pPZoC5wg0My0RUEcnizcTZIkmZ3tSMZJ71ug='], u'fees': 0, u'owner': u'113dARdhbwSrbohSWoahQhKEyDZcoas', 'pubkeys': ['04ba9d76d0f8c62633c7a377e98e944e4f2e4d46f843236b19587f60c37f36c6342be23e2f33e51e910893926687b9fee25b2af329aca5b7fe9986c86c145c78ff'], u'decisions': [u'Hillary'], u'states_combinatory': [[1]]}
martin@martin-VirtualBox:~/Truthcoin-POW-master$ ./truth_cli.py txs
[]
martin@martin-VirtualBox:~/Truthcoin-POW-master$ ./truth_cli.py buy_shares
What is the unique name for this prediction market?
>HillaryPM
how many states does this pm have?
>2
how many shares do you want to buy of state 0? To sell states, use negative numbers.
>10
how many shares do you want to buy of state 1? To sell states, use negative numbers.
>0
failed to add tx because: that is not a prediction market yettx: {'count': 1329, u'buy': [10, 0], u'PM_id': u'HillaryPM', 'signatures': ['G15A4WYKa12vIbCKRCestIvpkpxx+4RhKdaQt1t+7tN7OUT7l8I+vLPnk0pw1xapqUpHj+MFzfl0aozf2EGEQhM='], 'pubkeys': ['04ba9d76d0f8c62633c7a377e98e944e4f2e4d46f843236b19587f60c37f36c6342be23e2f33e51e910893926687b9fee25b2af329aca5b7fe9986c86c145c78ff'], u'type': u'buy_shares'}


zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Re: Python implementation
« Reply #4 on: September 30, 2014, 06:34:11 am »
Wow! this is great!
I am glad you were able to get so far.
I will try and patch this up tomorrow morning.

I hope you will be able to migrate predictions onto my chain. It is a great way for beta testers to experiment.

zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Re: Python implementation
« Reply #5 on: September 30, 2014, 07:46:08 pm »
Summary:
If you find a block at the same time you make a tx, the tx gets deleted sometimes. If you are the only person mining, then a lot of tx you write will get deleted. Turn your miner off while you write the tx, and this wont happen.

Details:

It is sure cool being able to read the blocks and know exactly what happened.
You were mining at 10x the normal speed at the time you signed the transaction to make the prediction market.
It took just 7 seconds since the last block. The miners were designed to check for new tx every 30 seconds.

The transaction for creating the prediction market never got put into the blockchain.
This is because your miner was working on a block at the same time you published the transaction. Your miner found a block that did not contain you tx, but it did cointain a mint tx (which gives you your reward for finding a block). This mint transaction increased your 'count', so the 'count' in the tx for creating the prediction market was too low.

Since the tx for creating the prediction market was invalid, it was deleted.

My plan for fixing this bug is to have the miners restart every time we create a new tx.

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #6 on: September 30, 2014, 07:51:43 pm »
does this mean in your implementation transactions are only valid for one block?
Does that mean if a transaction does not get included right away it becomes invalid?

I think such a concept as a mempool (like in Bitcoin) is necessary. However, I guess the reason you made this decision is that the order is crucial for buy/sell transactions, right?

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #7 on: September 30, 2014, 08:00:48 pm »
Some more questions:

where can I specify a time/date of the resolution of the decision?

I do not 100% understand the distribution of vote coins in your implementation. And how are votecoins connected to a "jury". What happens if I create a jury?

zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Re: Python implementation
« Reply #8 on: September 30, 2014, 08:03:24 pm »
does this mean in your implementation transactions are only valid for one block?
Does that mean if a transaction does not get included right away it becomes invalid?

I think such a concept as a mempool (like in Bitcoin) is necessary. However, I guess the reason you made this decision is that the order is crucial for buy/sell transactions, right?

If Zack writes a tx, it is valid until Zack broadcasts a different tx.
If Zack does not broadcast a different tx, then the tx will stay valid for months.

I don't know what a 'mempool' is.
What decision did I make?

zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Re: Python implementation
« Reply #9 on: September 30, 2014, 08:04:58 pm »
Some more questions:

where can I specify a time/date of the resolution of the decision?

I do not 100% understand the distribution of vote coins in your implementation. And how are votecoins connected to a "jury". What happens if I create a jury?

You cannot specify an exporation yet. They can be decided as soon as enough people have voted, and we are in the consensus time period.

If you create a jury, then you get all the jury coins. Whoever holds those coins can vote on the decisions that are asked of the jury.
If you want to start a jury with 10 other people, then divide the coins into 11 piles, and send them to each person.

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #10 on: September 30, 2014, 08:09:35 pm »

If Zack writes a tx, it is valid until Zack broadcasts a different tx.
If Zack does not broadcast a different tx, then the tx will stay valid for months.

Ok, this is indeed different if other blocks does not cause this problem.

I don't know what a 'mempool' is.
What decision did I make?


mempool is short for memory pool and is the name for all Bitcoin transactions that are spread in the network but not included in a block.
Compare: mempool.info
I thought you made the decision to not have a mempool - but if I understand it correctly the command txs shows the mempool of the your truthcoin network implementation.

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #11 on: October 01, 2014, 02:22:59 am »
Some more questions:

where can I specify a time/date of the resolution of the decision?

I do not 100% understand the distribution of vote coins in your implementation. And how are votecoins connected to a "jury". What happens if I create a jury?

You cannot specify an exporation yet. They can be decided as soon as enough people have voted, and we are in the consensus time period.

If you create a jury, then you get all the jury coins. Whoever holds those coins can vote on the decisions that are asked of the jury.
If you want to start a jury with 10 other people, then divide the coins into 11 piles, and send them to each person.

But you plan to add resolution dates, right?

Second question: have you changed something to the difficulty adjustments. I am mining about 40minutes now and have not found a block yet. I currently have the difficulty of 000004d67a62d9b17b4000000000000000000000000000000000000000000000.

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #12 on: October 01, 2014, 03:19:17 am »
I am stuck at Block 1022

koeppelmann

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Python implementation
« Reply #13 on: October 01, 2014, 06:08:40 pm »
After updating to the newest version make_PM market worked and I added the "HillaryPM".

However - when I tried to buy shares I got a "count error":

Code: [Select]
martin@martin-VirtualBox:~/Truthcoin-POW-master$ ./truth_cli.py buy_shares
What is the unique name for this prediction market?
>HillaryPM
how many states does this pm have?
>2
how many shares do you want to buy of state 0? To sell states, use negative numbers.
>10
how many shares do you want to buy of state 1? To sell states, use negative numbers.
>0
failed to add tx because: count error

zack

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 384
    • View Profile
Re: Python implementation
« Reply #14 on: October 12, 2014, 10:58:52 pm »
sorry to take so long to respond.
The error you had was because you are the only person on the network. you found a block at the same time you made the tx.