Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Codify implicit sorting of oracle submissions before txn close & fix … #678

Merged
merged 1 commit into from
Nov 17, 2020

Conversation

Vagabond
Copy link
Contributor

…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.

…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
Copy link

codecov bot commented Nov 17, 2020

Codecov Report

Merging #678 (499a932) into master (4fcd506) will decrease coverage by 0.15%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/transactions/blockchain_txn.erl 84.06% <0.00%> (-0.16%) ⬇️
src/handlers/blockchain_sync_handler.erl 94.64% <100.00%> (+1.91%) ⬆️
src/blockchain_gateway_cache.erl 54.54% <0.00%> (-9.85%) ⬇️
src/handlers/blockchain_gossip_handler.erl 68.18% <0.00%> (-9.10%) ⬇️
src/blockchain_worker.erl 38.72% <0.00%> (-0.54%) ⬇️
src/blockchain.erl 63.33% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fcd506...499a932. Read the comment docs.

Copy link
Contributor

@jadeallenx jadeallenx left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@vihu
Copy link
Member

vihu commented Nov 17, 2020

For reference, I was able to successfuly resync with revalidation from block 585361 and pass the supposed doom block 587899

@evanmcc evanmcc merged commit 58711fb into master Nov 17, 2020
@evanmcc evanmcc deleted the adt/fix-txn-order branch November 17, 2020 22:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants