Skip to content
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

core: init native interops in the genesis block #894

Merged
merged 13 commits into from
Apr 27, 2020

Conversation

AnnaShaleva
Copy link
Member

closes #836

@AnnaShaleva AnnaShaleva self-assigned this Apr 20, 2020
@AnnaShaleva AnnaShaleva force-pushed the neo3/genesis/init_native_interops branch 2 times, most recently from 1455f62 to 07b9cd8 Compare April 21, 2020 10:00
@roman-khimov roman-khimov force-pushed the neo3/genesis/init_native_interops branch from 07b9cd8 to 0642931 Compare April 23, 2020 20:18
@roman-khimov roman-khimov marked this pull request as ready for review April 23, 2020 20:21
@roman-khimov roman-khimov requested a review from fyrchik April 23, 2020 20:21
@roman-khimov
Copy link
Member

@fyrchik: please take a look, I'll rebase it afterwards.

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #894 into master will increase coverage by 0.82%.
The diff coverage is 59.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #894      +/-   ##
==========================================
+ Coverage   63.32%   64.15%   +0.82%     
==========================================
  Files         195      192       -3     
  Lines       16451    16198     -253     
==========================================
- Hits        10418    10392      -26     
+ Misses       5495     5275     -220     
+ Partials      538      531       -7     
Impacted Files Coverage Δ
pkg/config/protocol_config.go 70.00% <ø> (+6.36%) ⬆️
pkg/core/interop_neo.go 60.08% <ø> (-0.08%) ⬇️
pkg/core/interops.go 100.00% <ø> (ø)
pkg/core/state/account.go 95.52% <ø> (-0.43%) ⬇️
pkg/core/storage/store.go 42.30% <ø> (ø)
pkg/core/transaction/transaction.go 82.72% <ø> (+1.56%) ⬆️
pkg/core/transaction/type.go 80.48% <ø> (-3.19%) ⬇️
pkg/rpc/response/result/account_state.go 87.50% <ø> (-0.74%) ⬇️
pkg/core/native/interop.go 37.50% <25.00%> (+37.50%) ⬆️
pkg/core/native/native_neo.go 36.33% <37.95%> (+7.45%) ⬆️
... and 16 more

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 aa8d4d2...e6f5cff. Read the comment docs.

@roman-khimov roman-khimov changed the title core: init native interops into the genesis block core: init native interops in the genesis block Apr 23, 2020
@roman-khimov roman-khimov force-pushed the neo3/genesis/init_native_interops branch from 0642931 to 4107f06 Compare April 24, 2020 09:01
@roman-khimov
Copy link
Member

Updated and improved, it's important to merge this tomorrow, so have a look at it.

}
r := io.NewBinReaderFromBuf(b)
balance.DecodeBinary(r)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you have an empty line here but not in Bytes() ?

if err != nil {
return err
}
if err := n.ModifyAccountVotes(oldAcc, ic.DAO, (&big.Int{}).Not(&acc.Balance)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not Not, but Neg.
We also use new(big.Int) in every other place.

Copy link
Member

Choose a reason for hiding this comment

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

It is not Not, but Neg.

Yep, it was fixed in some subsequent commit, maybe I need to shuffle these changes a little.

var (
pKeys []*keys.PublicKey
err error
)
if len(txx) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

When invoked with non-zero sized slice, it is used for calculating NextConsensus field.
DBFT needs to be changed, but for now we can return GetNextBlockValidators when invoked with non-zero slice.
https://github.com/neo-project/neo/blob/master/src/neo/Consensus/ConsensusContext.cs#L349

Copy link
Member

Choose a reason for hiding this comment

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

I don't think DBFT needs any change wrt this. We already do return next block validators from GetValidators.

@@ -446,7 +450,7 @@ func (n *NEO) getNextBlockValidators(ic *interop.Context, _ []vm.StackItem) vm.S
func (n *NEO) GetNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
si := d.GetStorageItem(n.Hash, nextValidatorsKey)
if si == nil {
return bc.GetStandByValidators()
Copy link
Contributor

Choose a reason for hiding this comment

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

If validatorsCount is not yet initialized, GetValidatorsInternal can fail, no?
https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/Native/Tokens/NeoToken.cs#L264

Copy link
Member

Choose a reason for hiding this comment

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

It's initialized now in Initialize at block 0, so I don't think we have any problem.

AnnaShaleva and others added 11 commits April 27, 2020 12:30
The notion of NativeContractState shouldn't ever existed, native contract is a
contract and its state is saved as regular contract state which is critical
because we'll have MPT calculations over this state soon.

Initial minting should be done in Neo.Native.Deploy because it generates
notification that should have proper transaction context.

RegisterNative() shouldn't exist as a public method, native contracts are only
registered at block 0 and they can do it internally, no outside user should be
able to mess with it.

Move some structures from `native` package to `interop` also to avoid circular
references as interop.Context has to have a list of native contracts (exposing
them via Blockchainer is again too dangerous, it's too powerful tool).
It fails at the moment and it doesn't make sense at conceptual level.
nil is not a good StackItem, we have proper VM-level Null for this.
As it should be done (although current serialization format is not quite
right).
This technically breaks voting with UTXO-based NEO (processTXWithValidators*),
but we're moving towards the new system.
@roman-khimov roman-khimov force-pushed the neo3/genesis/init_native_interops branch from 9016cb4 to 5c9e3e5 Compare April 27, 2020 09:31
@roman-khimov roman-khimov requested a review from fyrchik April 27, 2020 09:49
It has all the methods required now, so you can register, vote and get
voting results. Fixes #865.
They're completely replaced now by the NEO native contract voting system.
@roman-khimov roman-khimov force-pushed the neo3/genesis/init_native_interops branch from 5c9e3e5 to e6f5cff Compare April 27, 2020 13:07
@roman-khimov
Copy link
Member

Updated to mention #865 as it technically fixes it now.

@roman-khimov roman-khimov merged commit de91418 into master Apr 27, 2020
@roman-khimov roman-khimov deleted the neo3/genesis/init_native_interops branch April 27, 2020 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add native interops initialization into the genesis block
3 participants