-
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
Make ConsensusContext public (master-2.x) #1892
Conversation
neo express must duplicate ConsensusContext implementation for gas preload. If ConsensusContext was public, neo-express could simply use it
What is "gas preload"? |
In Neo Express for Neo 2, when you create privatenet you can specify how much gas you want to create. Neo-express then creates enough empty blocks to generate that much gas + a transfer and claim transaction. This automatically creates the requested gas in the genesis account, ready to go for dev and test scenarios.
I had to replicate the logic in neo-express because the ConsensusContext type is internal. But I don't want to maintain duplicate code nor re-implement it in Neo Express for Neo 3. It would be much more straightforward for Neo Express if ConensusContext was a public type. |
I will be faster if you create the blocks without consensus, only signed by consensus nodes, isn't it? |
Speed isn't really an issue here. A developer can create 1000s of GAS in a few seconds. My goal is correctness - the blocks generated by preload need to match the ones generated by consensus, so using the ConsensusContext seems like the best approach. |
In Neo3, it will generate 30,000,000 GAS during initialization, I think this should be enough for testing. neo/src/neo/SmartContract/Native/Tokens/GasToken.cs Lines 19 to 23 in 9322675
|
And there is a constructor in neo/neo/Consensus/ConsensusService.cs Lines 48 to 51 in a423b18
|
Agreed, preload gas is not an option for neo express for neo 3. We do have other scenarios for creating offline transactions related to configuring a blockchain for test/debug scenarios that need the same behavior.
I'm not sure how that's relevant. I'm using ConsensusContext directly. I'm not creating an instance of ConsensusService. |
Which method do you use? |
Yes. The full code I would use is: // relay any transations via neoSystem.Blockchain.Ask
var ctx = new ConsensusContext(nodeWallet, Blockchain.Singleton.Store);
ctx.Reset(0);
ctx.MakePrepareRequest();
ctx.MakeCommit();
var block = ctx.CreateBlock();
var blockRelay = neoSystem.Blockchain.Ask<RelayResult>(block).Result; |
@shargon What do you think? Is it worth making |
I think that It's harmless |
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.
For neo3 we have better options
Yes, as I said here
I think that it's easy to create a chain without consensus, you only need to do a for, increase the height, change the validator, change the prevHash, change NextConsensus, and sign it with the consensus wallet. The solution could be done in neo2 too but we have a mint transction, it could be "harder". But now that we have states, maybe it's easier like you said, I am not sure, so it's ok for me this change. |
This seems harder than the code from my earlier comment |
neo express must duplicate ConsensusContext implementation for gas preload. If ConsensusContext was public, neo-express could simply use it