Skip to content

Commit

Permalink
Merge branch 'extra-rest/v2.4.x' of https://github.com/bandprotocol/c…
Browse files Browse the repository at this point in the history
…hain into extra-rest/v2.5.x
  • Loading branch information
RogerKSI committed Apr 17, 2023
2 parents fec38c4 + dfd54e7 commit 7100da1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 74 deletions.
74 changes: 25 additions & 49 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,31 @@ services:
dockerfile: Dockerfile
image: band-validator:latest
networks:
bandchain:
ipv4_address: 172.18.0.11
- bandchain
command: sh -c "chmod +x ./run.sh && ./run.sh validator1"

multi-validator2-node:
image: band-validator:latest
networks:
bandchain:
ipv4_address: 172.18.0.12
- bandchain
command: sh -c "chmod +x ./run.sh && ./run.sh validator2"

multi-validator3-node:
image: band-validator:latest
networks:
bandchain:
ipv4_address: 172.18.0.13
- bandchain
command: sh -c "chmod +x ./run.sh && ./run.sh validator3"

multi-validator4-node:
image: band-validator:latest
networks:
bandchain:
ipv4_address: 172.18.0.14
- bandchain
command: sh -c "chmod +x ./run.sh && ./run.sh validator4"

emitter-node:
image: band-validator:latest
networks:
bandchain:
- bandchain
command: sh -c "chmod +x ./run.sh && ./run.sh emitter"

query-node:
Expand All @@ -45,26 +41,16 @@ services:
- 1317:1317
- 9090:9090
networks:
bandchain:
ipv4_address: 172.18.0.15
- bandchain
command: sh -c "chmod +x ./run.sh && ./run.sh query-node"
# rest-server:
# image: band-validator:latest
# networks:
# bandchain:
# ipv4_address: 172.18.0.20
# restart: always
# ports:
# - 1317:1317
# command: bandcli rest-server --laddr tcp://0.0.0.0:1317 --node tcp://172.18.0.15:26657 --chain-id bandchain --trust-node

proxy-server:
build:
context: ./proxy
image: proxy-server:latest
restart: always
networks:
bandchain:
ipv4_address: 172.18.0.99
- bandchain
depends_on:
- query-node
ports:
Expand All @@ -74,9 +60,9 @@ services:
build:
context: ./proxy-ssl
image: proxy-ssl-server:latest
restart: always
networks:
bandchain:
ipv4_address: 172.18.0.98
- bandchain
depends_on:
- query-node
ports:
Expand All @@ -89,9 +75,10 @@ services:
postgres:
image: postgres:12
restart: always
ports:
- "5432:5432"
networks:
bandchain:
ipv4_address: 172.18.0.88
- bandchain
environment:
POSTGRES_PASSWORD: postgrespassword

Expand All @@ -100,44 +87,35 @@ services:
context: ./hasura
image: hasura:latest
ports:
- "5433:5433"
- "5433:8080"
depends_on:
- "postgres"
restart: always
networks:
bandchain:
ipv4_address: 172.18.0.89
- bandchain
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@172.18.0.88:5432/postgres
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@172.18.0.88:5432/postgres
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_SERVER_HOST: 0.0.0.0
HASURA_GRAPHQL_SERVER_PORT: 5433
HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES: "true"
volumes:
- ./hasura/hasura-metadata:/hasura-metadata

# TODO: Expose port to consume kafka from other
zookeeper:
image: wurstmeister/zookeeper
# ports:
# - "2181:2181"
networks:
bandchain:
ipv4_address: 172.18.0.30
- bandchain
kafka:
image: wurstmeister/kafka
# ports:
# - "9092:9092"
networks:
bandchain:
ipv4_address: 172.18.0.31
- bandchain
environment:
KAFKA_ADVERTISED_HOST_NAME: 172.18.0.31
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ADVERTISED_PORT: 9092
KAFKA_CREATE_TOPICS: test:1:1
KAFKA_ZOOKEEPER_CONNECT: 172.18.0.30:2181
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock

Expand All @@ -147,17 +125,15 @@ services:
image: bandchain_flusher:latest
networks:
bandchain:
command: sh -c "sleep 30 && python main.py init bandchain test replay --db postgres:postgrespassword@172.18.0.88:5432/postgres"
command: sh -c "sleep 30 && python main.py init bandchain test replay --db postgres:postgrespassword@postgres:5432/postgres"

