Skip to content

Conversation

@shargon
Copy link
Member

@shargon shargon commented Oct 1, 2025

Description

Please @neo-project/core review this PR, as we agree in Centre Point it's important for the community.
Was decided in Centre Point to have two decimals in ExecutionFactor this PR tries to address it

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Test A
  • Test B

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@shargon shargon marked this pull request as ready for review October 2, 2025 07:50
Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner now. But I'd also adjust BurnGas() since it's documented to use datoshis and for its users (if there are any) that should be sufficient.

@shargon shargon changed the title Exec Factor with two decimals Exec Factor with decimals Oct 3, 2025
@shargon
Copy link
Member Author

shargon commented Oct 3, 2025

I think it could be more clear if we multiply inside AddFee method, otherwise, AddFee it's in picoDatoshi and BurnFee it's in datoshi, what do you think @roman-khimov @AnnaShaleva?

@roman-khimov
Copy link
Contributor

AddFee is an internal thing, BurnFee is only used by contracts. To me it's not a problem.

@shargon shargon mentioned this pull request Oct 3, 2025
15 tasks
@shargon
Copy link
Member Author

shargon commented Oct 6, 2025

Please @neo-project/core review this PR, as we agree in Centre Point it's important for the community.

Important changes areas:

  • AddFee should use picoDatoshi always

@shargon shargon added the Critical Issues (bugs) that need to be fixed ASAP label Oct 6, 2025
@shargon shargon added Help Wanted We suggest a careful read at https://docs.neo.org/. However, fell free to further discuss the topic. and removed Work in Progress labels Oct 6, 2025
@roman-khimov
Copy link
Contributor

AddFee should use picoDatoshi always

picoGAS! It's 8+4, so 1^-12. picoDatoshi would be 1^-20.

@shargon
Copy link
Member Author

shargon commented Oct 28, 2025

Please @neo-project/core review this PR

@vncoelho
Copy link
Member

Without the current state of dev I can not completely test.
But from my previous test it is fine to me.

Wi1l-B0t
Wi1l-B0t previously approved these changes Oct 28, 2025
ajara87
ajara87 previously approved these changes Oct 28, 2025
@superboyiii
Copy link
Member

superboyiii commented Oct 29, 2025

Don't we need a Hardfork for this? It changes fee calculation logic.
image
ContractManagement storage will be incompatible at the beginning...

@shargon
Copy link
Member Author

shargon commented Oct 29, 2025

Don't we need a Hardfork for this? It changes fee calculation logic. image ContractManagement storage will be incompatible at the beginning...

We have the fork logic, at what height did you set the HF_Faun fork?

@superboyiii
Copy link
Member

We have the fork logic, at what height did you set the HF_Faun fork?

Block 0.
I surely set fork height at a higher one.

    "Hardforks": {
      "HF_Aspidochelone": 1730000,
      "HF_Basilisk": 4120000,
      "HF_Cockatrice": 5450000,
      "HF_Domovoi": 5570000,
      "HF_Echidna": 7300000,
      "HF_Faun": 8300000,
      "HF_Gorgon": 8300000
    },

@superboyiii
Copy link
Member

superboyiii commented Oct 29, 2025

In genesis block
v3.8.2:

        {
            "id": -1,
            "state": "Added",
            "key": "/////wh7xoHAofcdVDRXtou6jV\u002Bf3U5ezA==",
            "value": "QAUhAfkhACgUe8aBwKH3HVQ0V7aLuo1fn91OXswom05FRjNuZW8tY29yZS12My4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABNEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0BIETlBQQgoDlBvbGljeUNvbnRyYWN0QABIAEAAQQJAC0EFKAxibG9ja0FjY291bnRAAUECKAdhY2NvdW50IQEUIQEQIQAgAEEFKA9nZXRBdHRyaWJ1dGVGZWVAAUECKA1hdHRyaWJ1dGVUeXBlIQERIQERIQEHIAFBBSgQZ2V0RXhlY0ZlZUZhY3RvckAAIQERIQEOIAFBBSgNZ2V0RmVlUGVyQnl0ZUAAIQERIQEVIAFBBSgPZ2V0U3RvcmFnZVByaWNlQAAhAREhARwgAUEFKAlpc0Jsb2NrZWRAAUECKAdhY2NvdW50IQEUIQEQIQEjIAFBBSgPc2V0QXR0cmlidXRlRmVlQAJBAigNYXR0cmlidXRlVHlwZSEBEUECKAV2YWx1ZSEBESEC/wAhASogAEEFKBBzZXRFeGVjRmVlRmFjdG9yQAFBAigFdmFsdWUhAREhAv8AIQExIABBBSgNc2V0RmVlUGVyQnl0ZUABQQIoBXZhbHVlIQERIQL/ACEBOCAAQQUoD3NldFN0b3JhZ2VQcmljZUABQQIoBXZhbHVlIQERIQL/ACEBPyAAQQUoDnVuYmxvY2tBY2NvdW50QAFBAigHYWNjb3VudCEBFCEBECEBRiAAQABAAUECAABAACgEbnVsbA=="
        }

This one:

        {
            "id": -1,
            "state": "Added",
            "key": "/////wh7xoHAofcdVDRXtou6jV\u002Bf3U5ezA==",
            "value": "QAUhAfkhACgUe8aBwKH3HVQ0V7aLuo1fn91OXswook5FRjNuZW8tY29yZS12My4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABUEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAf6N\u002B1UEIKA5Qb2xpY3lDb250cmFjdEAASABAAEECQAxBBSgMYmxvY2tBY2NvdW50QAFBAigHYWNjb3VudCEBFCEBECEAIABBBSgPZ2V0QXR0cmlidXRlRmVlQAFBAigNYXR0cmlidXRlVHlwZSEBESEBESEBByABQQUoEGdldEV4ZWNGZWVGYWN0b3JAACEBESEBDiABQQUoFGdldEV4ZWNQaWNvRmVlRmFjdG9yQAAhAREhARUgAUEFKA1nZXRGZWVQZXJCeXRlQAAhAREhARwgAUEFKA9nZXRTdG9yYWdlUHJpY2VAACEBESEBIyABQQUoCWlzQmxvY2tlZEABQQIoB2FjY291bnQhARQhARAhASogAUEFKA9zZXRBdHRyaWJ1dGVGZWVAAkECKA1hdHRyaWJ1dGVUeXBlIQERQQIoBXZhbHVlIQERIQL/ACEBMSAAQQUoEHNldEV4ZWNGZWVGYWN0b3JAAUECKAV2YWx1ZSEBESEC/wAhATggAEEFKA1zZXRGZWVQZXJCeXRlQAFBAigFdmFsdWUhAREhAv8AIQE/IABBBSgPc2V0U3RvcmFnZVByaWNlQAFBAigFdmFsdWUhAREhAv8AIQFGIABBBSgOdW5ibG9ja0FjY291bnRAAUECKAdhY2NvdW50IQEUIQEQIQFNIABAAEABQQIAAEAAKARudWxs"
        }

/////wh7xoHAofcdVDRXtou6jV\u002Bf3U5ezA== base64 to Hex: ffffffff087bc681c0a1f71d543457b68bba8d5f9fdd4e5ecc
7b68bba8d5f9fdd4e5ecc is apparently Policy contract. So policy contract registered in genesis contractmanagement contract has data incompatible.

@Wi1l-B0t
Copy link
Contributor

Wi1l-B0t commented Oct 29, 2025

The gasconsumed in Application Log before HF_Faun is Datoshi.

The gasconsumed in Application Log after HF_Faun is Datoshi or PicoGAS?

@shargon shargon dismissed stale reviews from ajara87 and Wi1l-B0t via 9fa5998 October 29, 2025 11:58
@shargon
Copy link
Member Author

shargon commented Oct 29, 2025

Thanks @superboyiii ! please check it again, it should be fixed

@shargon
Copy link
Member Author

shargon commented Oct 29, 2025

he gasconsumed in Application Log is Datoshi or PicoGAS?

should not be changed outside the ApplicationEngine

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check it with NeoGo implementation.

ajara87
ajara87 previously approved these changes Oct 29, 2025
@superboyiii
Copy link
Member

I tried some blocks, no incompatible data found. Let me make a full sync to check all.

Comment on lines -218 to +242
ExecFeeFactor = NativeContract.Policy.GetExecFeeFactor(snapshotCache);
if (settings == null || !settings.IsHardforkEnabled(Hardfork.HF_Faun, persistingBlock?.Index ?? NativeContract.Ledger.CurrentIndex(snapshotCache)))
{
// The values doesn't have the decimals stored
_execFeeFactor = NativeContract.Policy.GetExecFeeFactor(this) * FeeFactor;
}
else
{
// The values have the decimals stored
_execFeeFactor = NativeContract.Policy.GetExecPicoFeeFactor(this);
}

Copy link
Member

@AnnaShaleva AnnaShaleva Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shargon it seems that this logic doesn't work correctly in the following situation (I discovered it while porting this logic to NeoGo and it looks like it works the same way in C#, but I need you to recheck that):

  1. Consider this ApplicationEngine constructor is called before processing OnPersist trigger of Faun's block.
  2. settings.IsHardforkEnabled(Hardfork.HF_Faun, ...) at line 232 returns true, because Faun is already enabled at persisting block.
  3. However, Policy's OnPersist wasn't yet executed, hence there's old 1 ExecFeeFactor value stored in the Policy's storage.

So we end up in a situation when the else branch is executed at line 240, as a result _execFeeFactor will be set to 1 instead of 10000.

So I think we need a special condition for OnPersist trigger of Faun block here. Please, check it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a different key, if is not stored, make another query

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need a different key, the old one works fine after migration, we just need to properly handle the situation when migration isn't done yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnnaShaleva Could you propose the required changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@superboyiii
Copy link
Member

Storage is compatible now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical Issues (bugs) that need to be fixed ASAP Need Testing Waiting for Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants