Skip to content

Commit

Permalink
v0.3.0-pre (iov-one#171)
Browse files Browse the repository at this point in the history
* Add v0.3.0-pre to travis builds

* change: move domain & account checks to controllers (iov-one#123)

* change: move domain checks to controllers

* Shorten controller naming

* Improve code organisation

* change: move account handlers validity check to controllers

* add: account cert existence + docs

* add: cert not exist tests

* add: account expiration tests

* add: account owned by tests

* add: valid name tests

* add: require account tests

* chore: docs

* Move subtest suite to different module

* Add domain test

* Move testing to suite

* Revert "Move testing to suite"

This reverts commit 3b483ad.

* Move suite to x/domain/testing

* Make test key generation static

* add: domain controller tests

* Apply suggestions from code review

* Move account controller to new module

* Move domain controller to new module

* Refactor controllers

* Add changelog

* Separate handler to account/domain_handler file

Co-authored-by: orkunkl <kulceorkun@gmail.com>
Co-authored-by: Orkun Külçe <orkunkl@users.noreply.github.com>

* Convert HasSuperUser to DomainType (iov-one#137)

* Change HasSuperUser to DomainType

* Apply review recommendation

* Rename close to closed

* Delete zero admin assignment; Edit super user references in tests (iov-one#139)

* Reconciliate configuration (iov-one#150)

* Recon configuration

* Update config tx use values on the live chain

* Resolve import cycle

* Fix errors

* Simplify configuration tx

* pre requisites for domain reconciliation (iov-one#153)

* fix: register domain fee collection

* add: max valid until default

* V0.3.0 recon (iov-one#161)

* change: move remaining domain authorization checks to handlers

* change: register domain creation, and create domain related tests

* update: delete domain one line auth

* change: move blockchain targets checks to controllers

* change: move transfer account checks to controllers

* add: domain ctrl caching and account ctrl tests

* add: add existence and transferability tests for accounts

* chore: go mod tidy

* chore: update CHANGELOG.md

* change: reconcile domain register

* change: reconcile domain transfer

* change: add iovnscli flag for domain transfer

* change: domain renew reconcile

* update: CHANGELOG.md

* Recon account handlers (iov-one#165)

* Recon: register account

* Apply review recommendations

* Add cli

* Recon: transfer account

* Add cli tx

* Recon: delete account targets

* Started replace account targets

* Improve replace account targets

* Add changelog

* Finalize recon replace account targets

* Fix changelog

* Recon: add account certs

* Recon: delete account certs

* Recon: replace metadata

* Start recon renew account

* account reconciliation finalization (iov-one#168)

* change: finalize account reconciliation

* update: CHANGELOG.md

* Last touches

* Fix error message

Co-authored-by: Frojdi Dymylja <33157909+fdymylja@users.noreply.github.com>

Co-authored-by: Frojdi Dymylja <33157909+fdymylja@users.noreply.github.com>
  • Loading branch information
orkunkl and fdymylja authored Jun 3, 2020
1 parent 29b881f commit bee2ecd
Show file tree
Hide file tree
Showing 38 changed files with 4,955 additions and 1,840 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ notifications:
branches:
only:
- master
- v0.3.0-pre
- /^v[0-9]+\.[0-9]+\.x$/
- /^v[0-9]+\.[0-9]+\.[0-9]+$/
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
# Changelog

## HEAD

- fix account controller max renew exceed
- add tests to account handlers in domain
- reconcile domain spec
- treat handler as orchestrator
- extend keeper functionality
- move all errors/authorization checks to handlers
- introduce domain and account controllers
- upgrade cosmos-sdk to v0.38.4
- iovnsd: fix fee colletor address

### Breaking changes

- change hasSuperUser to DomainType
- Open domain's admin is changed from zero address to normal address
- Recon configuration
- Recon register account handler
- Recon transfer account handler
- Recon delete account handler
- Recon replace account targets handler
- Recon add account certs handler
- Recon delete account cert handler
- Recon replace metadata handler

## v0.2.5

- iovnscli: fix has-superuser bool flag bug
Expand Down
3 changes: 0 additions & 3 deletions iovns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ package iovns

// Separator divides domain name from account name in an IOV starname
var Separator = []byte("*")

// EmptyAccountName defines the empty account identifier in an IOV domain
const EmptyAccountName = ""
23 changes: 23 additions & 0 deletions mock/addr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mock

import (
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"os"
)

func Addresses() (sdk.AccAddress, sdk.AccAddress) {
keyBase := keys.NewInMemory()
addr1, _, err := keyBase.CreateMnemonic("alice", keys.English, "", keys.Secp256k1)
if err != nil {
fmt.Println("unable to generate mock addresses " + err.Error())
os.Exit(1)
}
addr2, _, err := keyBase.CreateMnemonic("bob", keys.English, "", keys.Secp256k1)
if err != nil {
fmt.Println("unable to generate mock addresses " + err.Error())
os.Exit(1)
}
return addr1.GetAddress(), addr2.GetAddress()
}
8 changes: 3 additions & 5 deletions swagger-ui/statik/statik.go

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions swagger-ui/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2894,12 +2894,13 @@ components:
admin:
$ref: "#/components/schemas/Address"
description: Owner of the domain
calidUntil:
validUntil:
type: number
description: ValidUntil is a unix timestamp that defines for how long the domain is valid
hasSuperUser:
type: bool
description: If the domain is owned by a super user or not
description: Unix timestamp that defines for how long the domain is valid
domainType:
type: string
example: close
description: defines the type of the domain
accountRenew:
type: number
description: The duration of each created or renewed account under the domain
Expand Down
31 changes: 31 additions & 0 deletions tutils/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tutils

import (
"math/rand"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
)

func GeneratePrivKeyAddressPairs(n int) (ks []crypto.PrivKey, addrs []sdk.AccAddress) {
r := rand.New(rand.NewSource(12345)) // make the generation deterministic
ks = make([]crypto.PrivKey, n)
addrs = make([]sdk.AccAddress, n)
for i := 0; i < n; i++ {
secret := make([]byte, 32)
_, err := r.Read(secret)
if err != nil {
panic("Could not read randomness")
}
if r.Int63()%2 == 0 {
ks[i] = secp256k1.GenPrivKeySecp256k1(secret)
} else {
ks[i] = ed25519.GenPrivKeyFromSecret(secret)
}
addrs[i] = sdk.AccAddress(ks[i].PubKey().Address())
}

return
}
140 changes: 105 additions & 35 deletions x/configuration/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cli
import (
"bufio"
"fmt"
"regexp"
"time"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -36,78 +35,139 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
return configTxCmd
}

var defaultDuration, _ = time.ParseDuration("1h")

const defaultRegex = "^(.*?)?"
const defaultNumber = 1

func getCmdUpdateConfig(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "update-config",
Short: "update domain configuration",
Short: "update domain configuration, provide the values you want to override in current configuration",
RunE: func(cmd *cobra.Command, args []string) (err error) {
cliCtx := context.NewCLIContext().WithCodec(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc).WithBroadcastMode(flags.BroadcastBlock)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBuilder := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
rawCfg, _, err := cliCtx.QueryStore([]byte(types.ConfigKey), types.StoreKey)
if err != nil {
return err
}
var config types.Config
cdc.MustUnmarshalBinaryBare(rawCfg, &config)

// get flags
configurerStr, err := cmd.Flags().GetString("configurer")
if err != nil {
return
}
configurer, err := sdk.AccAddressFromBech32(configurerStr)
if configurerStr != "" {
configurer, err := sdk.AccAddressFromBech32(configurerStr)
if err != nil {
return err
}
config.Configurer = configurer
}
validDomainName, err := cmd.Flags().GetString("valid-domain-name")
if err != nil {
return
return err
}

validDomain, err := cmd.Flags().GetString("valid-domain")
if validDomainName != defaultRegex {
config.ValidDomainName = validDomainName
}
validAccountName, err := cmd.Flags().GetString("valid-account-name")
if err != nil {
return err
}
_, err = regexp.Compile(validDomain)
if validAccountName != defaultRegex {
config.ValidAccountName = validAccountName
}
validBlockchainID, err := cmd.Flags().GetString("valid-blockchain-id")
if err != nil {
return err
}

validName, err := cmd.Flags().GetString("valid-name")
if validBlockchainID != defaultRegex {
config.ValidBlockchainID = validBlockchainID
}
validBlockchainAddress, err := cmd.Flags().GetString("valid-blockchain-address")
if err != nil {
return err
}
_, err = regexp.Compile(validName)
if validBlockchainAddress != defaultRegex {
config.ValidBlockchainAddress = validBlockchainAddress
}
domainRenew, err := cmd.Flags().GetDuration("domain-renew-period")
if err != nil {
return err
}

validBlockchainID, err := cmd.Flags().GetString("valid-blockchain-id")
if domainRenew != defaultDuration {
config.DomainRenewalPeriod = domainRenew
}
domainRenewCountMax, err := cmd.Flags().GetUint32("domain-renew-count-max")
if err != nil {
return err
}
_, err = regexp.Compile(validBlockchainID)
if domainRenewCountMax != defaultNumber {
config.DomainRenewalCountMax = domainRenewCountMax
}
domainGracePeriod, err := cmd.Flags().GetDuration("domain-grace-period")
if err != nil {
return err
}

validBlockchainAddress, err := cmd.Flags().GetString("valid-blockchain-address")
if domainGracePeriod != defaultNumber {
config.DomainGracePeriod = domainGracePeriod
}
accountRenewPeriod, err := cmd.Flags().GetDuration("account-renew-period")
if err != nil {
return err
}
_, err = regexp.Compile(validBlockchainAddress)
if accountRenewPeriod != defaultNumber {
config.AccountRenewalPeriod = accountRenewPeriod
}
accountRenewCountMax, err := cmd.Flags().GetUint32("account-renew-count-max")
if err != nil {
return err
}

domainRenew, err := cmd.Flags().GetDuration("domain-renew")
if accountRenewCountMax != defaultNumber {
config.AccountRenewalCountMax = accountRenewCountMax
}
accountGracePeriod, err := cmd.Flags().GetDuration("account-grace-period")
if err != nil {
return err
}

domainGracePeriod, err := cmd.Flags().GetDuration("domain-grace-period")
if accountGracePeriod != defaultDuration {
config.AccountGracePeriod = accountGracePeriod
}
blockchainTargetMax, err := cmd.Flags().GetUint32("blockchain-target-max")
if err != nil {
return err
}
if blockchainTargetMax != defaultNumber {
config.BlockchainTargetMax = blockchainTargetMax
}
certificateSizeMax, err := cmd.Flags().GetUint64("certificate-size-max")
if err != nil {
return err
}
if certificateSizeMax != defaultNumber {
config.CertificateSizeMax = certificateSizeMax
}
certificateCountMax, err := cmd.Flags().GetUint32("certificate-count-max")
if err != nil {
return err
}
if certificateCountMax != defaultNumber {
config.CertificateCountMax = certificateCountMax
}
metadataSizeMax, err := cmd.Flags().GetUint64("metadata-size-max")
if err != nil {
return err
}
if metadataSizeMax != defaultNumber {
config.MetadataSizeMax = metadataSizeMax
}

config := types.Config{
Configurer: configurer,
ValidDomain: validDomain,
ValidName: validName,
ValidBlockchainID: validBlockchainID,
ValidBlockchainAddress: validBlockchainAddress,
DomainRenew: domainRenew,
DomainGracePeriod: domainGracePeriod,
if err := config.Validate(); err != nil {
return err
}
// build msg
msg := &types.MsgUpdateConfig{
Expand All @@ -122,15 +182,25 @@ func getCmdUpdateConfig(cdc *codec.Codec) *cobra.Command {
return utils.GenerateOrBroadcastMsgs(cliCtx, txBuilder, []sdk.Msg{msg})
},
}
defaultDuration, _ := time.ParseDuration("1h")
// add flags
cmd.Flags().String("configurer", "", "configurer in bech32 format")
cmd.Flags().String("valid-domain", "", "regexp that determines if domain name is valid or not")
cmd.Flags().String("valid-name", "", "regexp that determines if account name is valid or not")
cmd.Flags().String("valid-blockchain-id", "", "regexp that determines if blockchain id is valid or not")
cmd.Flags().String("valid-blockchain-address", "", "regexp that determines if blockchain address is valid or not")
cmd.Flags().Duration("domain-renew", defaultDuration, "domain renewal duration in seconds before expiration")
cmd.Flags().String("valid-domain-name", defaultRegex, "regexp that determines if domain name is valid or not")
cmd.Flags().String("valid-account-name", defaultRegex, "regexp that determines if account name is valid or not")
cmd.Flags().String("valid-blockchain-id", defaultRegex, "regexp that determines if blockchain id is valid or not")
cmd.Flags().String("valid-blockchain-address", defaultRegex, "regexp that determines if blockchain address is valid or not")

cmd.Flags().Duration("domain-renew-period", defaultDuration, "domain renewal duration in seconds before expiration")
cmd.Flags().Uint32("domain-renew-count-max", uint32(defaultNumber), "maximum number of applicable domain renewals")
cmd.Flags().Duration("domain-grace-period", defaultDuration, "domain grace period duration in seconds")

cmd.Flags().Duration("account-renew-period", defaultDuration, "domain renewal duration in seconds before expiration")
cmd.Flags().Uint32("account-renew-count-max", uint32(defaultNumber), "maximum number of applicable account renewals")
cmd.Flags().Duration("account-grace-period", defaultDuration, "account grace period duration in seconds")

cmd.Flags().Uint32("blockchain-target-max", uint32(defaultNumber), "maximum number of blockchain targets could be saved under an account")
cmd.Flags().Uint64("certificate-size-max", uint64(defaultNumber), "maximum size of a certificate that could be saved under an account")
cmd.Flags().Uint32("certificate-count-max", uint32(defaultNumber), "maximum number of certificates that could be saved under an account")
cmd.Flags().Uint64("metadata-size-max", uint64(defaultNumber), "maximum size of metadata that could be saved under an account")
return cmd
}

Expand Down
37 changes: 15 additions & 22 deletions x/configuration/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package configuration

import (
"fmt"
"regexp"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/iov-one/iovns/x/configuration/types"
Expand All @@ -28,23 +27,8 @@ func NewGenesisState(conf types.Config, fees *types.Fees) GenesisState {
// ValidateGenesis makes sure that the genesis state is valid
func ValidateGenesis(data GenesisState) error {
conf := data.Config
if conf.DomainRenew < 0 {
return fmt.Errorf("empty domain renew")
}
if conf.Configurer == nil {
return fmt.Errorf("empty owner")
}
if _, err := regexp.Compile(conf.ValidBlockchainAddress); err != nil {
return fmt.Errorf("empty valid blockchain address regexp: %w", err)
}
if _, err := regexp.Compile(conf.ValidBlockchainID); err != nil {
return fmt.Errorf("empty valid blockchain id regexp: %w", err)
}
if _, err := regexp.Compile(conf.ValidDomain); err != nil {
return fmt.Errorf("empty valid domain regexp: %w", err)
}
if conf.ValidName == "" {
return fmt.Errorf("empty valid name regexp")
if err := conf.Validate(); err != nil {
return err
}
if data.Fees == nil {
return fmt.Errorf("empty fees")
Expand All @@ -69,11 +53,20 @@ func DefaultGenesisState() GenesisState {
// set default configs
config := types.Config{
Configurer: owner,
ValidDomain: "^(.*?)?",
ValidName: "^(.*?)?",
ValidDomainName: "^(.*?)?",
ValidAccountName: "^(.*?)?",
ValidBlockchainID: "^(.*?)?",
ValidBlockchainAddress: "^(.*?)?",
DomainRenew: 86400,
DomainRenewalPeriod: 86400,
DomainRenewalCountMax: 86400,
DomainGracePeriod: 86400,
AccountRenewalPeriod: 86400,
AccountRenewalCountMax: 86400,
AccountGracePeriod: 86400,
BlockchainTargetMax: 86400,
CertificateSizeMax: 86400,
CertificateCountMax: 86400,
MetadataSizeMax: 86400,
}
// set fees
fees := types.NewFees()
Expand All @@ -90,7 +83,7 @@ func DefaultGenesisState() GenesisState {
fees.UpsertDefaultFees(&domain_types.MsgReplaceAccountTargets{}, defFee)
fees.UpsertDefaultFees(&domain_types.MsgTransferAccount{}, defFee)
fees.UpsertDefaultFees(&domain_types.MsgTransferDomain{}, defFee)
fees.UpsertDefaultFees(&domain_types.MsgSetAccountMetadata{}, defFee)
fees.UpsertDefaultFees(&domain_types.MsgReplaceAccountMetadata{}, defFee)
// return genesis
return GenesisState{
Config: config,
Expand Down
Loading

0 comments on commit bee2ecd

Please sign in to comment.