Skip to content

Commit

Permalink
Merge pull request #8 from Team-Kujira/template
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
starsquidnodes authored Jun 5, 2024
2 parents ee97d5c + 222fed0 commit db1c315
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 268 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,13 @@ Default plan files shipped with pond can be found in `$HOME/.pond/planfiles`.
```json
{
"denom": "{{ .Denoms.USDC.Path }}",
"address": "{{ .Contracts.my_contract.Address }}"
"address": "{{ .Contracts.my_contract.Address }}",
"code_id": "{{ .CodeIds.my_contract }} | int"
}
```

Note: To be able to use the resulting code id as an integer value, you need to add `| int` after the template string. Otherwise the code id is provided as a string.

All deployments are done from the `deployer` account: `kujira1k3g54c2sc7g9mgzuzaukm9pvuzcjqy92nk9wse`

### Syntax
Expand Down Expand Up @@ -328,9 +331,20 @@ The above example will create the `POND` token as `factory/kujira1k3g54c2sc7g9mg

It stores the path of all three denoms, which can be accessed in subsequent contract instantiations of that deployment via `{{ .Denoms.POND.Address }}` for example.

#### Codes

If you are working on contracts that change a lot during the development, updating the registry all the might become a tedious task. Therefore you can specify your sources directly in the plan file and Pond deploys them and updates the registry accordingly.

```json
{
"codes":
"my_project": "file:///path/to/my_project/artifacts/my_project-aarch64.wasm"
}
```

#### Contracts

Pond instantiates all contracts from the `deployer` account, which also is set as the owner by default.
Pond instantiates all contracts from the `deployer` account.

To speed up the deployments, Pond handles contracts in batches which combine all instantiations into a single transaction:

Expand Down
4 changes: 3 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
NoContracts bool
ApiUrl string
RpcUrl string
KujiraVersion string
)

// initCmd represents the init command
Expand Down Expand Up @@ -63,7 +64,7 @@ var initCmd = &cobra.Command{

pond, _ := pond.NewPond(LogLevel)
pond.Init(
"docker", Namespace, ListenAddress, ApiUrl, RpcUrl,
"docker", Namespace, ListenAddress, ApiUrl, RpcUrl, KujiraVersion,
Chains, Contracts, Nodes, options,
)
},
Expand All @@ -78,6 +79,7 @@ func init() {
initCmd.PersistentFlags().StringVar(&ListenAddress, "listen", "127.0.0.1", "Set listen address")
initCmd.PersistentFlags().StringVar(&ApiUrl, "api-url", "https://rest.cosmos.directory/kujira", "Set API URL")
initCmd.PersistentFlags().StringVar(&RpcUrl, "rpc-url", "https://rpc.cosmos.directory/kujira", "Set RPC URL")
initCmd.PersistentFlags().StringVar(&KujiraVersion, "kujira-version", "", "Set Kujira version")
initCmd.PersistentFlags().BoolVar(&NoContracts, "no-contracts", false, "Don't deploy contracts on first start")

chains, err := templates.GetChains()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module pond

go 1.21.3
go 1.21

require (
github.com/rs/zerolog v1.32.0
Expand Down
57 changes: 54 additions & 3 deletions pond/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

"pond/pond/chain/feeder"
"pond/pond/chain/node"
"pond/pond/globals"
"pond/utils"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -158,7 +160,9 @@ func (c *Chain) UpdateGenesis(overrides map[string]string) error {
"app_state/gov/params/voting_period": "120s",
},
"kujira": {
"app_state/mint/minter/inflation": "0.0",
"app_state/mint/minter/inflation": "0.0",
},
"kujira-99f7924-1": {
"app_state/oracle/params/required_denoms": []string{"BTC", "ETH"},
"consensus/params/abci/vote_extensions_enable_height": "1",
},
Expand All @@ -179,7 +183,12 @@ func (c *Chain) UpdateGenesis(overrides map[string]string) error {
return c.error(err)
}

for _, key := range []string{"_default", node.Type} {
version, found := globals.Versions[node.Type]
if !found {
return fmt.Errorf("version not found")
}
keys := []string{"_default", node.Type, node.Type + "-" + version}
for _, key := range keys {
values, found := config[key]
if !found {
continue
Expand Down Expand Up @@ -217,6 +226,9 @@ func (c *Chain) GetHeight() (int64, error) {
SyncInfo struct {
LatestBlockHeight string `json:"latest_block_height"`
} `json:"sync_info"`
SyncInfoOld struct {
LatestBlockHeight string `json:"latest_block_height"`
} `json:"SyncInfo"`
}

var status Status
Expand All @@ -231,7 +243,12 @@ func (c *Chain) GetHeight() (int64, error) {
return -1, c.error(err)
}

height, err := strconv.ParseInt(status.SyncInfo.LatestBlockHeight, 10, 64)
strHeight := status.SyncInfoOld.LatestBlockHeight
if strHeight == "" {
strHeight = status.SyncInfo.LatestBlockHeight
}

height, err := strconv.ParseInt(strHeight, 10, 64)
if err != nil {
return -1, c.error(err)
}
Expand Down Expand Up @@ -363,3 +380,37 @@ func (c *Chain) SubmitProposal(data []byte, option string) error {

return nil
}

func (c *Chain) WaitForNode(name string) error {
c.logger.Debug().Str("node", name).Msg("wait for node")

command := []string{c.Command, "ps", "-qf", "name=" + name}
c.logger.Debug().Msg(strings.Join(command, " "))

var (
output []byte
err error
)

retries := 10
for i := 0; i < retries; i++ {
output, err = utils.RunO(c.logger, command)
if err != nil {
return err
}

if len(output) > 0 {
break
}

time.Sleep(time.Millisecond * 200)
}

if len(output) == 0 {
msg := "node not running"
c.logger.Error().Str("node", name).Msg(msg)
return fmt.Errorf(msg)
}

return nil
}
4 changes: 3 additions & 1 deletion pond/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *Chain) Init(namespace string, options map[string]string) error {

image := fmt.Sprintf("docker.io/%s/%s:%s", namespace, c.Type, version)

amount := 1_000_000_000_000
amount := 10_000_000_000_000

var wg sync.WaitGroup

Expand Down Expand Up @@ -61,6 +61,8 @@ func (c *Chain) Init(namespace string, options map[string]string) error {
return
}

c.WaitForNode(c.Nodes[i].Moniker)

err = c.Nodes[i].Init(namespace, amount)
if err != nil {
wg.Done()
Expand Down
30 changes: 30 additions & 0 deletions pond/chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ func (n *Node) Init(namespace string, amount int) error {
return err
}

for i := 0; i < 10; i++ {
_, err = os.Stat(fmt.Sprintf("%s/config/genesis.json", n.Home))
if err == nil {
break
}
n.logger.Debug().Msg("wait genesis.json")
time.Sleep(time.Millisecond * 200)
}
if err != nil {
return err
}

err = n.AddKey("validator", n.Mnemonic)
if err != nil {
n.logger.Err(err)
Expand All @@ -161,6 +173,24 @@ func (n *Node) Init(namespace string, amount int) error {
return err
}

// updating the genesis file takes a little bit, so sleep 100ms
// to ensure the address is found and prevent sleeping once for 500ms
time.Sleep(time.Millisecond * 100)

for i := 0; i < 5; i++ {
data, err := os.ReadFile(fmt.Sprintf("%s/config/genesis.json", n.Home))
if err != nil {
return err
}

if strings.Contains(string(data), address) {
break
}

n.logger.Debug().Msg("wait for genesis account")
time.Sleep(time.Millisecond * 500)
}

err = n.CreateGentx(amount / 2)
if err != nil {
return err
Expand Down
Loading

0 comments on commit db1c315

Please sign in to comment.