Skip to content

Commit

Permalink
Merge pull request #4 from oraichain/feat/emit-batch-txs-ids
Browse files Browse the repository at this point in the history
Feat/emit batch txs ids
  • Loading branch information
ducphamle2 authored Mar 28, 2024
2 parents ec8596d + 7289536 commit 20adc25
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 39 deletions.
8 changes: 7 additions & 1 deletion docs/developer/environment-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ npm run test

Change directory into the `Gravity-Bridge/module` folder and run

```
```bash
# Installing the protobuf tooling
sudo make proto-tools

Expand All @@ -92,7 +92,13 @@ go install github.com/grpc-ecosystem/grpc-gateway/[email protected].
go get github.com/grpc-ecosystem/grpc-gateway/[email protected]
```

For MacOS, we need to install buf as well

```bash
brew install bufbuild/buf/buf
```

```bash
# generate new protobuf files from the definitions, this makes sure the previous instructions worked
# you will need to run this any time you change a proto file
make proto-gen
Expand Down
9 changes: 4 additions & 5 deletions module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ make proto-gen

## Test

go test ./x/gravity/migrations/v2/... -v --count=1

go test ./x/gravity/migrations/v3/... -v --count=1

go test ./x/gravity/keeper/... -v --count=1
go test ./x/gravity/migrations/v3/... -v --count=1 | grep FAIL
go test ./x/gravity/keeper/... -v --count=1 | grep FAIL
go test ./x/gravity/... -v --count=1 | grep FAIL
go test ./x/gravity/types/... -v --count=1 | grep FAIL

## Update swagger

Expand Down
11 changes: 5 additions & 6 deletions module/app/upgrades/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"

"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/singlestep"
)

// RegisterUpgradeHandlers registers handlers for all upgrades
Expand Down Expand Up @@ -67,8 +65,9 @@ func RegisterUpgradeHandlers(
// tron.PlanName,
// tron.GetTronUpgradeHandler(mm, configurator, crisisKeeper),
// )
upgradeKeeper.SetUpgradeHandler(
singlestep.PlanName,
singlestep.GetUpgradeHandler(mm, configurator, crisisKeeper),
)

// upgradeKeeper.SetUpgradeHandler(
// singlestep.PlanName,
// singlestep.GetUpgradeHandler(mm, configurator, crisisKeeper),
// )
}
36 changes: 18 additions & 18 deletions module/proto/gravity/v1/batch.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ option go_package = "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/t

// OutgoingTxBatch represents a batch of transactions going from gravity to ETH
message OutgoingTxBatch {
uint64 batch_nonce = 1;
uint64 batch_timeout = 2;
repeated OutgoingTransferTx transactions = 3 [(gogoproto.nullable) = false];
string token_contract = 4;
uint64 cosmos_block_created = 5;
uint64 batch_nonce = 1;
uint64 batch_timeout = 2;
repeated OutgoingTransferTx transactions = 3 [ (gogoproto.nullable) = false ];
string token_contract = 4;
uint64 cosmos_block_created = 5;
}

// OutgoingTransferTx represents an individual send from gravity to ETH
message OutgoingTransferTx {
uint64 id = 1;
string sender = 2;
string dest_address = 3;
ERC20Token erc20_token = 4 [(gogoproto.nullable) = false];
ERC20Token erc20_fee = 5 [(gogoproto.nullable) = false];
uint64 id = 1;
string sender = 2;
string dest_address = 3;
ERC20Token erc20_token = 4 [ (gogoproto.nullable) = false ];
ERC20Token erc20_fee = 5 [ (gogoproto.nullable) = false ];
}

// OutgoingLogicCall represents an individual logic call from gravity to ETH
message OutgoingLogicCall {
repeated ERC20Token transfers = 1 [(gogoproto.nullable) = false];
repeated ERC20Token fees = 2 [(gogoproto.nullable) = false];
string logic_contract_address = 3;
bytes payload = 4;
uint64 timeout = 5;
bytes invalidation_id = 6;
uint64 invalidation_nonce = 7;
uint64 cosmos_block_created = 8;
repeated ERC20Token transfers = 1 [ (gogoproto.nullable) = false ];
repeated ERC20Token fees = 2 [ (gogoproto.nullable) = false ];
string logic_contract_address = 3;
bytes payload = 4;
uint64 timeout = 5;
bytes invalidation_id = 6;
uint64 invalidation_nonce = 7;
uint64 cosmos_block_created = 8;
}

