Skip to content

Commit a4e719c

Browse files
author
LazyLuis
committed
debug
1 parent 6900bcb commit a4e719c

2 files changed

Lines changed: 70 additions & 38 deletions

File tree

scripts/local_cluster.sh

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22

3-
N=4
4-
KEYS=("v1" "v2" "v3" "v4")
3+
N=3
4+
START=2 # start all node
5+
# START=3 # skip validator 2
6+
if [[ -n "$1" ]]; then
7+
START=$((START + $1))
8+
fi
9+
510
CHAINID="devnet"
611
MONIKER="Side Labs"
712
BINARY="$HOME/go/bin/sided"
@@ -39,13 +44,6 @@ LOGLEVEL="info"
3944
# Set dedicated home directory for the $BINARY instance
4045
HOMEDIR="$HOME/testnet"
4146

42-
# Path variables
43-
# CONFIG=$HOMEDIR/config/config.toml
44-
# APP_TOML=$HOMEDIR/config/app.toml
45-
46-
# GENESIS=$HOMEDIR/config/genesis.json
47-
# TMP_GENESIS=$HOMEDIR/config/tmp_genesis.json
48-
4947
# validate dependencies are installed
5048
command -v jq >/dev/null 2>&1 || {
5149
echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"
@@ -69,6 +67,7 @@ else
6967
overwrite="Y"
7068
fi
7169

70+
APPHOME="$HOMEDIR/side1"
7271

7372
# Setup local node if overwrite is set to Yes, otherwise skip setup
7473
if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
@@ -78,7 +77,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
7877
# Set moniker and chain-id for Cascadia (Moniker can be anything, chain-id must be an integer)
7978
for ((i=1; i<=N; i++)); do
8079

81-
APPHOME="$HOMEDIR/side$i"
80+
APPHOME="${APPHOME%?}$i"
8281
$BINARY init "$MONIKER #$i" -o --chain-id $CHAINID --home $APPHOME --default-denom "${DENOMS[0]}" &> /dev/null
8382

8483
CONFIG=$APPHOME/config/config.toml
@@ -91,6 +90,9 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
9190
sed -i.bak "s/bitcoin_rpc_user = \"\"/bitcoin_rpc_user = \"side\"/g" $APP_TOML
9291
sed -i.bak "s/bitcoin_rpc_password = \"\"/bitcoin_rpc_password = \"12345678\"/g" $APP_TOML
9392

93+
sed -i.bak 's/addr_book_strict = true/addr_book_strict = false/g' $CONFIG
94+
sed -i.bak 's/allow_duplicate_ip = false/allow_duplicate_ip = true/g' $CONFIG
95+
9496
if [[ $i -eq 1 ]]; then
9597

9698
sed -i.bak "s/127.0.0.1:26657/0.0.0.0:26657/g" "$CONFIG"
@@ -167,7 +169,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
167169
cp -f "${APPHOME%?}1/config/genesis.json" "$APPHOME/config/genesis.json"
168170
cp -r "${APPHOME%?}1/keyring-$KEYRING" "$APPHOME/keyring-$KEYRING"
169171

170-
$BINARY genesis gentx v$i ${INITIAL_SUPPLY%?}${DENOMS[0]} --keyring-backend $KEYRING --chain-id $CHAINID --identity "666AC57CC678BEC4" --website="https://side.one" --home $APPHOME --p2p-port "26${i}56" --ip 127.0.0.1
172+
$BINARY genesis gentx v$i ${INITIAL_SUPPLY%?}${DENOMS[0]} --keyring-backend $KEYRING --chain-id $CHAINID --identity "666AC57CC678BEC4" --website="https://side.one" --home $APPHOME --p2p-port "26${i}56"
171173
cp -r "$APPHOME/config/gentx/" "${APPHOME%?}1/config/gentx"
172174

173175
done
@@ -182,29 +184,6 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
182184
shasum ${APPHOME%?}$i/config/genesis.json
183185
done
184186

185-
# exit 0
186-
# $BINARY genesis gentx "${KEYS[1]}" ${INITIAL_SUPPLY%?}${DENOMS[0]} --keyring-backend $KEYRING --chain-id $CHAINID --identity 666AC57CC678BEC4 --website="https://side.one" --home $HOMEDIR2 --p2p-port 26626
187-
# $BINARY genesis gentx "${KEYS[2]}" ${INITIAL_SUPPLY%?}${DENOMS[0]} --keyring-backend $KEYRING --chain-id $CHAINID --identity "666AC57CC678BEC4" --website="https://side.one" --home $HOMEDIR3 --p2p-port 26636
188-
# $BINARY genesis gentx "${KEYS[3]}" ${INITIAL_SUPPLY%?}${DENOMS[0]} --keyring-backend $KEYRING --chain-id $CHAINID --identity "666AC57CC678BEC4" --website="https://side.one" --home $HOMEDIR4 --p2p-port 26646
189-
190-
# cp -r "$HOMEDIR2/config/gentx/" "$HOMEDIR/config/gentx"
191-
# cp -r "$HOMEDIR3/config/gentx/" "$HOMEDIR/config/gentx"
192-
# cp -r "$HOMEDIR4/config/gentx/" "$HOMEDIR/config/gentx"
193-
194-
# # Collect genesis tx
195-
# $BINARY genesis collect-gentxs --home &> /dev/null
196-
# echo "Genesis transactions collected"
197-
198-
# Run this to ensure everything worked and that the genesis file is setup correctly
199-
# $BINARY genesis validate --home "$HOMEDIR"
200-
201-
# cp -f "$HOMEDIR/config/genesis.json" "$HOMEDIR2/config"
202-
# cp -f "$HOMEDIR/config/genesis.json" "$HOMEDIR3/config"
203-
# cp -f "$HOMEDIR/config/genesis.json" "$HOMEDIR4/config"
204-
205-
if [[ $1 == "pending" ]]; then
206-
echo "pending mode is on, please wait for the first block committed."
207-
fi
208187
fi
209188

210189
# Cleanup function to run on Ctrl-C
@@ -219,7 +198,7 @@ cleanup() {
219198
# Trap SIGINT (Ctrl-C)
220199
trap cleanup SIGINT
221200

222-
for ((i=2; i<=N; i++)); do
201+
for ((i=START; i<=N; i++)); do
223202
$BINARY start --home ${APPHOME%?}$i > "$HOMEDIR/output$i.log" 2>&1 &
224203
done
225204

x/oracle/abci/extension.go

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,28 @@ func NewPriceOracleVoteExtHandler(logger log.Logger, valStore baseapp.ValidatorS
5757
func (h *PriceOracleVoteExtHandler) ExtendVoteHandler() sdk.ExtendVoteHandler {
5858
return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
5959

60-
if !h.config.Enable || !voteExtensionEnabled(ctx, req.Height) {
60+
if req.Height < ctx.ConsensusParams().Abci.VoteExtensionsEnableHeight {
6161
return &abci.ResponseExtendVote{}, nil
6262
}
63+
64+
h.logger.Warn("Prepare vote extension")
6365
// here we'd have a helper function that gets all the prices and does a weighted average
6466

67+
// var prices map[string]string
68+
// for {
69+
// prices = h.getAllVolumeWeightedPrices()
70+
// if len(prices) > 0 {
71+
// break
72+
// }
73+
// time.Sleep(time.Second * 2)
74+
// }
75+
// prices := make(map[string]string)
6576
prices := h.getAllVolumeWeightedPrices()
6677
h.lastPriceSyncTS = req.Time.UnixMilli()
6778

6879
headers, err := h.getBitcoinHeaders(ctx, req.Height)
6980
if err != nil {
70-
//return nil, fmt.Errorf("failed to fetch bitcoin headers: %w", err)
81+
// return nil, fmt.Errorf("failed to fetch bitcoin headers: %w", err)
7182
h.logger.Error("failed to fetch bitcoin headers", "error", err)
7283
}
7384
voteExt := types.OracleVoteExtension{
@@ -89,10 +100,16 @@ func (h *PriceOracleVoteExtHandler) ExtendVoteHandler() sdk.ExtendVoteHandler {
89100
func (h *PriceOracleVoteExtHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandler {
90101
return func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
91102

103+
h.logger.Warn("VerifyVoteExtensionHandler", "height", req.Height, "validator", hex.EncodeToString(req.ValidatorAddress), "extenstion", hex.EncodeToString(req.VoteExtension))
104+
92105
if !voteExtensionEnabled(ctx, req.Height) {
93106
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil
94107
}
95108

109+
if len(req.VoteExtension) == 0 {
110+
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
111+
}
112+
96113
validator := hex.EncodeToString(req.ValidatorAddress)
97114
h.logger.Info("VerifyVoteExtensionHandler", "height", req.Height, "validator", validator)
98115
var voteExt types.OracleVoteExtension
@@ -105,6 +122,12 @@ func (h *PriceOracleVoteExtHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteE
105122
return nil, fmt.Errorf("vote extension height does not match request height; expected: %d, got: %d", req.Height, voteExt.Height)
106123
}
107124

125+
if len(voteExt.Prices) == 0 {
126+
h.logger.Error("VerifyVoteExtensionHandler", "height", req.Height, "validator", validator, "Price", len(voteExt.Prices))
127+
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
128+
// return nil, fmt.Errorf("invalid price length %d", len(voteExt.Prices))
129+
}
130+
108131
// if len(voteExt.Prices) > 0 {
109132
// // check if a fack price is existing.
110133
// if _, ok := voteExt.Prices[types.NULL_SYMBOL]; !ok {
@@ -251,6 +274,21 @@ func (h *PriceOracleVoteExtHandler) PrepareProposal() sdk.PrepareProposalHandler
251274
return nil, errors.New("failed to encode injected vote extension tx")
252275
}
253276

277+
for _, vote := range extInfo.Votes {
278+
279+
if vote.BlockIdFlag == cmtproto.BlockIDFlagCommit {
280+
var voteExt types.OracleVoteExtension
281+
if err := voteExt.Unmarshal(vote.VoteExtension); err != nil {
282+
h.logger.Error("failed to decode vote extension", "err", err, "validator", fmt.Sprintf("%x", vote.Validator.Address))
283+
return nil, err
284+
}
285+
if len(voteExt.Prices) == 0 {
286+
h.logger.Error("Empty Oracle Prices")
287+
return nil, fmt.Errorf("invalid price length: 0")
288+
}
289+
}
290+
}
291+
254292
// Inject a "fake" tx into the proposal s.t. validators can decode, verify,
255293
// and store the canonical stake-weighted average prices and block headers.
256294
proposalTxs = append([][]byte{bz}, proposalTxs...)
@@ -265,6 +303,7 @@ func (h *PriceOracleVoteExtHandler) PrepareProposal() sdk.PrepareProposalHandler
265303

266304
func (h *PriceOracleVoteExtHandler) ProcessProposal() sdk.ProcessProposalHandler {
267305
return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
306+
268307
if !voteExtensionEnabled(ctx, req.Height) {
269308
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
270309
}
@@ -281,7 +320,21 @@ func (h *PriceOracleVoteExtHandler) ProcessProposal() sdk.ProcessProposalHandler
281320

282321
err := baseapp.ValidateVoteExtensions(ctx, h.valStore, req.Height, ctx.ChainID(), injectedVoteExtTx)
283322
if err != nil {
284-
return nil, err
323+
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
324+
}
325+
326+
for _, vote := range injectedVoteExtTx.Votes {
327+
328+
if vote.BlockIdFlag == cmtproto.BlockIDFlagCommit {
329+
var voteExt types.OracleVoteExtension
330+
if err := voteExt.Unmarshal(vote.VoteExtension); err != nil {
331+
h.logger.Error("failed to decode vote extension", "err", err, "validator", fmt.Sprintf("%x", vote.Validator.Address))
332+
return nil, err
333+
}
334+
if len(voteExt.Prices) == 0 {
335+
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
336+
}
337+
}
285338
}
286339

287340
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil

0 commit comments

Comments
 (0)