Simplifying the Class A ModelSorry this has taken a few days to get my ducks in a row (will be great when I go RBB!), but I wanted to make sure what I'm proposing tests successfully and will give us the outcomes I'm looking for (simplify Class A & remove ambiguity on whether a transaction is valid or not).
I've been discussing with Tachikoma for a few days, and I think I've now done enough testing to make this official & submit a pull.
What?This pull is structured to simplify the Class A model by removing a number of potentially confusing rules and replacing them with a single defining rule.
Why?Class A is only intended to provide backwards compatibility & is not used in any of the respective wallet implementations or for any features other than basic simple send. Thus the effort being expended on Class A does not correlate with its utility to the project and this pull is intended to put Class A to bed so we can move onto other more useful work.
How?All of the following rules would be removed from the spec:
The following conditions must also be satisfied for the transaction to be considered decode-able:
* The reference address sequence number must be the data address sequence number + 1
* Ideally, all outputs should be the same (except the change). In fringe cases where the change output value is equal to the other output values the change address can be identified by sequence number, which must not equal or be +/-1 of the sequence number for either the reference address or the data address
* A last resort 'peek and decode' method may be used to identify the data packet in the event of ambiguity following the above rules. This involves decoding each packet and looking for the correct bytes for a simple send (the majority of bytes in a Class A simple send do not change). These byte checks are defined as:
+ Bytes two to eight must equal 00
+ Byte nine must equal 01 or 02
* Should there still be packet ambiguity or 'peek and decode' reveals more than one packet (simple sends are always one packet) the transaction is considered invalid.
And replaced with:
* Has exactly two non-exodus outputs (one of which must be the data address) with a value equal to the Exodus output and/or has exactly one output with a sequence number +1 of the data address for reference output identification
EDIT: Qualified that one of the two same valued outputs must be the data address & that the two same valued outputs are in addition to the Exodus output.
A transaction will either satisfy this single rule or not, helping to remove some of the discussion/ambiguity around whether certain transactions that are decodable (eg via P&D) but don't meet one or some of the original rules should be validated. The rule has been written to cater for all existing transactions and new code based on this simplified logic has undergone a fair degree of testing.
This is not a change to the underlying structure of Class A and more a consolidation of wording/logic such that we have a clear interpretation of what is and what isn't a valid Class A transaction. This also does not enforce a method for testing against the rule - the rule is intended to be clear enough that no specific approach needs to be defined.
I have already rewritten the Masterchest library to utilize this logic instead for the purposes of testing (
source). This has resulted in a big reduction & simplification in Class A parsing code. I've run the modified library against a full blockscan in the engine, and can confirm that
all transactions validated by the original complex rule implementation have been also been validated by the simplified model. Additionally transactions that were under active discussion between Tachikoma & I which were
decodable via P&D but technically invalid per spec when considered against the original ruleset are now validated via the new single rule.
While trying to break this simplification I was able to identify an edge case of an incorrectly structured transaction that would cause ambiguity through this rule. Essentially same output values provide one reference address while dataseqnum+1 provides a different reference address. This edge case exists just the same in the original ruleset and has never been used in a transaction (that I could locate, happy to be corrected) - an example of such an incorrectly built transaction is as follows:
SEQNUM ADDRESS OUTPUT VALUE
101 ChangeAddress 0.05 BTC
100 DataAddress 0.00006 BTC
72 ReferenceAddress 0.00006 BTC
148 ExodusAddress 0.00006 BTC
As you can see the seqnum for the reference address should be 101 following dataseqnum+1, but that's actually the seqnum of what would be the change address following same output values. For this specific case (where same outputs and dataseqnum+1 provide different ref addresses) in order to allow it we would need to set an order of precedence on whether same outputs or dataseqnum+1 is authoritative first and once we start down the road of which rule is more important than another we head back down into complexity territory. As I say this is not a 'new' edge case specific to the simplification, but out of all the edge cases I looked at I think it is the one case that this simplification does not solve. This is the very definition of ambiguity on the reference address so if it ever does appear on the network should be considered invalid IMO.
I have added a line in the pull to be explicit about this if we find an edge case is broadcast that results in ambiguity - "NOTE: Should a transaction result in an edge case that appears to follow the rules above but fails to exclusively and without ambiguity identify the sending, reference and data addresses the transaction is considered invalid."
TL:DR; Since this simplification caters not only for properly formatted transactions but also for every single edge case that has ever been broadcast for a Mastercoin transaction with just one single sentence - my own view is we should merge & put Class A to bed now and focus our efforts elsewhere.To help with considering this pull, I have hooked up dev to prod to allow the consensus check to run against dev. You can see the results of the simplified logic here (
https://masterchest.info/consensus_masterchestinfodev.aspx). Spoiler alert...
Shame about Exodus, I thought we had that locked up during the hackathon? Other than that though, I recall offering a round of beers when we hit consensus - given our locations though you're all going to just have to buy yourself a beer and bill me for it
EDIT: Hmmm, how bizarre. One of the changes we made during the hackathon (seconds in a year from 31557600 to 31556926) is MIA. Put it back in, we're back synced on Exodus
though Bitoy's is still a bit off. I'd like to hear about update frequency from Grazcoin & Bitoy too if you can guys as I've noticed consensus seems to slip in and out depending on how recently the implementations update. Consensus runs every 5 mins FYI.
Pull request is here
https://github.com/mastercoin-MSC/spec/pull/36, please -1/+1 and feel free to comment/ask any questions.
Thanks
Zathras
P.S. Tachikoma, quick FYI took some hunting to isolate but squished the bug that was causing a second row for an address (1LjT88X7Zu8BdbqJw8vfRa83NJuzYL9kqm) in the balances table.