This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Fix sys_fee calculation in block persist #905
Merged
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.
What current issue(s) does this address, or what feature is it adding?
Fix #902
#902 is the unforeseen result of fixing (among others) a wrong
net_feecalculation reported in #749.It all started when I there changed the
SystemFeeimplementation of theInvocationTransactionfromto
to be inline with neocore's (ref)
This together with another change fixed #749. What I unfortunately did not foresee is that it would cause the issue described in #902, which is caused by this line:
neo-python/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py
Line 666 in fe90f62
According to the neocore implementation the equivalent of our
block.TotalFees().valuewould be (ref)The crux of the problem is the cast from
Fixed8tolong, which is implemented as (ref)Our version did not apply this cast (essentially divide by
Fixed8.FD()) on theTotalFees. I believe this is just an error that originated in the faultyInvocationTransaction.SystemFeeimplementation and that propagated throughout the code base.How did you solve this problem?
First off, I applied the same division to the
TotalFeesend result.Second, since we now get a float instead of an int, I changed the logic for creating a 8 bytes bytearray from an int, to use
struct.unpack("<d", float)(which creates an 8 bytes double in little endian format). This appears to be inline with storing a float (8 bytes in C#).Third, I took the time to cross referenced the implementation of all other transactions on
system feeandnetwork feewith the C# code and made 2 changes there.Finally, I updated all tests + fixtures (because the db storage is different)
How did you make sure your solution works?
make test+ compare with neo-cliAre there any special changes in the code that we should be aware of?
yes, we change the storage format of the system fee in the db. Previously
now
This will require a resync of the chain 😞 , but should at least fix all known
net_feeandsys_feediscrepancies.Please check the following, if applicable:
make lint?make test?CHANGELOG.rst? (if not, please do)