Marketplace with blockchain based reputation system supporting bid,ask, and cancel messages.

Our previous running code, needs work: http://repository.tudelft.nl/islandora/object/uuid:c1816da8-c82e-47bc-bde2-4f35b9a3e775
Existing literature (no code, just ideas):
Economic theory foundation: https://scholar.google.nl/citations?view_op=view_citation&hl=en&user=ZEDUm5UAAAAJ&citation_for_view=ZEDUm5UAAAAJ:2osOgNQ5qMEC
Ongoing 15 pages of decentral markets survey .tex : https://github.com/Tribler/tribler/issues/2535
Related implementation on central server from 2011 that can handle 6 million orders per second on a single thread on a 3 GHz machine.
Getting started with coding:
Additional resource: https://github.com/Tribler/dispersy/pull/517
The decentral market is now smoothly operational in Gumby:

Gumby experiment link: https://jenkins.tribler.org/job/pers/job/market_experiment_devos50/
Like the AllChannel experiment, this can (should?) become a performance/health indicator for our decentralised market.
Suggestions:
Sections:
related work: evolution over past 15 years:
Some of the first research concerned with P2P agent-based marketplaces is that of
Youll [27]. In this work, a framework for an agent-mediated P2P marketplace was
suggested and implemented in Java using a centralized trader registry. Searching for
potential traders is done using an adaption of the Contract Net protocol [5]. The use of
Web Services that are based on standard protocols, e.g., WSDL and SOAP, along with a
decentralized registry implemented over a P2P network such as Gnutella (as suggested
in [17]) seems a more suitable choice for P2P marketplace implementations. The important
issue of tradersâ trustworthiness was briefly mentioned in Youllâs work, but not
really handled. Coalitions between traders were not checked. In addition, no simulations
or analysis of experimental results were provided to justify why decentralized
marketplaces might be better than centralized ones.
Another justification for decentralized marketplaces can be derived from [16], where
a P2P-agent double continuous auction was presented. It was shown that such a decentralized
auction displays price convergence behavior similar to that of the centralized
auction. However, the P2P auction outperforms the centralized auction in the sense that
it has a constant cost in the number of message rounds needed to find the market equilibrium
price when the number of traders increases, whereas a central auctioneer incurs a
linear cost in this case. It would be interesting to extend this work and introduce quality
of products or trustworthiness of agents into the simulation.
Turner et al. describe in [23] a P2P resource market where buyers and sellers trade
their surplus resources, e.g., CPU cycles, storage, and bandwidth. They suggest that
each entity in the market might issue its own currency, and propose the Lightweight
Currency Protocol as a standard protocol for the interaction between users and currency
issuers. This protocol might be a building block on top of which P2P marketplaces
could be implemented.
The theoretical work of Neeman et al. [15] shows that when buyers and sellers
are given the opportunity to choose between trading through a centralized market or
through a decentralized one, they would both prefer the centralized option. However,
they assume in their work that a homogeneous product is traded and that the centralized
market incurs no costs. We are interested (by contrast) in the case where the product
traded is not necessarily homogeneous; products from different sellers may have different
qualities. Furthermore, not all trading partners can be assumed to be trustworthy.
This might lead to the emergence of coalitions based on trading relationships, explored
for example in [2].
@basvijzendoorn these tickets seems to have overlap, see https://github.com/Tribler/tribler/issues/2535#issuecomment-260346273 for another table of content.
ToDo Bas, read and run the code :
THE Core economic theory of markets from 1970: https://github.com/dmvaldman/library/blob/master/economics/Akerlof%20-%20The%20Market%20for%20Lemons.pdf
Worked on a first very basic version of a Trustchain credits <-> BTC market in Tribler. I've integrated the Bitcoin wallet and made an API endpoint to get the balance, both confirmed and unconfirmed using the Electrum wallet. Note that the asks and bids are requested using the RESTful API. In addition, when Tribler discovers a new ask/bid, the list in the GUI is automatically updated and sorted accordingly.

