Skip to content

Instantly share code, notes, and snippets.

@myrual
Last active December 18, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myrual/20c3ca6d0a236c8b766b40489c87ff68 to your computer and use it in GitHub Desktop.
Save myrual/20c3ca6d0a236c8b766b40489c87ff68 to your computer and use it in GitHub Desktop.
A short introduction to verify transaction

This is a short introduction for Mixin Kernel. It explain how Mixin Kernel verify a transaction. Code repo

When a new transaction first arrived at the Mixin Kernel node, the following steps will happen.

  1. Code: kernel/queue.go#L11. This code just do plain raw transaction format validate e.g. version, extra size, check the input total amount equals output amount, validate the signatures for each input and ensure the UTXO is not spent yet.

  2. Code: kernel/queue.go#L19. This is a standalone loop thread to poll all the queued transaction in step 1 to ensure that all transactions are processed in a single thread, because step 1 is called by RPC from many different connections.

  3. Code: kernel/graph.go#L13. This method is called by step 2 and step 8 to queue the unsigned empty transaction to the graph round pool.

  4. Code: kernel/graph.go#L18. This is a standalone loop thread to poll all the queued snapshots in the graph round pool to ensure that all snapshots are processed in a single thread, because step 3 is called by self transaction poll thread and peer snapshot broadcasting.

  5. Code: kernel/graph.go#L48. This is the key consensus method to do graph snapshot validation and signing. It first does a transaction format validation the same as step 1, then ensure all node signatures in the snapshot are valid and unique. If the signatures are empty then sign it in step 6, otherwise verify the signatures in step 7.

  6. Code: kernel/graph.go#L204. This method first ensure that the empty snapshot is made by the node itself in step 2, otherwise will skip the signing and ignore it. Then wait until the local timestamp is after the round end of the node itself. If the snapshot timestamp is within the 3 seconds round gap, update the round end to the snapshot timestamp, otherwise improve the round start or queue the snapshot to wait for further signing. Sign the snapshot with the node private spend key and broadcast the signed result to all gossip peers.

  7. Code: kernel/graph.go#L116. This method verify the snapshot is signed by other nodes in the same logic as step 6, sign it if possible. If the snapshot is signed by enough consensus nodes, then the snapshot will be considered as finalized and written into the snapshots database. The result will also be broadcasted to all gossip peers.

  8. Code: kernel/peer.go#L193. This is a standalone loop to handle incoming snapshot broadcast from other gossip peers. And will put the valid snapshot into step 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment