xxB-2024-001: xxDK C Library Implementation

Bounty xxB-2024-001: xxDK C Library Implementation

Overview

This bounty rewards developers for implementing full language bindings for the xxDK library, focusing on C with optional extensions for Rust and C#. C support enables support for Rust, C#, Python, Ruby, etc.

Prize Pool

Total Prize: 1,000,000 xx (~$50,000 USD)

Breakdown:

  • C Library Implementation: 500,000 xx
    • This must be completed before work on Rust or C# can begin. Rust and C# can be worked on in parallel.
  • Rust Bindings Extension: 250,000 xx
  • C# Bindings Extension: 250,000 xx

Requirements

Eligibility

  • Participants must complete KYC verification
  • Participants from OFAC-sanctioned countries are not eligible
  • Multiple contributors may collaborate on submissions
  • Existing xx network contractors are not eligible

Technical Requirements

  1. C Library Implementation

  2. Optional Extensions

    • Rust Bindings

      • Full FFI bindings to C implementation
      • Idiomatic Rust API
      • Documentation and examples
      • Cargo package integration
    • C# Bindings

      • Full P/Invoke bindings to C implementation
      • Idiomatic C# API
      • Documentation and examples
      • NuGet package integration

Submission Requirements

  1. Source code must be:

    • Open source (same license as xxDK)
    • Submitted via merge request to appropriate repository
    • Well-documented
    • Passing all tests
    • Following project coding standards
  2. Documentation must include:

    • API reference
    • Integration guide
    • Example applications
    • Build/installation instructions

Judging Criteria

Submissions will be evaluated on:

  1. Completeness of implementation
  2. Code quality and maintainability
  3. Documentation quality
  4. Test coverage
  5. Performance
  6. Ease of integration

Timeline

  • Submissions accepted until completed or program ends
  • Reviews will occur within 2 weeks of submission
  • Prizes paid within 30 days of approval

Payment Terms

  • Prizes paid in XX tokens
  • Multiple submissions may split prize pool
  • Major awards (>50,000 XX) subject to 6-12 month linear vesting
  • All payments subject to KYC approval
  • We may make partial payments at our discretion
  • Payments may be locked in a linear vesting schedule for up to 1 year

Contact

Submit questions and proposals through:

  • Repository issues
  • Developer forum
  • Developer chat channels

Please respond in the forum if you are pursuing this grant.

Legal

  • xx network reserves right to modify bounty terms
  • All submissions must comply with applicable laws
  • Participants retain rights to submitted code under project license
  • xx network not responsible for lost or invalid submissions

Last Updated: November 12, 2024

1 Like

Hi all, I worked with @rick on the initial Rust bindings earlier this year, and I would be happy to continue working to make them and the C bindings more complete.

For background, I’m formerly the lead engineer of the Mobby blockchain platform, where I worked with Rick for a period of a couple of years, and I’ve been working professionally with Rust and systems engineering more generally for most of my career.

Let me know if you need any more information!

3 Likes

This sounds great @julia, glad to have you back.

Can you propose some milestones for the first C Library part of the project?

Apologies for the delay, I’ve been busy traveling!

A preliminary list of milestones:

  1. Core CMix functionality (creating/loading keystores, creating/managing reception IDs, starting network threads, etc; the basic functionality common across use cases)
  2. E2E and connect client/server functionality
  3. Restlike functionality
  4. File transfer functionality
  5. DM functionality
  6. RPC functionality*
  7. Misc. functionality
  8. Finalize documentation, test suite, build system

I’m thinking of approaching the library functionality in chunks, focusing primarily on being able to translate existing examples (e.g. from the xxdk-examples repo); this is the goal of the first 6 milestones. For each of these I would aim to have the relevant functions callable from C, the relevant examples translated, and at least a cursory test suite and documentation.

(It’s entirely likely I’m missing large swaths of functionality out of unfamiliarity here; lemme know if this seems like a reasonable division of the library functionality.)

At that point, I’m thinking there will likely be some smaller/more obscure pieces of functionality that remain inaccessible from the C bindings; identifying and implementing/documenting/testing these is the purpose of the 7th milestone. Additionally, the test suite and documentation may need expansion and/or cleanup, and the build system may need cleanup; this is the 8th.

I’m aiming to start work in earnest early-to-mid next week, after I’ve gotten home from the holidays.

*I remember when Rick and I were working on the Rust bindings the RPC functionality was still something of a work in progress, and a scan of the current client repo indicates that it’s still fairly barebones. I suppose it’s still a bit down the line so the question is mostly moot for now, but is that in fact within scope for the bindings?

1 Like

These look good. You are good to go to get started on this. We will partial award as you complete the milestones. Please let the forum know if you need help or drop it moving forward.

2 Likes

Hi? Julia, A few simple questions.
What is your GitHub ID/username?
When will the implementation of the library start?
Could provide a link where community members can track the progress of the development.
Thank you.

Hi? Julia, A few simple questions.
What is your GitHub ID/username?
When will the implementation of the library start?
Could provide a link where community members can track the progress of the development.
Thank you.

See the news post which links the repository for this information.

As mentioned in the Foundation’s reply, it looks enough info is provided in the post above (xxB-2024-001: xxDK C Library Implementation - #2 by julia).

Could provide a link where community members can track the progress of the development.

I don’t mean to be against all these questions, but the curator, not us, is in charge of progress tracking as a bunch of other things (including KYC, reviewing the code, etc.) which is why that work (of the curator) isn’t free, by the way.
The grantee has no other obligation than to deliver as per milestones mutually agreed upon prior to the vote of approval. They can let us watch, but they don’t have to - it’s up to them.
From a more practical perspective: there’s nothing we can do with the code until it’s ready unless we want and can contribute for free, but why would the grantee spend time on dealing with your pull requests unless you’re a C guru and enjoy contributing for free, in which case we’d be better off if you took this task on for free and spared the Foundation the expense and effort.
The more burden on the grantee, the slower and/or more expensive development gets.

First milestone complete! You can take a look at the current state of things over at https://git.xx.network/elixxir/libxxdk/-/tree/c-bindings.

An overview of what’s done:

  • Core/common Cmix functionality:
    • Creating/loading Cmix instances.
    • Starting/stopping network follower tasks, with callbacks for monitoring network health.
    • Management of reception IDs and contacts.
    • EKV reads/writes.
  • Logging configuration: small interface for redirecting xxDK log output to either files or to a custom log message handler, to enable integrating xxDK log output into native logging systems in other languages.
  • Some incomplete example programs, translated from the Go examples.
  • A very preliminary automated test suite.

Some miscellaneous design notes:

In general, I’ve tried to make the bindings behave as much like idiomatic C as possible. For instance, this means no functions with multiple return values; functions that may fail return a potentially-null error string, and output their success results via out pointers.

Error strings are stored in library-managed thread-local storage which will be overwritten by subsequent errors. Currently, potentially-failing functions return pointers to the error string directly, though it would be more idiomatic to return e.g. an int or enum indicating success or failure and to provide a single xx_GetError function to get the most recent error string.

I’m currently using a manually-written xxdk.h as the C interface to the library, instead of the Cgo-generated header. The generated header is not ideal for use as an actual C library interface, for several reasons (namely: inability to add const or other qualifiers to functions parameters/return values, lots of extraneous/internal/irrelevant definitions, inclusion of bindings-internal headers forcing these to be available to library users, lack of include guards for the main body of the library), and a manually-written one is much cleaner and more usable.

One downside of using a manually-written header, of course, is that the generated header is automatically compatible with the Go library, whereas a manually-written one needs to be manually checked and updated for compatibility. It would be good to, at the very least, find a way to automatically test the types of the manually-written definitions against the generated ones. I personally think that the gain in library usability is big enough to justify the loss in maintainability, though I would happily accept comments/opinions on this.

Please feel free to reach out with any thoughts or comments!

3 Likes

I’m not qualified to comment, so all I’ll say is thank you :slight_smile:

Would it be possible to create a basic Python example, or maybe recommend how to go about using Python with xxDK and leave that as an exercise to the enthusiast?

Rick has finished his review here:

Payouts for milestone 1:

https://explorer.xx.network/extrinsics/17326095-1

https://explorer.xx.network/extrinsics/17326402-1

2 Likes