message EventOutgoingBatchCanceled {
Expand Down
112 changes: 112 additions & 0 deletions module/scripts/e2e/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
set -ux

# setup the network using the old binary

OLD_VERSION=${OLD_VERSION:-"v1.0.3"}
ARGS="--chain-id testing -y --keyring-backend test --fees 200uoraib --gas auto --gas-adjustment 1.5 -b block"
NEW_VERSION=${NEW_VERSION:-"txidevent"}
VALIDATOR_HOME=${VALIDATOR_HOME:-"$HOME/.gravity/validator1"}

# kill all running binaries
pkill gravity && sleep 2

# download current production binary
current_dir=$PWD
rm -rf ../../gravity-bridge-old/ && git clone https://github.com/Oraichain/Gravity-Bridge.git ../../gravity-bridge-old/ && cd ../../gravity-bridge-old/module && git checkout $OLD_VERSION && go mod tidy && make install

cd $current_dir

# setup local network
sh $PWD/scripts/multi_local_node.sh

# test send from cosmos to eth
gravity tx gravity send-to-eth 0x0000000000000000000000000000000000071001 12500000000000000000oraib0x0000000000000000000000000000000000C0FFEE 1000000000000000000oraib0x0000000000000000000000000000000000C0FFEE 2500000000000000oraib0x0000000000000000000000000000000000C0FFEE oraib --fees 10uoraib --from orchestrator1 --chain-id testing --home $HOME/.gravity/validator1 --keyring-backend test -y -b block

# test send request batch, can not set this on because client cli of this request-batch
# at v1.0.3 version is wrong format
# gravity tx gravity request-batch oraib0x0000000000000000000000000000000000C0FFEE oraib --fees 10uoraib --from orchestrator1 --chain-id testing --home $HOME/.gravity/validator1 --keyring-backend test -y

# create new upgrade proposal, turn this on when we need real proposal
# UPGRADE_HEIGHT=${UPGRADE_HEIGHT:-19}
# gravity tx gov submit-proposal software-upgrade $NEW_VERSION --title "foobar" --description "foobar" --from validator1 --upgrade-height $UPGRADE_HEIGHT --upgrade-info "x" --deposit 10000000uoraib $ARGS --home $VALIDATOR_HOME
# gravity tx gov vote 1 yes --from validator1 --home "$HOME/.gravity/validator1" $ARGS && gravity tx gov vote 1 yes --from validator2 --home "$HOME/.gravity/validator2" $ARGS

# # sleep to wait til the proposal passes
# echo "Sleep til the proposal passes..."
# sleep 12

# # Check if latest height is less than the upgrade height
# latest_height=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')
# while [ $latest_height -lt $UPGRADE_HEIGHT ];
# do
# sleep 5
# ((latest_height=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')))
# echo $latest_height
# done

# kill all processes
pkill gravity

# install new binary for the upgrade
echo "install new binary"
make install

# re-run all validators. All should run
screen -S validator1 -d -m gravity start --home=$HOME/.gravity/validator1 --minimum-gas-prices=0.00001uoraib
screen -S validator2 -d -m gravity start --home=$HOME/.gravity/validator2 --minimum-gas-prices=0.00001uoraib
screen -S validator3 -d -m gravity start --home=$HOME/.gravity/validator3 --minimum-gas-prices=0.00001uoraib

# sleep a bit for the network to start
echo "Sleep to wait for the network to start..."
sleep 10

# test send from cosmos to eth
gravity tx gravity send-to-eth 0x0000000000000000000000000000000000071001 12500000000000000000oraib0x0000000000000000000000000000000000C0FFEE 1000000000000000000oraib0x0000000000000000000000000000000000C0FFEE 2500000000000000oraib0x0000000000000000000000000000000000C0FFEE oraib --fees 10000uoraib --from orchestrator1 --chain-id testing --home $HOME/.gravity/validator1 --keyring-backend test -y -b block --gas 400000000

# total of 3 tx ids
gravity tx gravity send-to-eth 0x0000000000000000000000000000000000071001 12500000000000000000oraib0x0000000000000000000000000000000000C0FFEE 1000000000000000000oraib0x0000000000000000000000000000000000C0FFEE 2500000000000000oraib0x0000000000000000000000000000000000C0FFEE oraib --fees 10000uoraib --from orchestrator1 --chain-id testing --home $HOME/.gravity/validator1 --keyring-backend test -y -b block --gas 400000000

# test send request batch
txhash=$(gravity tx gravity request-batch oraib0x0000000000000000000000000000000000C0FFEE oraib --fees 10000uoraib --gas 400000000 --from orchestrator1 --chain-id testing --home $HOME/.gravity/validator1 --keyring-backend test -y | grep -o 'txhash: [^ ]*' | awk '{print $2}')

echo "Wait 10s for tx $txhash is executed on blockchain..."
sleep 10
echo "$(curl -s "http://127.0.0.1:26657/tx?hash=0x$txhash&prove=true" | jq -r '.result.tx_result.log')" | grep -q "batched_tx_ids"
if echo "$(curl -s "http://127.0.0.1:26657/tx?hash=0x$txhash&prove=true" | jq -r '.result.tx_result.log')" | grep -q "batched_tx_ids"
then
echo "Testcase success, batched_tx_ids already exist on event"
else
echo "Testcase failed, batched_tx_ids does not exist on event"
exit 1
fi

height_before=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')

re='^[0-9]+([.][0-9]+)?$'
if ! [[ $height_before =~ $re ]] ; then
echo "error: Not a number" >&2; exit 1
fi

sleep 30

height_after=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')

height_after=$(curl --no-progress-meter http://localhost:1317/blocks/latest | jq '.block.header.height | tonumber')

if ! [[ $height_after =~ $re ]] ; then
echo "error: Not a number" >&2; exit 1
fi

if [ $height_after -gt $height_before ]
then
echo "Test Passed"
else
echo "Test Failed"
fi

inflation=$(curl --no-progress-meter http://localhost:1317/cosmos/mint/v1beta1/inflation | jq '.inflation | tonumber')
if ! [[ $inflation =~ $re ]] ; then
echo "Error: Cannot query inflation => Potentially missing Go GRPC backport" >&2;
echo "Tests Failed"; exit 1
fi
Loading

0 comments on commit 20adc25

Please sign in to comment.