TODO (GUI-related):
good screenshot. will include it in grant submission for Tuesday.
I've rewritten some of the wallet logic. We now support more than one wallet and each wallet has a short identifier. The main idea is that we have various wallets that holds assets, i.e.:
More wallets can easily be added in the future.
Also, some of the API endpoints have been rewritten. One can query all the wallets available with a call to GET /wallets. This returns a list of identifiers of each wallet (i.e. btc and mc). Each wallet has various methods that should be implemented:
This allows us to get rid of the PaymentProviders in the current decentralised market code and use wallets that are integrated in Tribler instead.
Finally, the GUI has to be redesigned slightly to support multiple wallets and multiple assets.
Good progress. If now API access is hacked, wallet access is possible. Needs to be hardend.
Privacy of Traders problem description
https://www.sharelatex.com/project/58c7d6390d2b81b36b2736a3
0) connectable ! Control of wallet! New message order-match-made
@devos50 critical above item slipped of the roadmap. We need to detect if peer is connectable. Everything assumes full connectability.
A small update here. Last week, I've been working on writing a big integration test that tests the decentralized market from ask/bid dissemination up to and including making transactions (with real bitcoin!). This works well and the Jenkins job can be found here: https://jenkins.tribler.org/job/pers/job/market_community_btc_credits_test/. The wallets used in this test are encrypted.
In addition, I've spent some time improving the incremental payments system. Also, I've included a bloom filter in each introduction request so the order books are synchronized between two users. This addresses bootstrapping problems since we have no persistency of orders in our market.
Also, the timeout mechanism of asks and bids has been fixed and I've added an event so orders are dynamically removed from the GUI. This all works pretty neat.
@synctext regarding the connectability of peers, I rather implement a generic check in Tribler for this since there might be more components in the future that requires connectability. Do you agree if we just disable creating new orders and display a warning if a peer is not connectable for a first iteration?
BTC <-> Tribler reputation can now be exchanged without problems. In addition, I've added support for trading between multiple wallets, like a real currency exchange. This means that we can also add more types of wallets later.
Existing decentralized solutions:
Comparable centralized solutions for cryptocurrency trading:
More related work:
(decentralized) matching:
This video explains why it's hard to build order books on the blockchain. I should note that they assume a "traditional" blockchain with proof-of-work consensus which causes latency and thus possibilities for market/order manipulation.
Must-read related work: http://www.econinfosec.org/archive/weis2014/papers/Clark-WEIS2014.pdf
Beta testing branch market_community: no tracebacks and able to do some trading.

able to create negative balance on my Tribler reputation credits. We conducted a collusion attack on the live network. We did several back and forth transactions to create an endless amount of reputation. Note the -1*10^12 reputation in the screenshot below.

