-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Oracle PostPersist #2074
Merged
Merged
Fix Oracle PostPersist #2074
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1805453
Fix Oracle PostPersist
shargon 74c7a1a
Add other check
shargon 1da5b7f
Prevent two same responses in the same block
shargon db3eb1e
Remove check
shargon 8ce353d
Merge branch 'master' into fix-oracle
shargon 5715b86
Revert one condition
shargon b5082b8
Merge branch 'master' into fix-oracle
shargon 4233867
Rename
shargon 7eb4cb2
Merge branch 'master' into fix-oracle
shargon a2afcbf
Merge branch 'master' into fix-oracle
vncoelho bcb6585
Prevent adding tx if oracle it's duplicated
shargon 9a2e1d1
Optimize
shargon cbad584
Merge branch 'master' into fix-oracle
shargon 3fa4f6f
Merge branch 'master' into fix-oracle
shargon 9567464
Revert
shargon 4cbd2eb
Merge remote-tracking branch 'origin/fix-oracle' into fix-oracle
shargon 36d2285
Merge branch 'master' into fix-oracle
shargon 979639b
Fix duplicate
shargon 1b1d020
Merge branch 'master' into fix-oracle
shargon 034c49b
Remove unnecessary parentheses.
erikzhang 524d2c1
Merge branch 'master' into fix-oracle
shargon 14c5c04
Simplify AddTransaction
erikzhang 00804bd
Simplify RemoveTransaction
erikzhang f71992d
Merge branch 'master' into fix-oracle
shargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,16 @@ public class TransactionVerificationContext | |
/// </summary> | ||
private readonly Dictionary<UInt160, BigInteger> senderFee = new Dictionary<UInt160, BigInteger>(); | ||
|
||
/// <summary> | ||
/// Store oracle responses | ||
/// </summary> | ||
private readonly Dictionary<ulong, UInt256> oracleResponses = new Dictionary<ulong, UInt256>(); | ||
|
||
public void AddTransaction(Transaction tx) | ||
{ | ||
var oracle = tx.GetAttribute<OracleResponse>(); | ||
if (oracle != null) oracleResponses.Add(oracle.Id, tx.Hash); | ||
|
||
if (senderFee.TryGetValue(tx.Sender, out var value)) | ||
senderFee[tx.Sender] = value + tx.SystemFee + tx.NetworkFee; | ||
else | ||
|
@@ -25,13 +33,23 @@ public bool CheckTransaction(Transaction tx, StoreView snapshot) | |
{ | ||
BigInteger balance = NativeContract.GAS.BalanceOf(snapshot, tx.Sender); | ||
senderFee.TryGetValue(tx.Sender, out var totalSenderFeeFromPool); | ||
|
||
BigInteger fee = tx.SystemFee + tx.NetworkFee + totalSenderFeeFromPool; | ||
return balance >= fee; | ||
if (balance < fee) return false; | ||
|
||
var oracle = tx.GetAttribute<OracleResponse>(); | ||
if (oracle != null && oracleResponses.ContainsKey(oracle.Id)) | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, this can be replaced with generic "Conflicts" mechanism (#1991) that would also allow for proper transaction to have higher priority over fallback. |
||
|
||
return true; | ||
} | ||
|
||
public void RemoveTransaction(Transaction tx) | ||
{ | ||
if ((senderFee[tx.Sender] -= tx.SystemFee + tx.NetworkFee) == 0) senderFee.Remove(tx.Sender); | ||
|
||
var oracle = tx.GetAttribute<OracleResponse>(); | ||
if (oracle != null) oracleResponses.Remove(oracle.Id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why don't remove
CheckTransaction
and Change Add tobool TryAdd
(thread-safe)?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.
Because
CheckTransaction
is called inTransaction.Verify()
.