Giter VIP home page Giter VIP logo

dinonce's Introduction

dinonce_gopher

dinonce - a distributed nonce tracker

main branch

For most blockchain clients it is essential to keep track of transaction nonces that protect against duplicate transactions and replay attacks.

You can read more about nonces here.

Normally, a non-partitioned client application, like your mobile wallet app or MetaMask will easily do this for you, but tracking nonces gets trickier once your application needs to split-brain and run in a distributed fashion. Check MetaMask's nonce-tracker implementation here.

dinonce is a nonce ticketing service which we use at welthee to process transactions(tx) with multiple tx executors, making sure that we avoid:

  • double spending
  • filling a network's tx pool by having gaps in our nonce sequences

How it works? In a nutshell.

dinonce is designed to support ticketing for multiple nonce sequences in parallel.

An identity on a given blockchain should have it's own sequence of nonces. dinonce defines such a sequence as a lineage.

For each lineage a dinonce client can get a leased nonce ticket for a transcation, and should specify a ticket externalId which should be unique for a transaction for a given lineage. In other words, it should uniquely identify a natural transaction in the calling system.

If the operation succeeds, dinonce will reserve hold a lease for the tx's newly associated nonce.

Since most tx executors (dinonce's clients) operate with an at-least-once semantics, it is possible that the tx will:

  • complete (a.k.a will be mined on the blockchain)
  • will fail for non-transient reasons

If the tx completes successfully, then the client is expected to close the ticket, marking it unlease-able forever. If the tx fails, the client is expected to notify dinonce to release the ticket. In this case, it should be assigned to the next lease request, and be re-used as soon as possible, to avoid filling node tx pools on the blockchain network.

Client Integrations

dinonce is built using a contract first approach with OpenAPI 3.0. The API definition can be found here.

You can generate a client library for the language of your choice using the openapi-generator.

Deployment

dinonce is packaged as a Docker container and pushed automatically to Docker Hub. If you're interested, check out the Dockerfile that generates the image here.

Since we are fans of both Kubernetes and Terraform we have created a Helm Chart to easy deployment to Kubernetes. The user is responsible to create the ConfigMap dinonce config, which should contain a single config.yaml data entry and have the structure similar to this example.

We like to thing about the services we run as self-contained Terraform projects with clear external dependencies, so we've created a handy Terraform module directory to help with deployments.

Currently there is just one module that you can use, called helm-aws-rds-psql, which will create a managed AWS RDS Aurora PostgreSQL database, create a namespace in kubernetes and deploy the aforementioned Helm Chart to your cluster.

See a usage example here.

Backends

dinonce is designed to support multiple storage backends as long as they respect the above described semantics.

The initial backend we are launching is PostgreSQL. If you'd like to implement a new backend, feel free to do so and open a pull request.

dinonce's People

Contributors

renovate[bot] avatar mpdred avatar lukacsaronzs avatar

Stargazers

David Przybilla avatar  avatar  avatar Máté Lang avatar  avatar Botond Dáni avatar

Watchers

James Cloos avatar Amir Hossein Babaeian avatar Stefan Balea avatar Persea Alexandra avatar  avatar

Forkers

mpdred matelang

dinonce's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
  • ubuntu 22.04
  • ubuntu 22.04
github-actions
.github/workflows/main.yml
  • actions/checkout v3
  • actions/upload-artifact v3
  • actions/checkout v3
  • actions/download-artifact v3
  • docker/setup-qemu-action v2
  • docker/setup-buildx-action v2
  • docker/login-action v2
  • falti/dotenv-action v1.0.4
  • docker/build-push-action v4
.github/workflows/pr.yml
  • actions/checkout v3
gomod
go.mod
  • go 1.20
  • github.com/deepmap/oapi-codegen v1.13.2
  • github.com/etherlabsio/healthcheck/v2 v2.0.0
  • github.com/getkin/kin-openapi v0.118.0
  • github.com/golang-migrate/migrate/v4 v4.16.2
  • github.com/google/uuid v1.3.0
  • github.com/labstack/echo-contrib v0.15.0
  • github.com/labstack/echo/v4 v4.11.1
  • github.com/lib/pq v1.10.9
  • github.com/rs/zerolog v1.30.0
  • github.com/spf13/viper v1.16.0
  • github.com/ziflex/lecho/v3 v3.5.0
helm-values
deployments/helm/values.yaml
terraform
deployments/terraform/modules/helm-aws-rds-psql/aws-rds-psql/providers.tf
  • aws ~> 5.0
  • hashicorp/terraform ~> 1.0
deployments/terraform/modules/helm-aws-rds-psql/aws-rds-psql/rds.tf
  • terraform-aws-modules/rds-aurora/aws ~> 8.0
deployments/terraform/modules/helm-aws-rds-psql/helm/helm.tf
deployments/terraform/modules/helm-aws-rds-psql/helm/providers.tf
  • helm ~> 2.1
  • kubernetes ~> 2.2
  • hashicorp/terraform ~> 1.0

  • Check this box to trigger a request for Renovate to run again on this repository

Handling nonces of transactions removed from mem-pool

The documentation states that the package handles filling the transactions mem-pool with nonces while guaranteeing that no nonce will be missing.
Have you considered extending this package to handle nonces of transactions that were not included for a given period of time in a block and have been removed from the mem-pool.

Here is a scenario for transactions for one address:

  1. Ticket 1 (Nonce: 1) - Leased
  2. Ticket 2(Nonce: 2) - Leased
  3. Transaction 1 uses Ticket 1 (nonce: 1) with 10 gwei as gas price.
  4. Transaction 2 uses Ticket 2 (nonce: 2) with 100 gwei as gas price.
  5. Send the transactions to the mem-pool.
  6. Confirm both of the tickets since we have successful responses from the provider.
  7. 30 minutes pass and Transaction 1 and 2 are removed from mem-pool (since tx 1 had too low gas price).
  8. If we try again we continue from nonce 3 which is wrong.

A similar thing can happen if we want for transaction receipt, but chain reorganization occurs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.