Nashx: "NASHX is about enabling two untrusted parties to make safe exchanges online by putting them in a Mexican standoff. We put two untrusted parties into Nash equilibrium, through a military strategy called Mutually assured destruction so that neither party has anything to gain by scamming one another." (http://nashx.com/About)
They use a neat strategy but not decentralized. Also nice to read about http://en.wikipedia.org/wiki/Mexican_standoff and http://en.wikipedia.org/wiki/Mutually_assured_destruction :)

When running some experiments on a larger scale, it turned out that there were still some errors that occurred in very unlikely circumstances. It took me quite some hours to hunt these down and fix them since I had to go through many MBs of log files.
The experiment now seems to function as it should and I'm ready to extract the first graphs out of it.

First (very preliminary) results with an order book where the Google stock symbol is traded:

Note that the total quantity traded is barely affected when the network size increases. This is a promising result but the order book itself does not generate a very high load on the network. I will try with another order book that generates more traffic to see what happens.
TODO:
Progress: https://www.sharelatex.com/project/594baae7e341f31a47fc0a13
Update: first experiment with a third-party matchmaker succeeded, time to scale this up and test it better. In the image below, node 1 is the matchmaker that matches node 2 and 3 who have created an ask and bid respectively.

Taxi experiment using a real-world Uber dataset up and running: https://jenkins.tribler.org/job/pers/job/taxi_experiment_devos50/.
Related work bitsquare decentral market:
Redundant data storage (flooded to all peers) and
Resistant against spam/flooding
So please copy or try to understand their magical solution
First initial results of taxi-simulation using the market:



After considerable effort, I managed to compile and run bitshares on the DAS5 (so we can compare it against our own implementation). I had to compile my own version of GCC, OpenSSL, CMake and Boost but it seems to work now.
After some thinking, I feel that that the we are not really using the power of (our) blockchain (TradeChain) in the market implementation. Instead of using TradeChain as a post-market ledger, I envision it to be the core component of the market, used to account all ask/bid/order cancels, transactions and payments. In this scenario, the market becomes properly blockchain-regulated (or blockchain-powered I guess).
There are various advantages of doing this, the most obvious one being that all operations in the market become tamper-proof and irrefutable (this is already a property of the decentralized exchanges Iâm comparing with, i.e. Waves and Bitshares). Making TradeChain an essential component in the market helps to make a more fair comparison with other blockchain-based exchanges. Another advantages is that we can combine gossiping of the blockchain and order synchronization between peers (currently, these are two separate processes, leading to increased communication costs). Finally, it provides more transparency since all market manipulations are recorded on TradeChain.
The only problem I foresee here is that some operations recorded on the TradeChain do not involve a transaction counterparty, for instance, cancelling one of your own orders. As a consequence, the block that captures the order cancellation only contains one signature, namely your own. To ensure entanglement, I propose to use one of the matchmakers as âwitness nodeâ that verifies that you have cancelled the order.
I think we have a strong platform to sell after we make TradeChain our core component: decentralized and scalable matchmaking, irrefutable and transparent transactions, zero transaction fees and near-instant clearing and settlement.
@synctext do you agree with this?
Got the experiment with the Waves platform completely working: https://jenkins.tribler.org/job/pers/job/waves_experiment_devos50/57/. However, it seems that they use a centralized matchmaker server so it's not as decentralized as they claim. Transfer of value is recorded on a global blockchain however. Also, for every new buy/sell order, a small transaction fee has to be paid to the matchmaker.
The Bitshares market is now also fully functional within Gumby (up to the point where I can make buy and sell orders): https://jenkins.tribler.org/job/pers/job/bitshares_experiment_devos50/116/. We are now ready to compare our implementation against these markets đ
Next focus will be the refactoring of the market to make TradeChain our central component.
more related work, social markets: https://thenextweb.com/contributors/2017/08/29/can-blockchains-replace-retail-giants-like-amazon-ebay/#.tnw_tyPxx71b
Another ICO {scam} exchange market with low/no fees: https://bitcointalk.org/index.php?topic=2091630.0
Ready for business: 2019 :-)
Related work: https://ico.wcex.co/whitepaper?lang=en (centralized but low fees)
On the Impossibility of Fair Exchange Without a Trusted Third Party shows that it is impossible to facilitate a fair exchange without a TTP being involved. This is the reason why incremental payments should be used. Filecoin uses a similar philosophy, however, they consider this as future work while we have full support for incremental payments and transaction recording.
Bitcoin Historical Data - Bitcoin data at 1-min intervals from select exchanges, Jan 2012 to May 2017 and other datasets at that site.
Now that the market is functional and the first emulation results are available, I will focus on improving the security of our platform. This includes a (basic) defense against the Sybil-attack using Temporal Pagerank. The unique property of Temporal Pagerank is that it incorporates the notion of time. The temporal aspect is often disregarded when we consider defenses against the Sybil attack (see Exploiting Temporal Dynamics in Sybil Defenses). The structure of our transaction ledger (TradeChain) is used as input for this algorithm. It has been proven that Temporal Pagerank is resistant against historical Sybil attacks. Additionally, it is computationally cheap.
At this point, the algorithm has been implemented and integrated in Tribler (PR will be opened soon) and the performance of the mechanism will be evaluated using a real-world dataset.
The paper Bazaar: Strengthening user reputations in online marketplaces describes a novel technique to determine transaction risks in an online marketplace. The key idea is to create a _risk graph_ and perform a max-flow computation on it from a specific buyer to a seller to asses whether a transaction should be flagged as _fraudulent_ (or high-risk). Since max-flow computations is an expensive technique, they split up the complete graph into multiple, smaller graphs in a smart way. This provides a speedup of around 3x.
Their experiment is based on scraped eBay data, containing millions of purchases. The algorithm is driven by user-feedback where new feedback, either positive or negative, modifies the risk graph.
After a bit more research I realized that the problem is not about sybil _detection_ but rather about sybil _prevention_. Temporal Pagerank is not designed to detect Sybils since they are not guaranteed to be assigned a lower trust score than honest nodes, however, the effects of a Sybil attack on reputation are limited (but not as strong as NetFlow).
Fortunately, Temporal Pagerank is an asymmetric reputation system since it's personalized (the random walk starts from the set of your own half-interactions). This is beneficial since it has been proven that symmetric reputations mechanism cannot be Sybil-proof. Examples of symmetric algorithms are EigenTrust and regular PageRank.
I've considered various dataset to evaluate Temporal Pagerank, however, there have been some issues:
While I agree that using a social network dataset is nice, it lacks some desired properties that make Temporal Pagerank work. Additionally, I don't want to derivate much from the domain I've been exploring (peer-to-peer markets) so for now, I propose that I use my own scraped dataset with eBid transactions. This dataset contains 246.181 transactions, created by 13.955 users. Each transaction has a value (so it's a weighted graph) and a timestamp (so the set of transactions is ordered). So it contains all the properties we want and it's data from an e-commerce platform.
Next step is to perform a small (local) experiment with just the reputation algorithm to see how much influence Sybils have on their ranking (similar to the method described here). Next, we can emulate the market on the DAS-5, with crawling, and perform a Sybil attack to see how it works in a complete environment with nodes crawling the TradeChains of others.
I just realized that NetFlow will not work for computing reputations of traders. Imagine a transaction between user A and B where a total value is exchanged of 20 dollars. Now, this is represented as an edge from A -> B and with an edge from B -> A with a weight of 20. However, when performing the first step of the NetFlow algorithm, the capacities of all new edges will always be zero (since the maximum flow from A -> B is the same as the maximum flow from B -> A) and as a consequence, the final trust scores of all agents will be zero. In fact, NetFlow is based on inequality between consumption and contribution.
Update: this also holds for the BarterCast algorithm.
I've performed a few experiments with Temporal PageRank. First, I've rerun the experiment of Pim where he determined the computation time required for the algorithm. Instead of running it once, I've averaged the results over ten runs. We use the scraped data from eBid (described in one of my previous comments). The horizontal axis shows the total amount of transactions in the graph and the vertical axis the computation time. The results are shown for the preparation time of the data structure and the actual computation time for Temporal PageRank. We see that Temporal PageRank is a feasible algorithm, even for a graph with many traders and transactions.

However, a more interesting question is _how much reputation Sybil attackers are able to gain with Temporal PageRank_. To determine this, we perform an artificial Sybil attack as follows: first, we pick 100 random nodes who will become attackers. Each of these attackers introduce a varying amount of additional Sybil nodes and initiates a transaction with a value of 1.000.000 with this Sybil. It has been proven that this gives the maximum amount of reputation to an attacker. We consider different amounts of additional Sybils introduced; 1, 2, 3, ... 10. We are interested in the average increase of PageRank score and rank by attackers when they perform a Sybil attack (this metric is used by most papers I've found that evaluate Sybil Attacks on PageRank). We consider three (related) reputation mechanisms: PageRank, Personalized PageRank and Temporal PageRank. The results of this experiment are shown in the following figures. As we see, Temporal PageRank is more resistant against Sybil attacks than the other two algorithms (yay!).


I was thinking a bit about the current implementation of the decentralised market in Tribler. While it's working (https://jenkins.tribler.org/job/pers/job/market_experiment_devos50/732/) and contains an implementation of the Temporal Pagerank algorithm, next point of actions can be the following:
ACM publication related work: decentralized blockchain-based electronic marketplaces. Discussion at YCombinator.

Very naive flow diagram, real inter-continental trade lanes are extremely difficult to track. Which person do you trust to track container contents in Singapore, Taiwan or Shanghai? Who is to blame for breakage?
Related work on market for labor and tasks:
"This article will provide a theoretical compass to assist in navigating the reinvention of the company. In the same vein, the seismic movements that have fractured the firm, hence redrawing labour lawâs borders will be investigated. The exploration is organized as follows. First and foremost, attention will be devoted to the doctrinal debate on the fragmentation of the firm and the decentralisation of the production cycle. "
The Invention of the Future. Does âPlatformisationâ Redefine the Notion of the Firm?
Bitshares live exchange (https://wallet.bitshares.org/#/explorer/blocks):

Really decentral related work? https://github.com/KomodoPlatform/BarterDEX "The Komodo security services are performed by notary nodes"
Docs: http://barterdex.readthedocs.io/en/latest/faq.html#how-to-get-listed-on-barterdex
cost: also called the taker fee. This is about 0.15%
I've listed BarterDEX already in my related work comment. At that time, there was no code. It seems that there's a beta available now. Their technology heavily relies on atomic swaps, a feature that requires BIP65 implemented. While this ensures that exchange of currencies is either executed or not at all, its functionality is limited to trading of cryptocurrencies.
Browsing a bit through their documentation, I found this comparison between state-of-the-art DEX platforms (the last row is quite arbitrary chosen):

I will try to get some more information about their decentralized matching algorithm. Curious to know how they implemented that.
They haven't done any scalability experimentation at all, after reading through their whitepaper. Also, some statements they make, are fuzzy:
With 100 full nodes, thousands of non-relay nodes can be supported, possibly tens of thousands, though that number has not been reached in practice, so we will have to wait and see what the real world limitations are.
... In practice, we are seeing the nearly instantaneous response when all the parameters are properly met.
I compiled BarterDEX and got it running on the DAS5, it's ready for some experiments đ
Extracted from the IDEX whitepaper:
Due to the competitive nature of the space we are not revealing the exact proposed method for decentralizing the orderbook at this time
Also, according to the whitepaper, their distributed order book will be live in Q3 2018.
Even more fantasy and dreaming from their main project, Aurora (https://auroradao.com/assets/Aurora-Labs-Whitepaper-V0.9.5.pdf):
In addition to guaranteeing open access, operating the infrastructure in a distributed manner brings many additional benefits. [...] Additionally Aurora will be able to access computing power for the best rates possible. It is conceivable that Aurora will eventually incorporate machine learning algorithms operate an AI banker. Operating on a distributed network would give Aurora access to a lot of cheap computing power.
Epic text!
I might have fried the DAS5 cluster at the VU but I managed to reach over 30.000 trades/sec.
The following graph gives the relation between the total number of traders in the network and the average global throughput in trades per second. Each trader trades with another trader at a rate of 20 trades/sec, for a period of 30 seconds. The graph is made after optimizing the code and storing all Trustchain records in memory such that lookups are _very_ efficient.
Also, the graph strongly suggests horizontal scalability.

Repeated the OpenRide experiment, here are two rough plots (still needs some polish and I'm running it more times so I can add some error bars). During the experiment, I differ the broadcast settings, in particular, the fan-out _f_ and _TTL_. So when using _f = 10_ and _TTL=2_, each new ask/bid order reaches 10 + 10^2 = 110 nodes. As we see, lower values of _f_ and _TTL_ lead to suboptimal efficiency, in particular in the situation where _f = 5_ and _TTL = 2_. Also, note that increasing the broadcast range further doesn't really improve the matching efficiency anymore.

Average bandwidth usage per network participant:

https://en.m.wikipedia.org/wiki/MyersonâSatterthwaite_theorem
"there is no efficient way for two parties to trade a good when they each have secret and probabilistically varying valuations for it, without the risk of forcing one party to trade at a loss."
Don't forget Bitbay #BAY (Bitbay.market which is also a decentralized market with smart contracts.
I now have a trading bot running on the market testnet, which periodically (every 35) creates an order, alternating between an ask and a bid. See here for the latest orders of this node. Note that these blocks are not dual-signed since they are source blocks (and can have any counterparty). I will run this overnight to see whether things work as expected.
Next step: add a second node to the testnet and let these two bots trade.
Nice! This could be the V7.2 key feature. A testnet wallet auto-activated and instant live animation would be cool TorrentFreak promo points.
Gigachannel feature will not be fully usable and have gossip updates for 7.2.
After some major refactoring, matchmakers no longer reserve some quantity in their order books when matching. Instead, any conflicts should be resolved between the two trading parties.
The motivation behind this change is that I noticed during my experiments that matchmaking becomes very inefficient if assets are reserved. By avoiding the reservation of assets in the order book, the same order can be matched against multiple other orders and a match message will be sent to all identities behind the matched orders now. Intuitively, this should lead to better matching efficiency but I should validate this with some experiments on my order datasets.
Lots of related work appearing. As discussed indeed 1 common theme. We need reputations, we are not working on it, and concrete plan is lacking.
https://hackernoon.com/dharma-protocol-tokenized-debt-and-funding-through-decentralized-systems-384527f1a75d
Since our market is mostly accountability-oriented, I think a reputation system is a valuable addition and a natural extension of this line of work.
Sorry, to clarify: common theme on these white papers: they have no reputation system, they critically need one, and are delaying work on it. Fundamental science: universal reputation system.
phd thesis outline, outcome of discussion:
After (almost) a week of work, I have the following progress:
venv with Python 3 and run the AnyDex validation fully with Python 3. Not sure about any improvements regarding speed so far.Next, I will focus on some fundamental issues, namely counterparty fraud detection and improved trade accountability. Hopefully, I can make some progress with the GUI next week, and setup some unit tests for the REST API.
I think the issues raised in this ticket have been sufficiently addressed with the deployment of AnyDex and our upcoming journal article đ .
Most helpful comment
I might have fried the DAS5 cluster at the VU but I managed to reach over 30.000 trades/sec.
The following graph gives the relation between the total number of traders in the network and the average global throughput in trades per second. Each trader trades with another trader at a rate of 20 trades/sec, for a period of 30 seconds. The graph is made after optimizing the code and storing all Trustchain records in memory such that lookups are _very_ efficient.
Also, the graph strongly suggests horizontal scalability.