flusher-daemon:
image: bandchain_flusher:latest
networks:
bandchain:
- bandchain
restart: always

networks:
bandchain:
ipam:
driver: default
config:
- subnet: "172.18.0.0/16"


13 changes: 8 additions & 5 deletions docker-config/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ cp /chain/docker-config/$1/node_key.json ~/.band/config/node_key.json
cp /chain/docker-config/genesis.json ~/.band/config/genesis.json
cp -r /chain/docker-config/files ~/.band

sed -E -i \
"s/timeout_commit = \".*\"/timeout_commit = \"3s\"/" \
~/.band/config/config.toml

if [ "$1" == "query-node" ];then
cp /chain/docker-config/app.toml ~/.band/config/app.toml
fi

if [ "$1" == "emitter" ];then
sleep 60
bandd start --with-emitter test@172.18.0.31:9092 \
--p2p.persistent_peers 11392b605378063b1c505c0ab123f04bd710d7d7@172.18.0.11:26656,0851086afcd835d5a6fb0ffbf96fcdf74fec742e@172.18.0.12:26656,63808bd64f2ec19acb2a494c8ce8467c595f6fba@172.18.0.14:26656,7b58b086dd915a79836eb8bfa956aeb9488d13b0@172.18.0.13:26656
bandd start --with-emitter test@kafka:9092 \
--p2p.persistent_peers 11392b605378063b1c505c0ab123f04bd710d7d7@multi-validator1-node:26656,0851086afcd835d5a6fb0ffbf96fcdf74fec742e@multi-validator2-node:26656,63808bd64f2ec19acb2a494c8ce8467c595f6fba@multi-validator3-node:26656,7b58b086dd915a79836eb8bfa956aeb9488d13b0@multi-validator4-node:26656
elif [ "$1" == "query-node" ];then
bandd start --rpc.laddr tcp://0.0.0.0:26657 \
--p2p.persistent_peers [email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656 --pruning nothing \
--with-request-search=sqlite3:rqsearch.db \
--p2p.persistent_peers 11392b605378063b1c505c0ab123f04bd710d7d7@multi-validator1-node:26656,0851086afcd835d5a6fb0ffbf96fcdf74fec742e@multi-validator2-node:26656,63808bd64f2ec19acb2a494c8ce8467c595f6fba@multi-validator3-node:26656,7b58b086dd915a79836eb8bfa956aeb9488d13b0@multi-validator4-node:26656 --with-request-search=sqlite3:rqsearch.db \
--with-pricer=1
else
bandd start --rpc.laddr tcp://0.0.0.0:26657 \
--p2p.persistent_peers 11392b605378063b1c505c0ab123f04bd710d7d7@172.18.0.11:26656,0851086afcd835d5a6fb0ffbf96fcdf74fec742e@172.18.0.12:26656,63808bd64f2ec19acb2a494c8ce8467c595f6fba@172.18.0.14:26656,7b58b086dd915a79836eb8bfa956aeb9488d13b0@172.18.0.13:26656
--p2p.persistent_peers 11392b605378063b1c505c0ab123f04bd710d7d7@multi-validator1-node:26656,0851086afcd835d5a6fb0ffbf96fcdf74fec742e@multi-validator2-node:26656,63808bd64f2ec19acb2a494c8ce8467c595f6fba@multi-validator3-node:26656,7b58b086dd915a79836eb8bfa956aeb9488d13b0@multi-validator4-node:26656
fi
19 changes: 11 additions & 8 deletions docker-config/start_docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

source ~/.profile
# docker rm --force $(docker ps -a -q)

DIR=`dirname "$0"`

# remove old genesis
Expand Down Expand Up @@ -57,7 +60,7 @@ bandd gentx validator1 100000000uband \
--pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/V/OZek6B2PMh6XEJJ+IsLm0w+22PdJqeSgevs7O3kJ"}' \
--details "Alice's Adventures in Wonderland (commonly shortened to Alice in Wonderland) is an 1865 novel written by English author Charles Lutwidge Dodgson under the pseudonym Lewis Carroll." \
--website "https://www.alice.org/" \
--ip 172.18.0.11 \
--ip multi-validator1-node \
--keyring-backend test

# modify moniker
Expand All @@ -69,7 +72,7 @@ bandd gentx validator2 100000000uband \
--pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AnJK4pz+t0lwUdCe39joIjUsTINht1dkdkW3jIzHTOiF"}' \
--details "Fish is best known for his appearances with Ring of Honor (ROH) from 2013 to 2017, where he wrestled as one-half of the tag team reDRagon and held the ROH World Tag Team Championship three times and the ROH World Television Championship once." \
--website "https://www.wwe.com/superstars/bobby-fish" \
--ip 172.18.0.12 \
--ip multi-validator2-node \
--keyring-backend test

# modify moniker
Expand All @@ -81,7 +84,7 @@ bandd gentx validator3 100000000uband \
--pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A6VP+qhMjy95h4Lei5YqhHhOKISHp0eBOghXJDpg4roz"}' \
--details "Carol Susan Jane Danvers is a fictional superhero appearing in American comic books published by Marvel Comics. Created by writer Roy Thomas and artist Gene Colan." \
--website "https://www.marvel.com/characters/captain-marvel-carol-danvers" \
--ip 172.18.0.13 \
--ip multi-validator3-node \
--keyring-backend test

# modify moniker
Expand All @@ -93,7 +96,7 @@ bandd gentx validator4 100000000uband \
--pubkey '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A9A3CPFh0Vg/SeQmCkKysI07oYbXgDojzDrNEvB02ddv"}' \
--details "Evil is an American supernatural drama television series created by Robert King and Michelle King that premiered on September 26, 2019, on CBS. The series is produced by CBS Television Studios and King Size Productions." \
--website "https://www.imdb.com/title/tt9055008/" \
--ip 172.18.0.14 \
--ip multi-validator4-node \
--keyring-backend test

# remove temp test
Expand All @@ -106,6 +109,7 @@ bandd collect-gentxs
cp ~/.band/config/genesis.json $DIR/genesis.json
sed -i -e 's/\"allow_messages\":.*/\"allow_messages\": [\"\/cosmos.authz.v1beta1.MsgExec\", \"\/cosmos.authz.v1beta1.MsgGrant\", \"\/cosmos.authz.v1beta1.MsgRevoke\", \"\/cosmos.bank.v1beta1.MsgSend\", \"\/cosmos.bank.v1beta1.MsgMultiSend\", \"\/cosmos.distribution.v1beta1.MsgSetWithdrawAddress\", \"\/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission\", \"\/cosmos.distribution.v1beta1.MsgFundCommunityPool\", \"\/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward\", \"\/cosmos.feegrant.v1beta1.MsgGrantAllowance\", \"\/cosmos.feegrant.v1beta1.MsgRevokeAllowance\", \"\/cosmos.gov.v1beta1.MsgVoteWeighted\", \"\/cosmos.gov.v1beta1.MsgSubmitProposal\", \"\/cosmos.gov.v1beta1.MsgDeposit\", \"\/cosmos.gov.v1beta1.MsgVote\", \"\/cosmos.staking.v1beta1.MsgEditValidator\", \"\/cosmos.staking.v1beta1.MsgDelegate\", \"\/cosmos.staking.v1beta1.MsgUndelegate\", \"\/cosmos.staking.v1beta1.MsgBeginRedelegate\", \"\/cosmos.staking.v1beta1.MsgCreateValidator\", \"\/cosmos.vesting.v1beta1.MsgCreateVestingAccount\", \"\/ibc.applications.transfer.v1.MsgTransfer\"]/g' $DIR/genesis.json

# Build
docker-compose up -d --build

sleep 10
Expand All @@ -114,8 +118,7 @@ for v in {1..4}
do
rm -rf ~/.yoda
yoda config chain-id bandchain
yoda config node tcp://172.18.0.1$v:26657
yoda config chain-rest-server http://172.18.0.20:1317
yoda config node tcp://multi-validator$v-node:26657
yoda config validator $(bandd keys show validator$v -a --bech val --keyring-backend test)
yoda config executor "rest:https://asia-southeast2-band-playground.cloudfunctions.net/test-runtime-executor?timeout=10s"

Expand Down Expand Up @@ -151,7 +154,7 @@ done
# Create faucet container
rm -rf ~/.faucet
faucet config chain-id bandchain
faucet config node tcp://172.18.0.15:26657
faucet config node tcp://query-node:26657
faucet config port 5005
for i in $(eval echo {1..5})
do
Expand All @@ -165,6 +168,6 @@ do
sleep 2
done

docker create --network chain_bandchain --name bandchain_faucet -p 5005:5005 --ip 172.18.0.17 band-validator:latest faucet r
docker create --network chain_bandchain --name bandchain_faucet -p 5005:5005 band-validator:latest faucet r
docker cp ~/.faucet bandchain_faucet:/root/.faucet
docker start bandchain_faucet
2 changes: 1 addition & 1 deletion flusher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RUN apt-get update && apt-get install -y libpq-dev gcc
RUN pip install -r requirements.txt

# TODO: Using environment variable for db and kafka bootstrap services
CMD python main.py sync --db postgres:postgrespassword@172.18.0.88:5432/postgres -s 172.18.0.31:9092
CMD python main.py sync --db postgres:postgrespassword@postgres:5432/postgres -s kafka:9092
1 change: 1 addition & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,5 @@ def Column(*args, **kwargs):
Column("counterparty_channel", sa.String),
Column("state", sa.Integer),
Column("order", sa.String),
Column("last_update", CustomDateTime, index=True),
)
19 changes: 18 additions & 1 deletion flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def handle_new_block(self, msg):
self.conn.execute(blocks.insert(), msg)

