Tribler / tribler

Privacy enhanced BitTorrent client with P2P content discovery
https://www.tribler.org
GNU General Public License v3.0
4.86k stars 451 forks source link

Blockchain Engineering 2023 - token transaction engine #7293

Closed synctext closed 3 months ago

synctext commented 1 year ago

Token transaction engine. Create a lightweight and fast token transaction engine for mobile devices. Your engine should be able to process 1000 transactions per second with standard 4G connectivity. Record these transactions within a simple SQLite backend. Realise simple primitives such as send/receive token primitives. Required background reading: ConTrib: Universal and Decentralized Accounting in Shared-Resource Systems.

synctext commented 1 year ago

Not yet read the required background reading. @kandrio checked out the superapp, confused about the modules. Also @AkiSchmatzler

AkiSchmatzler commented 1 year ago

meeting with @kandrio , @mehulbhuradia , and myself

transaction possible implementation

from the example trustchain docs

Initiator creates a proposal halfBlock, signs it with his private key, creates the wrapper halfBlockBroadcast that contains the proposal block. He sends the broadcast to everyone. The receiver (the one which the transaction is intended for) creates an agreement block (AgreementHalfBlock), they sign it. Then, they put the proposal and the ageeement in a block (halfBlockPair) (which represents the completed transaction) and broadcast it to the network (halfBlockPairBroadcast message). The fact that everyone in the network is aware of every step of the transaction (broadcast of proposal and agreement) assures its integrity.

synctext commented 1 year ago
AkiSchmatzler commented 1 year ago

this link contains all the stuff we need to create our community and send our messages over the network : overlay kotlin ipv8

kandrio commented 1 year ago

First Iteration on Transaction Engine

@luukvancampen mainly got his hands dirty with the code in the weekend. At the current state, our app is able to:

  1. Present a list with all the peers in the community.
  2. Allow the user to choose one peer and send a transaction proposal to that peer
  3. Allow the user to receive a transaction proposal (through a pop-up) and confirm it through the click of a button.

NOTE: It seems that step 2 (sending of proposals) does not work consistently. We noticed that in some cases, the sender sends a proposal and no pop-up shows up in the receiver's device. We have been trying to debug this for hours, but no solution has been found yet. We could use some feedback on if this is expected and how to tackle it.

Development repo: https://github.com/luukvancampen/blockchain-engineering

Here is how the main app looks like currently:

synctext commented 1 year ago

Significant experience with @luukvancampen, the "1000" button is exactly what is needed. Just a bit worried that we don't have 5 working developers. Bonus point: fix the tutorial or expand with details within a Pull Request. Code for binary transfer testing (part of the digital Euro): with lost packet reporting Updated digital Euro and packet loss report and try out those IPv8 improvement PRs Everybody was a bit stuck, try to get 3 emulators to talk to each other. Reliable foundations for future sprints.

kandrio commented 1 year ago

Next internal meeting: Wednesday, March 8th at 17:00

To-do

