Skip to content

Commit

Permalink
Merge pull request #464 from bandprotocol/extra/rest-tss-full-db
Browse files Browse the repository at this point in the history
[Extra/rest] DB, emitter, flusher for tss, bandtss module
  • Loading branch information
RogerKSI authored Nov 28, 2024
2 parents d2c5b25 + 376faef commit 0453b32
Show file tree
Hide file tree
Showing 18 changed files with 1,399 additions and 25 deletions.
2 changes: 2 additions & 0 deletions app/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func NewAppHooks(appCodec codec.Codec,
keepers.OracleKeeper,
keepers.RestakeKeeper,
keepers.FeedsKeeper,
keepers.TSSKeeper,
keepers.BandtssKeeper,
keepers.ICAHostKeeper,
keepers.IBCKeeper.ClientKeeper,
keepers.IBCKeeper.ConnectionKeeper,
Expand Down
43 changes: 43 additions & 0 deletions docker-config/start_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ echo "erase relief tree tobacco around knee concert toast diesel melody rule sig
echo "thought insane behind cool expand clarify strategy occur arrive broccoli middle despair foot cake genuine dawn goose abuse curve identify dinner derive genre effort" \
| bandd keys add account2 --recover --keyring-backend test

echo "drop video mention casual soldier ostrich resemble harvest casual step design gasp grunt lab meadow buzz envelope today spy cliff column habit fall eyebrow" \
| bandd keys add account3 --recover --keyring-backend test

# add accounts to genesis
bandd genesis add-genesis-account validator1 10000000000000uband --keyring-backend test
bandd genesis add-genesis-account validator2 10000000000000uband --keyring-backend test
Expand All @@ -53,6 +56,7 @@ bandd genesis add-genesis-account requester 100000000000000uband --keyring-backe
bandd genesis add-genesis-account relayer 100000000000000uband --keyring-backend test
bandd genesis add-genesis-account account1 100000000000000uband --keyring-backend test
bandd genesis add-genesis-account account2 100000000000000uband --keyring-backend test
bandd genesis add-genesis-account account3 100000000000000uband --keyring-backend test

# create copy of config.toml
cp ~/.band/config/config.toml ~/.band/config/config.toml.temp
Expand Down Expand Up @@ -117,6 +121,7 @@ bandd genesis collect-gentxs
cp ~/.band/config/genesis.json $DIR/genesis.json
cat <<< $(jq '.app_state.gov.params.voting_period = "60s"' $DIR/genesis.json) > $DIR/genesis.json
cat <<< $(jq '.app_state.feeds.params.current_feeds_update_interval = "10"' $DIR/genesis.json) > $DIR/genesis.json
cat <<< $(jq '.app_state.bandtss.params.min_transition_duration = "60s"' $DIR/genesis.json) > $DIR/genesis.json
cat <<< $(jq --arg addr "$(bandd keys show requester -a --keyring-backend test)" '.app_state.feeds.params.admin = $addr' $DIR/genesis.json) > $DIR/genesis.json
cat <<< $(jq '.app_state.restake.params.allowed_denoms = ["uband"]' $DIR/genesis.json) > $DIR/genesis.json

Expand Down Expand Up @@ -162,6 +167,44 @@ do
docker start bandchain-yoda${v}
done

sleep 10

for v in {1..3}
do
rm -rf ~/.cylinder
cylinder config node tcp://multi-validator$v-node:26657
cylinder config chain-id bandchain
cylinder config granter $(bandd keys show account$v -a --keyring-backend test)
cylinder config max-messages 20
cylinder config broadcast-timeout "5m"
cylinder config rpc-poll-interval "1s"
cylinder config max-try 5
cylinder config gas-prices "0uband"
cylinder config min-de 100
cylinder config gas-adjust-start 1.6
cylinder config gas-adjust-step 0.2
cylinder config random-secret "$(openssl rand -hex 32)"
cylinder config checking-de-interval "1m"

for i in $(eval echo {1..4})
do
# add signer key
cylinder keys add signer$i
done

# send band tokens to grantees
echo "y" | bandd tx bank multi-send account$v $(cylinder keys list -a) 1000000uband --keyring-backend test --chain-id bandchain --gas-prices 0.0025uband -b sync
sleep 4

# grant tss
echo "y" | bandd tx tss add-grantees $(cylinder keys list -a) --from account$v --keyring-backend test --chain-id bandchain --gas-prices 0.0025uband --gas 700000 -b sync
sleep 4

docker create --network chain_bandchain --name bandchain-cylinder${v} band-validator:latest cylinder run
docker cp ~/.cylinder bandchain-cylinder${v}:/root/.cylinder
docker start bandchain-cylinder${v}
done

# pull latest image first
docker pull bandprotocol/bothan-api:latest

Expand Down
114 changes: 114 additions & 0 deletions flusher/flusher/bandtss_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import enum

import sqlalchemy as sa

from .db import Column, CustomBase64, CustomDateTime, metadata


class GroupTransitionStatus(enum.Enum):
nil = 0
creating_group = 1
waiting_sign = 2
waiting_execution = 3
success = 4
expired = 5


class CustomGroupTransitionStatus(sa.types.TypeDecorator):
impl = sa.Enum(GroupTransitionStatus)

def process_bind_param(self, value, dialect):
return GroupTransitionStatus(value)


bandtss_group_transitions = sa.Table(
"bandtss_group_transitions",
metadata,
Column("proposal_id", sa.Integer, sa.ForeignKey("proposals.id"), primary_key=True),
Column("tss_signing_id", sa.Integer, sa.ForeignKey("tss_signings.id"), nullable=True),
Column(
"current_tss_group_id",
sa.Integer,
sa.ForeignKey("tss_groups.id"),
nullable=True,
),
Column(
"incoming_tss_group_id",
sa.Integer,
sa.ForeignKey("tss_groups.id"),
nullable=True,
),
Column("current_group_pub_key", CustomBase64, nullable=True),
Column("incoming_group_pub_key", CustomBase64, nullable=True),
Column("status", CustomGroupTransitionStatus),
Column("exec_time", CustomDateTime),
Column("is_force_transition", sa.Boolean),
Column(
"created_height",
sa.Integer,
sa.ForeignKey("blocks.height"),
nullable=True,
index=True,
),
sa.Index(
"ix_tss_signing_id_current_tss_group_id_incoming_tss_group_id",
"tss_signing_id",
"current_tss_group_id",
"incoming_tss_group_id",
),
)

bandtss_historical_current_groups = sa.Table(
"bandtss_historical_current_groups",
metadata,
Column(
"proposal_id",
sa.Integer,
sa.ForeignKey("proposals.id"),
nullable=True,
index=True,
),
Column(
"current_tss_group_id",
sa.Integer,
sa.ForeignKey("tss_groups.id"),
primary_key=True,
),
Column(
"transition_height",
sa.Integer,
sa.ForeignKey("blocks.height"),
index=True,
primary_key=True,
),
)

bandtss_members = sa.Table(
"bandtss_members",
metadata,
Column("tss_group_id", sa.Integer, sa.ForeignKey("tss_groups.id"), primary_key=True),
Column("account_id", sa.Integer, sa.ForeignKey("accounts.id"), primary_key=True),
Column("is_active", sa.Boolean),
Column("since", CustomDateTime, nullable=True),
)

bandtss_signings = sa.Table(
"bandtss_signings",
metadata,
Column("id", sa.Integer, primary_key=True),
Column("account_id", sa.Integer, sa.ForeignKey("accounts.id")),
Column("fee_per_signer", sa.String),
Column("total_fee", sa.String),
Column(
"current_group_tss_signing_id",
sa.Integer,
sa.ForeignKey("tss_signings.id"),
nullable=True,
),
Column(
"incoming_group_tss_signing_id",
sa.Integer,
sa.ForeignKey("tss_signings.id"),
nullable=True,
),
)
24 changes: 12 additions & 12 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,32 @@ class ProposalStatus(enum.Enum):
Inactive = 6


class VoteOption(enum.Enum):
Empty = 0
Yes = 1
Abstain = 2
No = 3
NoWithVeto = 4
class TSSEncoder(enum.Enum):
Unspecified = 0
Proto = 1
FullABI = 2
PartialABI = 3


class CustomResolveStatus(sa.types.TypeDecorator):

impl = sa.Enum(ResolveStatus)

def process_bind_param(self, value, dialect):
return ResolveStatus(value)


class CustomProposalStatus(sa.types.TypeDecorator):

impl = sa.Enum(ProposalStatus)

def process_bind_param(self, value, dialect):
return ProposalStatus(value)


class CustomVoteOption(sa.types.TypeDecorator):

impl = sa.Enum(VoteOption)
class CustomTSSEncoder(sa.types.TypeDecorator):
impl = sa.Enum(TSSEncoder)

def process_bind_param(self, value, dialect):
return VoteOption(value)
return TSSEncoder(value)


class CustomDateTime(sa.types.TypeDecorator):
Expand Down Expand Up @@ -193,6 +189,7 @@ def Column(*args, **kwargs):
Column("prepare_gas_used", sa.Integer, default=0),
Column("execute_gas", sa.Integer),
Column("execute_gas_used", sa.Integer, default=0),
Column("tss_encoder", CustomTSSEncoder),
Column("sender", sa.String, nullable=True),
Column("client_id", sa.String),
Column("request_time", sa.Integer, nullable=True, index=True),
Expand All @@ -201,6 +198,9 @@ def Column(*args, **kwargs):
Column("resolve_height", sa.Integer, sa.ForeignKey("blocks.height"), nullable=True, index=True),
Column("reason", sa.String, nullable=True),
Column("result", CustomBase64, nullable=True),
Column("bandtss_signing_id", sa.Integer, sa.ForeignKey("bandtss_signings.id"), nullable=True),
Column("bandtss_signing_error_codespace", sa.String, nullable=True),
Column("bandtss_signing_error_code", sa.Integer, nullable=True),
Column("total_fees", sa.String),
Column("is_ibc", sa.Boolean),
sa.Index(
Expand Down
Loading

0 comments on commit 0453b32

Please sign in to comment.