def handle_new_transaction(self, msg):
msg["fee_payer"] = msg["fee_payer"] if len(msg["fee_payer"]) else None
msg["fee_payer"] = msg["fee_payer"] if "fee_payer" in msg and len(msg["fee_payer"]) else None
self.conn.execute(
insert(transactions).values(**msg).on_conflict_do_update(constraint="transactions_pkey", set_=msg)
)
Expand Down Expand Up @@ -392,20 +392,30 @@ def handle_set_request_count_per_day(self, msg):
)

def handle_new_incoming_packet(self, msg):
self.update_last_update_channel(msg['dst_port'], msg['dst_channel'], msg['block_time'])
del msg["block_time"]

msg["tx_id"] = self.get_transaction_id(msg["hash"])
del msg["hash"]
self.conn.execute(
insert(incoming_packets).values(**msg).on_conflict_do_nothing(constraint="incoming_packets_pkey")
)

def handle_new_outgoing_packet(self, msg):
self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time'])
del msg["block_time"]

msg["tx_id"] = self.get_transaction_id(msg["hash"])
del msg["hash"]

self.conn.execute(
insert(outgoing_packets).values(**msg).on_conflict_do_nothing(constraint="outgoing_packets_pkey")
)

def handle_update_outgoing_packet(self, msg):
self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time'])
del msg["block_time"]

