Skip to content

Commit

Permalink
feat: customize staking module for inscription (#11)
Browse files Browse the repository at this point in the history
* staking: integrate with custom staking module

* docker: fix Dockerfile

* dep: update cosmos-sdk

* fix: CreateValidator failed
  • Loading branch information
j75689 authored Dec 23, 2022
1 parent 9f42bb6 commit c2aba0b
Show file tree
Hide file tree
Showing 8 changed files with 650 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ARG USER=bfs
ARG USER_UID=1000
ARG USER_GID=1000

ENV PACKAGES ca-certificates bash curl
ENV PACKAGES ca-certificates bash curl libstdc++
ENV WORKDIR=/server

RUN apk add --no-cache $PACKAGES \
Expand Down
11 changes: 11 additions & 0 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
types3 "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -114,13 +115,20 @@ func (suite *AnteTestSuite) CreateTestEIP712MsgCreateValidator(from sdk.AccAddre
// Build MsgCreateValidator
valAddr := sdk.ValAddress(from.Bytes())
privEd := ed25519.GenPrivKey()
addr1 := sdk.AccAddress(from.Bytes())
blsSecretKey, _ := bls.RandKey()
blsPk := hex.EncodeToString(blsSecretKey.PublicKey().Marshal())
msgCreate, err := types3.NewMsgCreateValidator(
valAddr,
privEd.PubKey(),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20)),
types3.NewDescription("moniker", "indentity", "website", "security_contract", "details"),
types3.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
addr1,
addr1,
addr1,
blsPk,
)
suite.Require().NoError(err)
return suite.CreateTestEIP712CosmosTxBuilder(from, priv, chainId, gas, gasAmount, msgCreate)
Expand Down Expand Up @@ -150,11 +158,14 @@ func (suite *AnteTestSuite) CreateTestEIP712GrantAllowance(from sdk.AccAddress,

func (suite *AnteTestSuite) CreateTestEIP712MsgEditValidator(from sdk.AccAddress, priv cryptotypes.PrivKey, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
valAddr := sdk.ValAddress(from.Bytes())
blsSecretKey, _ := bls.RandKey()
blsPk := hex.EncodeToString(blsSecretKey.PublicKey().Marshal())
msgEdit := types3.NewMsgEditValidator(
valAddr,
types3.NewDescription("moniker", "identity", "website", "security_contract", "details"),
nil,
nil,
sdk.AccAddress(priv.PubKey().Address()), blsPk,
)
return suite.CreateTestEIP712CosmosTxBuilder(from, priv, chainId, gas, gasAmount, msgEdit)
}
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ func New(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.AuthzKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
)
Expand Down
9 changes: 6 additions & 3 deletions crypto/keyring/options.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package keyring

import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
ethHd "github.com/evmos/ethermint/crypto/hd"
)

var (
// SupportedAlgorithms defines the list of signing algorithms used on BFS:
// - eth_secp256k1 (Ethereum)
SupportedAlgorithms = keyring.SigningAlgoList{ethHd.EthSecp256k1}
// - eth_bls (Ethereum)
SupportedAlgorithms = keyring.SigningAlgoList{ethHd.EthSecp256k1, hd.EthBLS}
// SupportedAlgorithmsLedger defines the list of signing algorithms used on BFS for the Ledger device:
// - eth_secp256k1 (Ethereum)
SupportedAlgorithmsLedger = keyring.SigningAlgoList{ethHd.EthSecp256k1}
// - eth_bls (Ethereum)
SupportedAlgorithmsLedger = keyring.SigningAlgoList{ethHd.EthSecp256k1, hd.EthBLS}
)

