Skip to content

Commit

Permalink
Merge branch 'main' into chain-config-per-node
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Dec 15, 2022
2 parents 1917cbf + 5509895 commit f387b9c
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 356 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,15 +726,15 @@ echo hello > /tmp/timestampvm.genesis.json
AVALANCHEGO_EXEC_PATH="${HOME}/go/src/github.com/ava-labs/avalanchego/build/avalanchego"
AVALANCHEGO_PLUGIN_PATH="${HOME}/go/src/github.com/ava-labs/avalanchego/build/plugins"
curl -X POST -k http://localhost:8081/v1/control/start -d '{"execPath":"'${AVALANCHEGO_EXEC_PATH}'","numNodes":5,"logLevel":"INFO","pluginDir":"'${AVALANCHEGO_PLUGIN_PATH}'","blockchainSpecs":[{"vmName":"timestampvm","genesis":"/tmp/timestampvm.genesis.json"}]}'
curl -X POST -k http://localhost:8081/v1/control/start -d '{"execPath":"'${AVALANCHEGO_EXEC_PATH}'","numNodes":5,"logLevel":"INFO","pluginDir":"'${AVALANCHEGO_PLUGIN_PATH}'","blockchainSpecs":[{"vmName":"timestampvm","genesis":"/tmp/timestampvm.genesis.json","blockchain_alias":"timestamp"}]}'
# or
avalanche-network-runner control start \
--log-level debug \
--endpoint="0.0.0.0:8080" \
--avalanchego-path ${AVALANCHEGO_EXEC_PATH} \
--plugin-dir ${AVALANCHEGO_PLUGIN_PATH} \
--blockchain-specs '[{"vm_name":"timestampvm","genesis":"/tmp/timestampvm.genesis.json"}]'
--blockchain-specs '[{"vm_name":"timestampvm","genesis":"/tmp/timestampvm.genesis.json","blockchain_alias":"timestamp"}]'
```
```bash
Expand All @@ -759,14 +759,16 @@ curl -X POST --data '{
# in this example,
# "E8isHenre76NMxbJ3munSQatV8GoQ4XKWQg9vD34xMBqEFJGf" is the blockchain Id
# "timestamp" is the blockchain alias
# You can use 127.0.0.1:9650/ext/bc/timestamp or 127.0.0.1:9650/ext/bc/E8isHenre76NMxbJ3munSQatV8GoQ4XKWQg9vD34xMBqEFJGf
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "timestampvm.proposeBlock",
"params":{
"data":"0x6d796e6577626c6f636b0000000000000000000000000000000000000000000014228326"
},
"id": 1
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/E8isHenre76NMxbJ3munSQatV8GoQ4XKWQg9vD34xMBqEFJGf
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/timestamp
```
```bash
Expand All @@ -775,7 +777,7 @@ curl -X POST --data '{
"method": "timestampvm.getBlock",
"params":{},
"id": 1
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/E8isHenre76NMxbJ3munSQatV8GoQ4XKWQg9vD34xMBqEFJGf
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/timestamp
```
## Configuration
Expand Down
30 changes: 30 additions & 0 deletions local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ func (ln *localNetwork) CreateBlockchains(
if err := ln.waitForCustomChainsReady(ctx, chainInfos); err != nil {
return err
}

if err := ln.RegisterBlockchainAliases(ctx, chainInfos, chainSpecs); err != nil {
return err
}

return nil
}

// if alias is defined in blockchain-specs, registers an alias for the previously created blockchain
func (ln *localNetwork) RegisterBlockchainAliases(
ctx context.Context,
chainInfos []blockchainInfo,
chainSpecs []network.BlockchainSpec,
) error {
fmt.Println()
ln.log.Info(logging.Blue.Wrap(logging.Bold.Wrap("registering blockchain aliases")))
for i, chainSpec := range chainSpecs {
if chainSpec.BlockchainAlias != "" {
blockchainAlias := chainSpec.BlockchainAlias
chainId := chainInfos[i].blockchainID.String()
ln.log.Info("registering blockchain alias",
zap.String("alias", blockchainAlias),
zap.String("chain-id", chainId))
for nodeName, node := range ln.nodes {
if err := node.client.AdminAPI().AliasChain(ctx, chainId, blockchainAlias); err != nil {
return fmt.Errorf("failure to register blockchain alias %v on node %v: %w", blockchainAlias, nodeName, err)
}
}
}
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type BlockchainSpec struct {
ChainConfig []byte
NetworkUpgrade []byte
SubnetConfig []byte
BlockchainAlias string
PerNodeChainConfig map[string][]byte
}

Expand Down
Loading

0 comments on commit f387b9c

Please sign in to comment.