condition = True
for col in outgoing_packets.primary_key.columns.values():
condition = (col == msg[col.name]) & condition
Expand Down Expand Up @@ -439,3 +449,10 @@ def handle_set_connection(self, msg):

def handle_set_channel(self, msg):
self.conn.execute(insert(channels).values(**msg).on_conflict_do_update(constraint="channels_pkey", set_=msg))

def update_last_update_channel(self, port, channel, timestamp):
self.conn.execute(
channels.update().where((channels.c.port == port) & (channels.c.channel == channel)).values(
last_update=timestamp
)
)
2 changes: 2 additions & 0 deletions hooks/emitter/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (h *Hook) emitSetChannel(ctx sdk.Context, portId string, channelId string)
"counterparty_channel": channel.Counterparty.ChannelId,
"state": channel.State,
"order": channel.Ordering,
"last_update": ctx.BlockTime().UnixNano(),
})
}

Expand Down Expand Up @@ -109,6 +110,7 @@ func newPacket(
) common.JsDict {
return common.JsDict{
"block_height": ctx.BlockHeight(),
"block_time": ctx.BlockTime().UnixNano(),
"src_channel": srcChannel,
"src_port": srcPort,
"sequence": sequence,
Expand Down
Loading

0 comments on commit 7100da1

Please sign in to comment.