-
Notifications
You must be signed in to change notification settings - Fork 86
Codify implicit sorting of oracle submissions before txn close & fix … #678
Conversation
…issue The implicit txn ordering behaviour if a transaction did not have a defined sort order can cause instability in the sort order when a new transaction is added, because the undefined sort order was the same as the last sort order. This could lead to the transaction without a defined sort order sorting before the transaction with a defined sort order (because of the other sort dimensions like nonces, etc).This means that adding another transaction to the end of the sort order list would cause the transaction with the implicit sort order to definitely sort after the transaction it may have sorted before earlier, invalidating the block. This change establishes a definitive sort order for the oracle price report txn to mirror the implicit sort order before the addition of the hotspot transfer function. Additionally it makes the undefined sort order one past the maximum to prevent this bug recurring and it add a log message to the sync_handler to make this failure clearer. This *may* expose other implicit sort ordering bugs, so a thorough resync (or at least ordering check of txns in blocks) is recommended.
Codecov Report
@@ Coverage Diff @@
## master #678 +/- ##
==========================================
- Coverage 68.40% 68.25% -0.16%
==========================================
Files 94 94
Lines 12311 12312 +1
==========================================
- Hits 8421 8403 -18
- Misses 3890 3909 +19
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, thank you
@@ -636,7 +637,7 @@ type_order(Txn) -> | |||
Type = type(Txn), | |||
case lists:keyfind(Type, 1, ?ORDER) of | |||
{Type, Index} -> Index; | |||
false -> erlang:length(?ORDER) | |||
false -> erlang:length(?ORDER) + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be safer to just error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd have to audit that all other transactions have a defined order and make sure we establish that ordering, but yes.
For reference, I was able to successfuly resync with revalidation from block |
…issue
The implicit txn ordering behaviour if a transaction did not have a
defined sort order can cause instability in the sort order when a new
transaction is added, because the undefined sort order was the same as
the last sort order. This could lead to the transaction without a
defined sort order sorting before the transaction with a defined sort
order (because of the other sort dimensions like nonces, etc).This means
that adding another transaction to the end of the sort order list would
cause the transaction with the implicit sort order to definitely sort
after the transaction it may have sorted before earlier, invalidating
the block.
This change establishes a definitive sort order for the oracle price
report txn to mirror the implicit sort order before the addition of the
hotspot transfer function. Additionally it makes the undefined sort
order one past the maximum to prevent this bug recurring and it add a
log message to the sync_handler to make this failure clearer.
This may expose other implicit sort ordering bugs, so a thorough
resync (or at least ordering check of txns in blocks) is recommended.