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

Add baedeker scripts that work with Polkadot 1.10+ #689

Open
wants to merge 4 commits into
base: devnet-ready
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .baedeker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.bdk-env
46 changes: 46 additions & 0 deletions .baedeker/forkless-data.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local
m = import 'baedeker-library/mixin/spec.libsonnet',
rm = import 'baedeker-library/mixin/raw-spec.libsonnet',
;

function(relay_spec, forked_spec, fork_source)

local relay = {
name: 'subtensor',
bin: 'bin/subtensor',
spec: {Raw:{
local modifyRaw = bdk.mixer([
rm.resetNetworking($),
rm.decodeSpec(),
rm.polkaLaunchPara($),
rm.reencodeSpec(),
]),
raw_spec: modifyRaw({
name: "Bittensor",
id: "%s_local" % forked_spec,
chainType: "Development",
codeSubstitutes: {},
properties: {
ss58Format: 42,
tokenDecimals: 9,
tokenSymbol: "TAO"
},
genesis: {
raw: {
top: cql.chain(fork_source).latest._preloadKeys._raw,
childrenDefault: {},
},
},
}),
}},
nodes: {
[name]: {
bin: $.bin,
wantedKeys: 'standalone',
},
for name in ['alice', 'bob', 'charlie']
},
};

relay + {
}
11 changes: 11 additions & 0 deletions .baedeker/rewrites.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local dotenv = {
[std.splitLimit(line, "=", 2)[0]]: std.splitLimit(line, "=", 2)[1]
for line in std.split(importstr "../.env", "\n")
if line != ""
if std.member(line, "=")
};

function(prev, repoDir)
(import 'baedeker-library/ops/rewrites.libsonnet').rewriteNodePaths({
'bin/subtensor':'%s/target/release/subtensor' % repoDir,
})(prev)
9 changes: 9 additions & 0 deletions .baedeker/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e
BDK_DIR=$(dirname $(readlink -f "$0"))
RUST_LOG=info baedeker --spec=docker -J$BDK_DIR/vendor/ --generator=docker_compose=$BDK_DIR/.bdk-env --generator=docker_compose_discover=$BDK_DIR/.bdk-env/discover.env --secret=file=$BDK_DIR/.bdk-env/secret --tla-str=relay_spec=rococo-local --input-modules='lib:baedeker-library/ops/nginx.libsonnet' --input-modules='lib:baedeker-library/ops/devtools.libsonnet' --tla-str=repoDir=$(realpath $BDK_DIR/..) $@ $BDK_DIR/rewrites.jsonnet
cd $BDK_DIR/.bdk-env
#docker compose up -d --wait --remove-orphans

# patch spec with Alice balance

Empty file.
21 changes: 21 additions & 0 deletions .baedeker/vendor/baedeker-library/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Unique Network

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions .baedeker/vendor/baedeker-library/inputs/base.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local
genesisState = import '../util/genesisState.libsonnet',
{mixinAllChains, ...} = import '../util/mixin.libsonnet',
k = import '../mixin/keys.libsonnet',
;

function(prev, final)

// :code
local WELLKNOWN_CODE = '0x3a636f6465';

local genesisMixin = {
// TODO: Process from wasm once native runtime free world lands.
specJson: cql.description('<build spec for %s>' % self.path, bdk.processSpec(self.bin, self.spec)),
genesisWasm: self.specJson.genesis.raw.top[WELLKNOWN_CODE],
genesisWasmData: cql.runtimeWasm(self.genesisWasm),
genesisStateVersion: self.genesisWasmData.version.state_version,
genesisHead: genesisState(self.specJson, self.genesisStateVersion),

ss58Format: super?.ss58Format ?? 42,
signatureSchema: super?.signatureSchema ?? 'Sr25519',
// FIXME: Try to guess from runtime metadata.
// If null - try to guess the schema.
// I.e use StashOf of pallet_staking, if staking presents in schema, and so on.
validatorIdAssignment: super?.validatorIdAssignment ?? 'none',

addressSeed(seed):: cql.addressSeed(self.signatureSchema, seed, self.ss58Format),
};

local mergedChains = (prev + mixinAllChains(prev, function(chain, path) genesisMixin + {
path: path,
nodes+: {
[nodename]+: local hostname = '%s-node-%s' % [path, nodename]; {
hostname: hostname,
wantedKeys:
if node?.wantedKeys == 'para' then k.paraWantedKeys($)
else if node?.wantedKeys == 'para-ed' then k.paraWantedKeys($, ed = true)
else if node?.wantedKeys == 'para-nimbus' then k.paraWantedKeys($, nimbus = true)
else if node?.wantedKeys == 'relay' then k.relayWantedKeys($)
else if node?.wantedKeys == 'standalone' then k.standaloneWantedKeys($)
else if std.isObject(node?.wantedKeys) then node?.wantedKeys
else if !('wantedKeys' in node) then {}
else error 'Unknown wantedKeys: %s' % node?.wantedKeys,
},
for [nodename, node] in (chain?.nodes ?? {})
},
}));

mergedChains + mixinAllChains(mergedChains, function(chain, path) {
nodes+: {
[nodename]+: bdk.ensureKeys(node.hostname, node.wantedKeys, chain.ss58Format),
for [nodename, node] in (chain?.nodes ?? {})
},
})
55 changes: 55 additions & 0 deletions .baedeker/vendor/baedeker-library/mixin/keys.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
local
needController({validatorIdAssignment, ...}) =
if validatorIdAssignment == 'none' || validatorIdAssignment == 'collatorSelection' then false
else if validatorIdAssignment == 'staking' then true
else error "unknown validatorIdAssignment: %s" % validatorIdAssignment,
;

{
relayWantedKeys(root): {
[if needController(root) then '_controller']: root.signatureSchema,
_stash: root.signatureSchema,

gran: 'Ed25519',
babe: 'Sr25519',
imon: 'Sr25519',
para: 'Sr25519',
asgn: 'Sr25519',
audi: 'Sr25519',
// rococo: beefy is required
beef: 'Ecdsa',

sessionKeys: {
grandpa: 'gran',
babe: 'babe',
im_online: 'imon',
authority_discovery: 'audi',
para_assignment: 'asgn',
para_validator: 'para',
beefy: 'beef',
},
},
paraWantedKeys(root, ed = false, nimbus = false): {
[if needController(root) then '_controller']: root.signatureSchema,
_stash: root.signatureSchema,

// COMPAT: asset-hub on polkadot uses ed25519 instead of sr25519 for session keys.
// https://github.com/paritytech/cumulus/blob/d4bb2215bb28ee05159c4c7df1b3435177b5bf4e/parachains/common/src/lib.rs#L57-L62
[if nimbus then 'nmbs' else 'aura']: if ed then 'Ed25519' else 'Sr25519',
// COMPAT: moonbeam only supports setting nimbus key in genesis, yet rand key is required.
[if nimbus then 'rand']: {alias: 'nmbs'},

sessionKeys: {
aura: 'aura',
},
},
standaloneWantedKeys(root): {
aura: 'Sr25519',
gran: 'Ed25519',

sessionKeys: {
aura: 'aura',
grandpa: 'gran',
},
},
}
Loading
Loading