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

En 6315/dns at genesis #1981

Merged
merged 13 commits into from Jun 23, 2020
Merged

En 6315/dns at genesis #1981

merged 13 commits into from Jun 23, 2020

Conversation

sasurobert
Copy link
Contributor

deployment and computation of sc addresses for the DNS contracts at genesis time

@andreibancioiu andreibancioiu self-requested a review June 19, 2020 14:35
cmd/node/config/genesisSmartContracts.json Outdated Show resolved Hide resolved
genesis/data/initialSmartContract.go Outdated Show resolved Hide resolved
genesis/data/initialSmartContract.go Outdated Show resolved Hide resolved
genesis/interface.go Show resolved Hide resolved
InitialSmartContracts() []InitialSmartContractHandler
IsInterfaceNil() bool
}

// TxExecutionProcessor represents a transaction builder and executor containing also related helper functions
type TxExecutionProcessor interface {
ExecuteTransaction(nonce uint64, sndAddr []byte, rcvAddress []byte, value *big.Int, data []byte) error
AccountExists(address []byte) bool
AccountExists(address []byte) (state.UserAccountHandler, bool)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to GetAccount() perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would leave like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

GetAcount is more appropriate. it gets the account now

genesis/process/intermediate/deployLibrarySC.go Outdated Show resolved Hide resolved
core/constants.go Outdated Show resolved Hide resolved
return err
}

account, ok := dp.AccountExists(scAddress)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure why not checking this before ExecuteTransaction instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste verification remained.

Copy link
Contributor

Choose a reason for hiding this comment

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

no need for this now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is checked before. check is needed here as well as you do not want the node to panic. although that means super big coding problem.


// IsInterfaceNil returns if underlying object is true
func (dp *deployLibrarySC) IsInterfaceNil() bool {
return dp == nil || dp.TxExecutionProcessor == nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

TxExecutionProcessor shouldn't be nil if we have a non-nil (correctly constructed) dp. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rigth

Copy link
Contributor

Choose a reason for hiding this comment

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

@andreibancioiu we always need to check this since it is an exported element by construction.

genesis/interface.go Outdated Show resolved Hide resolved
InitialSmartContracts() []InitialSmartContractHandler
IsInterfaceNil() bool
}

// TxExecutionProcessor represents a transaction builder and executor containing also related helper functions
type TxExecutionProcessor interface {
ExecuteTransaction(nonce uint64, sndAddr []byte, rcvAddress []byte, value *big.Int, data []byte) error
AccountExists(address []byte) bool
AccountExists(address []byte) (state.UserAccountHandler, bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

GetAcount is more appropriate. it gets the account now

genesis/process/genesisBlockCreator.go Outdated Show resolved Hide resolved
@@ -144,14 +154,40 @@ func (scp *smartContractParser) InitialSmartContractsSplitOnOwnersShards(

var smartContracts = make(map[uint32][]genesis.InitialSmartContractHandler)
for _, isc := range scp.initialSmartContracts {
shardID := shardCoordinator.ComputeId(isc.OwnerBytes())
if isc.Type == genesis.DNSType {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we talk about this but now the parser has an exception: it knows we have a special contract that is of type DNS. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. it does not need to split in that case. it also has type delegation.

genesis/process/genesisBlockCreator.go Outdated Show resolved Hide resolved
func GenerateInitialPublicKeys(
baseAddress []byte,
shardCoordinator sharding.Coordinator,
allShards bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ugly. Why not having 2 separate functions for each usecase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 functions doing the same thing, calling a basic stuff. receiving a function pointer if ok / not ok ?

Copy link
Contributor

Choose a reason for hiding this comment

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

almost the same thing, bool parameters that alter the execution of a function is not a good pattern. Indeed, code duplication should be avoided

return err
}

account, ok := dp.AccountExists(scAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for this now


// IsInterfaceNil returns if underlying object is true
func (dp *deployLibrarySC) IsInterfaceNil() bool {
return dp == nil || dp.TxExecutionProcessor == nil
Copy link
Contributor

Choose a reason for hiding this comment

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

@andreibancioiu we always need to check this since it is an exported element by construction.

genesis/process/shardGenesisBlockCreator.go Outdated Show resolved Hide resolved
genesis/process/shardGenesisBlockCreator.go Show resolved Hide resolved
andreibancioiu
andreibancioiu previously approved these changes Jun 23, 2020
genesis/process/genesisBlockCreator_test.go Outdated Show resolved Hide resolved
return err
}

isForCurrentShard := func([]byte) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps add an inline comment to explain this, for future reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comment

Copy link
Collaborator

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

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

Fix merge conflicts etc.

# Conflicts:
#	core/constants.go
#	genesis/process/intermediate/standardDelegationProcessor.go
iulianpascalau
iulianpascalau previously approved these changes Jun 23, 2020
@@ -95,8 +93,12 @@ func (dp *deployLibrarySC) Deploy(sc genesis.InitialSmartContractHandler) error
return err
}

isForCurrentShard := func(address []byte) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

this could have been a non-anonymous function, also, might have signaled this as a handler: isForCurrentShardFn

@sasurobert sasurobert merged commit 05fb0eb into feat/new-features Jun 23, 2020
@sasurobert sasurobert deleted the EN-6315/DNS-at-genesis branch June 23, 2020 15:42
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.

None yet

3 participants