// ETHAlgoOption defines a function keys options for the ethereum Secp256k1 curve.
// It supports eth_secp256k1 keys for accounts.
// It supports eth_secp256k1, eth_bls keys for accounts.
func ETHAlgoOption() keyring.Option {
return func(options *keyring.Options) {
options.SupportedAlgos = SupportedAlgorithms
Expand Down
10 changes: 8 additions & 2 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ function init() {
mkdir -p ${workspace}/.local
for ((i=0;i<${size};i++));do
mkdir -p ${workspace}/.local/validator${i}
mkdir -p ${workspace}/.local/relayer${i}

# init chain
${bin} init validator${i} --chain-id ${CHAIN_ID} --staking-bond-denom ${STAKING_BOND_DENOM} --home ${workspace}/.local/validator${i}

# create genesis accounts
${bin} keys add validator${i} --keyring-backend test --home ${workspace}/.local/validator${i} > ${workspace}/.local/validator${i}/info
${bin} keys add relayer${i} --keyring-backend test --home ${workspace}/.local/relayer${i} --algo eth_bls > ${workspace}/.local/relayer${i}/info
done
}

Expand All @@ -50,8 +52,13 @@ function generate_genesis() {
done

rm -rf ${workspace}/.local/validator${i}/config/gentx/

validatorAddr=${validator_addrs[$i]}
relayerAddr="$(${bin} keys show relayer${i} -a --keyring-backend test --home ${workspace}/.local/relayer${i})"
relayerBLSKey="$(${bin} keys show relayer${i} --keyring-backend test --home ${workspace}/.local/relayer${i} --output json | jq -r .pubkey_hex)"

# create bond validator tx
${bin} gentx validator${i} ${STAKING_BOND_AMOUNT}${STAKING_BOND_DENOM} \
${bin} gentx validator${i} ${STAKING_BOND_AMOUNT}${STAKING_BOND_DENOM} $validatorAddr $relayerAddr $relayerBLSKey \
--home ${workspace}/.local/validator${i} \
--keyring-backend=test \
--chain-id=${CHAIN_ID} \
Expand All @@ -64,7 +71,6 @@ function generate_genesis() {
--node tcp://localhost:$((${p2p_port_start}+${i})) \
--node-id "validator${i}" \
--ip 127.0.0.1

cp ${workspace}/.local/validator${i}/config/gentx/gentx-validator${i}.json ${workspace}/.local/gentx/
done

Expand Down
8 changes: 5 additions & 3 deletions deployment/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The ~/.bfsd folder has the following structure:
```bash
# new key
./build/bin/bfsd keys add validator --keyring-backend test
./build/bin/bfsd keys add relayer --keyring-backend test --algo eth_bls

# list accounts
./build/bin/bfsd keys list --keyring-backend test
Expand All @@ -43,13 +44,15 @@ See more details: https://docs.cosmos.network/v0.46/run-node/keyring.html#availa
Before starting the chain, you need to populate the state with at least one account.
```bash
VALIDATOR=$(./build/bin/bfsd keys show validator -a --keyring-backend test)
RELAYER=$(./build/bin/bfsd keys show relayer -a --keyring-backend test)
RELAYER_BLS=$(./build/bin/bfsd keys show relayer -a --keyring-backend test --output json | jq -r .pubkey_hex)"
./build/bin/bfsd add-genesis-account $VALIDATOR 100000000000bnb
```
5. Create validator in genesis state
```bash
# create a gentx.
./build/bin/bfsd gentx validator 1000000000bnb --keyring-backend=test --chain-id=inscription_9000-121 \
./build/bin/bfsd gentx validator 1000000000bnb $VALIDATOR $RELAYER $RELAYER_BLS --keyring-backend=test --chain-id=inscription_9000-121 \
--moniker="validator" \
--commission-max-change-rate=0.01 \
--commission-max-rate=1.0 \
Expand Down Expand Up @@ -78,12 +81,11 @@ bash ./deployment/localup/localup.sh stop
3. Send Tx
```bash
./build/bin/bfsd tx bank send 0xAa52014550825A7fE871cb2e7A053EF1D0D283c6 0x32Ff14Fa1547314b95991976DB432F9Aa648A423 500bnb --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750
./build/bin/bfsd tx bank send validator0 0x32Ff14Fa1547314b95991976DB432F9Aa648A423 500bnb --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b block
```
4. Restart the chain without state initialization
```bash
bash ./deployment/localup/localup.sh stop
bash ./deployment/localup/localup.sh start ${SIZE}
```

22 changes: 19 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ require (

require golang.org/x/text v0.4.0 // indirect

require github.com/prysmaticlabs/prysm v0.0.0-20220124113610-e26cde5e091b

require (
cloud.google.com/go v0.105.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
Expand All @@ -39,7 +41,7 @@ require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/hcsshim v0.9.4 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
Expand Down Expand Up @@ -73,6 +75,7 @@ require (
github.com/cosmos/iavl v0.19.4 // indirect
github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect
github.com/cosmos/ledger-go v0.9.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -90,6 +93,7 @@ require (
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/ferranbt/fastssz v0.0.0-20210905181407-59cf6761a7d5 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
Expand Down Expand Up @@ -127,6 +131,7 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.1 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
Expand All @@ -143,6 +148,7 @@ require (
github.com/jpillora/sizestr v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
Expand All @@ -154,11 +160,13 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/sys/mount v0.3.1 // indirect
github.com/moby/sys/mountinfo v0.6.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand All @@ -174,14 +182,16 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/prysmaticlabs/eth2-types v0.0.0-20210303084904-c9735a06829d // indirect
github.com/radovskyb/watcher v1.0.7 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
Expand All @@ -190,17 +200,23 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/takuoki/gocase v1.0.0 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/spn v0.2.1-0.20220921200247-8bafad876bdd // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/wealdtech/go-bytesutil v1.1.1 // indirect
github.com/wealdtech/go-eth2-types/v2 v2.5.2 // indirect
github.com/wealdtech/go-eth2-util v1.6.3 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
github.com/zondax/hid v0.9.1-0.20220302062450-5552068d2266 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
Expand Down Expand Up @@ -228,6 +244,6 @@ require (

replace (
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk v0.46.4 => github.com/bnb-chain/inscription-cosmos-sdk v0.0.2-0.20221214063634-de3874eb7dca
github.com/cosmos/cosmos-sdk v0.46.4 => github.com/bnb-chain/inscription-cosmos-sdk v0.0.2-0.20221223062300-e235b25ee7e4
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
)
Loading

0 comments on commit c2aba0b

Please sign in to comment.