mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Spec txid wire encoding and database repair
Add client Gherkin pinning little-endian wire order for every action that embeds a parent txid (like, reply, poll option, poll vote), and a psf-memo-db Gherkin for a utility that repairs existing byte-reversed references and rebuilds the affected indexes. By specifier.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# Scenarios: Txid wire encoding - 1, Txid wire encoding - 2, Txid wire encoding - 3, Txid wire encoding - 4
|
||||
#
|
||||
# Memo actions that reference a parent transaction embed that txid as 32 raw
|
||||
# bytes. The wire order is little-endian: the reverse of the 64-character
|
||||
# display txid. The indexer reverses those bytes back into the display txid so
|
||||
# the referenced post, reply, or poll can be found. This feature pins the wire
|
||||
# byte order for every client action that references a parent txid: like,
|
||||
# reply, poll option, and poll vote.
|
||||
Feature: Txid wire encoding
|
||||
|
||||
Background:
|
||||
Given a wallet authenticated for the address bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d
|
||||
Given the wallet has spendable output to pay the transaction fee
|
||||
|
||||
Scenario Outline: Txid wire encoding - 1 a like broadcasts the post txid in little-endian wire order
|
||||
Given a post with the txid <txid> authored by the author address
|
||||
When I click the heart icon on the post with txid <txid>
|
||||
When I submit the like without a tip
|
||||
Then the wallet broadcasts an OP_RETURN transaction with the Memo like prefix and the post txid <txid>
|
||||
|
||||
Examples:
|
||||
| txid |
|
||||
| 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef |
|
||||
| 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff |
|
||||
|
||||
Scenario Outline: Txid wire encoding - 2 a reply broadcasts the parent txid in little-endian wire order
|
||||
Given I open the thread for the post with txid <txid>
|
||||
When I type a reply with the text "<message>"
|
||||
When I submit the reply
|
||||
Then the wallet broadcasts an OP_RETURN transaction with the Memo reply prefix
|
||||
|
||||
Examples:
|
||||
| txid | message |
|
||||
| 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | hello memo |
|
||||
| 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff | a second one |
|
||||
|
||||
Scenario Outline: Txid wire encoding - 3 a poll option broadcasts the poll txid in little-endian wire order
|
||||
Given a poll with the txid <txid>
|
||||
When I open the poll with txid <txid>
|
||||
When I compose an option with the text "<option>"
|
||||
When I submit the option
|
||||
Then the app broadcasts an OP_RETURN transaction with the Memo add-poll-option prefix for the poll <txid>
|
||||
|
||||
Examples:
|
||||
| txid | option |
|
||||
| 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | yes |
|
||||
| 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff | no |
|
||||
|
||||
Scenario Outline: Txid wire encoding - 4 a poll vote broadcasts the poll txid in little-endian wire order
|
||||
Given a poll with the txid <txid>
|
||||
When I open the poll with txid <txid>
|
||||
When I vote with the comment "<comment>"
|
||||
When I submit the vote
|
||||
Then the app broadcasts an OP_RETURN transaction with the Memo poll-vote prefix for the poll <txid>
|
||||
|
||||
Examples:
|
||||
| txid | comment |
|
||||
| 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | yes |
|
||||
| 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff | I choose this |
|
||||
@@ -0,0 +1,74 @@
|
||||
# Scenarios: Repair txid encoding - 1, Repair txid encoding - 2, Repair txid encoding - 3, Repair txid encoding - 4, Repair txid encoding - 5, Repair txid encoding - 6
|
||||
#
|
||||
# Older psf-memo-client broadcasts embedded a referenced txid in big-endian
|
||||
# display order. The indexer expected little-endian wire order, so it stored a
|
||||
# byte-reversed reference in the likes, postLikes, postParents, postChildren,
|
||||
# pollOptions, and pollVotes stores. The txid repair utility rewrites a
|
||||
# reversed reference to display order and rebuilds the affected secondary
|
||||
# index. It leaves correctly-encoded records untouched, leaves references whose
|
||||
# target is unknown in either byte order untouched, and is idempotent.
|
||||
Feature: Repair txid encoding
|
||||
|
||||
Background:
|
||||
Given a psf-memo-db instance with posts, likes, postLikes, postParents, postChildren, polls, pollOptions, and pollVotes stores
|
||||
Given the fixture "db-with-reversed-txid-references" is loaded
|
||||
|
||||
Scenario Outline: Repair txid encoding - 1 the repair utility corrects a reversed like reference
|
||||
When the txid repair utility is run
|
||||
Then the likes store maps like <likeTxid> to post <postTxid>
|
||||
Then the postLikes store contains 1 entry whose key starts with <postTxid> and ends with <likeTxid>
|
||||
Then the postLikes store contains 0 entry whose key starts with <reversedPostTxid> and ends with <likeTxid>
|
||||
|
||||
Examples:
|
||||
| likeTxid | postTxid | reversedPostTxid |
|
||||
| like-1 | 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301 |
|
||||
|
||||
Scenario Outline: Repair txid encoding - 2 the repair utility corrects a reversed reply reference
|
||||
When the txid repair utility is run
|
||||
Then the postParents store maps reply <replyTxid> to parent <postTxid>
|
||||
Then the postChildren store contains 1 entry whose key starts with <postTxid> and ends with <replyTxid>
|
||||
Then the postChildren store contains 0 entry whose key starts with <reversedPostTxid> and ends with <replyTxid>
|
||||
|
||||
Examples:
|
||||
| replyTxid | postTxid | reversedPostTxid |
|
||||
| reply-1 | 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301 |
|
||||
|
||||
Scenario Outline: Repair txid encoding - 3 the repair utility corrects reversed poll option and vote references
|
||||
When the txid repair utility is run
|
||||
Then the pollOptions store maps option <optionTxid> to poll <pollTxid>
|
||||
Then the pollVotes store maps vote <voteTxid> to poll <pollTxid>
|
||||
|
||||
Examples:
|
||||
| optionTxid | voteTxid | pollTxid |
|
||||
| option-1 | vote-1 | 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff |
|
||||
|
||||
Scenario Outline: Repair txid encoding - 4 the repair utility leaves correctly-encoded references unchanged
|
||||
When the txid repair utility is run
|
||||
Then the likes store maps like <likeTxid> to post <postTxid>
|
||||
Then the postParents store maps reply <replyTxid> to parent <postTxid>
|
||||
Then the pollOptions store maps option <optionTxid> to poll <pollTxid>
|
||||
Then the pollVotes store maps vote <voteTxid> to poll <pollTxid>
|
||||
|
||||
Examples:
|
||||
| likeTxid | replyTxid | optionTxid | voteTxid | postTxid | pollTxid |
|
||||
| like-2 | reply-2 | option-2 | vote-2 | 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff |
|
||||
|
||||
Scenario Outline: Repair txid encoding - 5 the repair utility leaves an unknown reference unchanged
|
||||
When the txid repair utility is run
|
||||
Then the likes store maps like <likeTxid> to post <postTxid>
|
||||
|
||||
Examples:
|
||||
| likeTxid | postTxid |
|
||||
| like-3 | deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
|
||||
|
||||
Scenario Outline: Repair txid encoding - 6 the repair utility is idempotent
|
||||
When the txid repair utility is run
|
||||
And the txid repair utility is run again
|
||||
Then the postLikes store contains 1 entry whose key starts with <postTxid> and ends with <likeTxid>
|
||||
Then the postLikes store contains 0 entry whose key starts with <reversedPostTxid> and ends with <likeTxid>
|
||||
Then the postChildren store contains 1 entry whose key starts with <postTxid> and ends with <replyTxid>
|
||||
Then the postChildren store contains 0 entry whose key starts with <reversedPostTxid> and ends with <replyTxid>
|
||||
|
||||
Examples:
|
||||
| likeTxid | replyTxid | postTxid | reversedPostTxid |
|
||||
| like-1 | reply-1 | 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | efcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301 |
|
||||
Reference in New Issue
Block a user