Here are the next tasks we want to achieve, along with the developers that own them:

  1. make 2 emulators communicate with each other: @tudatt
  2. list in the application the bootstrap servers (if not bootstrap servers shown as green, then the app is not properly connected and an informative error should appear) @AkiSchmatzler
  3. check the PR the professor sent us and try to initialize the community as shown in the PR (https://github.com/ChrisSBras/trustchain-superapp/pull/4/files) @mehulbhuradia
  4. make 1000 transactions a second work using the new PR that the professor sent @luukvancampen
  5. find out why we get a UniquenessConstaint error sometimes when the receiver tries to insert an incoming transaction into their SQLite database. @kandrio
    • ANSWER: It turns out that this error shouldn't bother us too much. The root cause of the error is that, whenever we send a transaction, we proadcast it in the network, and each node shares it with their peers. As a result, the receiver might receive the transaction multiple times and try to add it multiple times in the SQLite database as well, hence the Uniqueness error.
  6. build the "confirm a proposal" functionality @kandrio
kandrio commented 1 year ago

Show Bootstrap Servers

I'll use this comment to expose my progress on extending the Detoks app to show the list of connected bootstrap servers.

How to find the list of bootstrap servers

Here's the piece of code that loads a List of the IPv4Addresses of the bootstrap servers into bootstrap_servers:

import nl.tudelft.ipv8.Community

val bootstrap_servers = Community.DEFAULT_ADDRESSES

Actually, DEFAULT_ADDRESSES looks like this:

DEFAULT_ADDRESSES: List<IPv4Address> = listOf(
    // Dispersy
    // Address("130.161.119.206", 6421),
    // ...
    // IPv8
    // Address("131.180.27.161", 6521),
    // ...
    // py-ipv8 + LibNaCL
    IPv4Address("131.180.27.161", 6427),
    // kotlin-ipv8
    IPv4Address("131.180.27.188", 1337),
    IPv4Address("131.180.27.187", 1337)
)

Indeed, if we take a look at the debug UI feature (uses the code from above) of the superapp, we can verify that the only addresses that are shown are the ones that are uncommented in DEFAULT_ADDRESSES:

debug_bootstrap_servers

We want to show something similar in the Detoks app as well.

TO BE CONTINUED: For further updates, see the following comment by @AkiSchmatzler who took over this effort:

kandrio commented 1 year ago

Confirm a Proposal

Current Situation

Currently, the following happens:

End Goal

We'll consider this effort successful if:

  1. [X] The incoming Proposal dissapears from the UI of the receiver once the user clicks on the CONFIRM button.
  2. [ ] The user that created the Proposal gets notified that it has been accepted by the receiver.

Solution

The createAgreement API function

In order to implement the functionality described in goal [1], we created the createAgreement API function that does the following:

  1. Removes the confirmed Proposal from the local proposals database (contains all incoming un-confirmed Proposals)
  2. Notifies the proposalAdapter that the proposals ArrayList is updated (so that the confirmed proposal dissappears from the UI)
  3. Creates and sends an Agreement block to the sender of the Proposal, using the createAgreementBlock API function of the ipv8 library.

Here's how the createAgreement API function looks like so far...

private fun createAgreement(block: TrustChainBlock, proposalAdapter: ProposalAdapter) {
    for (i in proposals.indices) {
        if (proposals[i].block == block) {
            proposals.removeAt(i)
            proposalAdapter.notifyItemRemoved(i)
            break
        }
    }
    // Get a reference to the TrustChain community
    val trustchain = IPv8Android.getInstance().getOverlay<TrustChainCommunity>()!!
    // Create an Agreement Block
    trustchain.createAgreementBlock(block, mapOf<Any?, Any?>())
}
AkiSchmatzler commented 1 year ago

about the bootstrap servers

In the bootstrap-servers branch of our development repo, I added a button bootsrap_servers, which when pressed opens a popup window showing the bootsrap servers :

slay

[update] the popup now also shows the walkable addresses, the WAN and the LAN addresses. There are some issues with showing the bootstrap servers as up or down --> to discuss in next meeting

synctext commented 1 year ago
luukvancampen commented 1 year ago

I made sure that the "1000" button works. It sends 1000 proposals to the specified peer and the peer signs them. The sender of the proposals then shows in the app how many agreements it has received and to what proposals the agreements are, so we can do basic packet drop detection. All proposals are assigned a number from 0 up until 999 in order to count received agreements. Each "benchmark run" get its own UUID so we do not accidentally count an agreement for the wrong benchmark.

luukvancampen commented 1 year ago

We will have an optional meeting saturday at 13:00. The next meeting will be monday at 17:00. Both meetings will be online.

Deadlines for monday

tudatt commented 1 year ago

Progress last sprint cycle:

Andrei (tudatt):

  1. Implemented a "dummy node" in Kotlin, as LightweightTxAppKt that can be run seamlessly in the terminal
  2. Added TransactionEngine API V1 and its implementation TransactionEngineImpl that can be extended by any Community, so it can benefit from sendTransaction functionality
  3. Implemented functionality for sending encrypted/unencrypted blocks to specific/random peers in the LightweightTxApp using TokenTransactionEngine.
kandrio commented 1 year ago

Progress last sprint cycle:

Kostas (kandrio):

  1. Worked on top of @tudatt's "dummy node" implementation and managed to make peers send basic messages to one another.
  2. Integrated our progress with the upstream master branch.
mehulbhuradia commented 1 year ago

Progress last sprint cycle:

Mehul(mehulbhuradia):

  1. Managed to get the python dummy nodes running but discarded the idea as @tudatt figured out a way to have them in kotlin and this allowed them to reuse existing code.
  2. Worked on top of @tudatt's and @kandrio's implementation of the dummy nodes and the TransactionEngine adding the functionality to receive incoming messages and process them.
AkiSchmatzler commented 1 year ago

progress last week (@AkiSchmatzler ):

image

image

luukvancampen commented 1 year ago

Luuks progress:

synctext commented 1 year ago
mehulbhuradia commented 1 year ago

Tasks going forward: (meeting on 25/3/23)

  1. Create the transaction api using code from kandrio-dummy and other-group-progress
  2. Create a pr for the api
  3. Create flamegraphs
  4. Add UI for benchmarking
  5. Extend the API to search and view the blocks?
kandrio commented 1 year ago

Progress last sprint cycle:

Kostas (kandrio):

  1. Created our first PR that introduces our TransactionEngine API and our LightweightTxApp:
  2. Addressed review comments.
  3. Created review branch with improvements:
  4. Waiting for @OrestisKan's follow-up review comments
tudatt commented 1 year ago

Progress last sprint cycle:

Andrei (tudatt): branch benchmark:

Questions: Right now we are only sending the block object TrustchainBlock because of the convenience of using the Builder. Should we consider creating our own, even simpler block?

AkiSchmatzler commented 1 year ago

Progress last sprint cycle. We now have the falemgraphs for :

We can now identify bottlenecks in those functions. The call to functions that have some pseudo-randomness in them seems to be a bottleneck at the moment. Example :

unencrypted Random Signed

we can see thazt our unencryptedRandomSigned function is mostly bottlenecked by the nextBytes() function. In the future, we will change the funcrtion accordingly so as to use another faster function. image

mehulbhuradia commented 1 year ago

Progress last sprint cycle:

Mehul(mehulbhuradia):

  1. Designed the functions for the IPv8 layers in the flamegraph.
  2. Currently redesigning the message handlers to echo messages, these echo messages will be used to record the time taken for the blocks to be recieved and the number of packets lost.
luukvancampen commented 1 year ago

Luuks progress:

  1. created functions for doing the first layers of benchmarking
  2. created UI for benchmakring and made sure ui can be used to run the actual benchmarks.
  3. benchmarking for actual TrustChain halfblock sending and getting proposal back is almost working.
synctext commented 1 year ago
luukvancampen commented 1 year ago

Unpolished APK: https://luukvancampen.stackstorage.com/s/1RzuNuFYpzLYGrQH

The first few steps of benchmarking can be done and it shows the time in nanoseconds it took. When pressing the 1000 button for a peer, it starts a 1000 trustchain transaction benchmark. There are some bugs in that which I will resolve. You can also create a single transaction with a peer, which the other peer then has to confirm.

AkiSchmatzler commented 1 year ago

about the flamegraphs: performance analysis

for signed permanently blocks, time is equally divided between building the block and storing it in storage, there is not much to optimize here, except if we would try and rewrite the function from the Trustchain to not use StringBuffer.append(), as it seems to be the biggest bottleneck. For the SQL storage, the getLatestQuery() call seems to be the biggest bottleneck. (same goes for signed blocks that are not permanently stored). image

--> todo: further analysis and write the results in the report, which needs to be linked in the readme

luukvancampen commented 1 year ago

Luuk's progress:

Links to original video's:

Link to APK:

IMG_6155

kandrio commented 1 year ago

Progress last sprint cycle:

Kostas (kandrio):

  1. Addressed review comments for our 1st PR that introduces our TransactionEngine API and our LightweightTxApp:
  2. 2nd PR underway that will introduce our entire backend
    • Will have it ready by Saturday 08/04/23
synctext commented 1 year ago
InvictusRMC commented 1 year ago

Hi team, can you please address the email that group II sent to you? Thanks!

kandrio commented 1 year ago

@InvictusRMC at what email did they send it?

InvictusRMC commented 1 year ago

@InvictusRMC at what email did they send it?

@kandrio apparently they only contacted @AkiSchmatzler on aki.schmatzler@gmail.com.

AkiSchmatzler commented 1 year ago

@InvictusRMC at what email did they send it?

@kandrio apparently they only contacted @AkiSchmatzler on aki.schmatzler@gmail.com.

I answered the group earlier today w the method i followed; I told them to get back to me if they still any further issues

luukvancampen commented 1 year ago

Final APK of this course:

Readme:

Pull request:

synctext commented 1 year ago