Skip to content

Commit

Permalink
Merged dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Aug 19, 2024
2 parents 0877781 + fcc64a5 commit cc9c883
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 506 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Suibase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- New VSCode extension https://marketplace.visualstudio.com/items?itemName=suibase.suibase

### Fixed
- "lsui/dsui/tsui client faucet" commands now work.
- More robust handling of backend (suibase-daemon)
- Reduce localnet storage need (delete full_node_db on regen).

Expand Down
4 changes: 2 additions & 2 deletions repair
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ suibase_repair() {
if [ -z "$SUIBASE_DAEMON_VERSION_FILE" ]; then
# shellcheck source=SCRIPTDIR/scripts/common/__suibase-daemon.sh
source "$REPAIR_SB_DIR/scripts/common/__suibase-daemon.sh"
update_suibase_daemon_as_needed
start_suibase_daemon_as_needed
fi

if [ -z "$DTP_DAEMON_VERSION_FILE" ]; then
# shellcheck source=SCRIPTDIR/scripts/common/__dtp-daemon.sh
source "$REPAIR_SB_DIR/scripts/common/__dtp-daemon.sh"
update_dtp_daemon_as_needed
start_dtp_daemon_as_needed
fi

# Exit instruction to the user.
Expand Down
25 changes: 14 additions & 11 deletions restart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Source '__globals.sh'.
SUIBASE_DIR="$HOME/suibase"
SCRIPT_COMMON_CALLER="$(readlink -f "$0")"
WORKDIR="localnet"
WORKDIR="none"

main() {
# Detect if suibase is not installed!
Expand All @@ -27,16 +27,19 @@ main() {
exit_if_deps_missing

# Block users from running any concurrent CLI commands.
cli_mutex_lock "localnet"
cli_mutex_lock "mainnet"
cli_mutex_lock "devnet"
cli_mutex_lock "testnet"
cli_mutex_lock "cargobin"
cli_mutex_lock "active"

restart_suibase_daemon
# Check for any JSON-RPC up, except for localnet.
wait_for_json_rpc_up "exclude-localnet"
cli_mutex_lock "suibase_daemon"


update_SUIBASE_DAEMON_PID_var

local _OLD_PID=$SUIBASE_DAEMON_PID
start_suibase_daemon_as_needed

if [ "$_OLD_PID" == "$SUIBASE_DAEMON_PID" ]; then
restart_suibase_daemon
# Check for any JSON-RPC up, except for localnet.
wait_for_json_rpc_up "exclude-localnet"
fi
}

main "$@"
53 changes: 41 additions & 12 deletions scripts/common/__globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,33 @@ export SUIBASE_CLI_LOCK_ACQUIRED_TESTNET=0
export SUIBASE_CLI_LOCK_ACQUIRED_MAINNET=0
export SUIBASE_CLI_LOCK_ACQUIRED_CARGOBIN=0
export SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE=0
export SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON=0
export SUIBASE_CLI_LOCK_DISABLED=0

# Disable CLI mutex mechanism.
#
# Useful for when a script is called by a script that already acquired the necessary lock.
# In that case, the child script should not use any of the mutex.
cli_mutex_disable() {
SUIBASE_CLI_LOCK_DISABLED=1
}
export -f cli_mutex_disable

# Allow to disable a lock. Used for
cleanup() {
# echo "Cleanup called"
# Clear progress files created by this script.
if [ "$SUIBASE_DAEMON_UPGRADING" == "1" ]; then
if [ "$SUIBASE_DAEMON_UPGRADING" == "true" ]; then
rm -f /tmp/.suibase/suibase-daemon-upgrading >/dev/null 2>&1
fi

# Associative arrays are not working for the trap. bash limitation?
# Did workaround by painfully defining variables for each workdir.
if [ "$SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE" == "1" ]; then
cli_mutex_release "active"
SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE=0
fi

if [ "$SUIBASE_CLI_LOCK_ACQUIRED_LOCALNET" == "1" ]; then
cli_mutex_release "localnet"
SUIBASE_CLI_LOCK_ACQUIRED_LOCALNET=0
Expand All @@ -190,11 +207,10 @@ cleanup() {
SUIBASE_CLI_LOCK_ACQUIRED_CARGOBIN=0
fi

if [ "$SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE" == "1" ]; then
cli_mutex_release "active"
SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE=0
if [ "$SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON" == "1" ]; then
cli_mutex_release "suibase_daemon"
SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON=0
fi

}

# Add color
Expand Down Expand Up @@ -384,8 +400,7 @@ try_locked_command() {
export -f try_locked_command


cli_mutex_lock()
{
cli_mutex_lock() {
# mutex is re-entrant (only first call to cli_mutex_lock will acquire the lock).

# Design choice:
Expand All @@ -404,6 +419,10 @@ cli_mutex_lock()
#
# Worst case, because the lock is in /tmp, a stale lock can be workaround with a reboot...

if [ "$SUIBASE_CLI_LOCK_DISABLED" == "1" ]; then
return
fi

local _WORKDIR=$1

if [ -z "$_WORKDIR" ]; then
Expand Down Expand Up @@ -433,6 +452,9 @@ cli_mutex_lock()
active)
_IS_ACQUIRED=$SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE
;;
suibase_daemon)
_IS_ACQUIRED=$SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON
;;
*)
setup_error "Internal error. cli_mutex_lock called with an unknown workdir $_WORKDIR"
;;
Expand Down Expand Up @@ -467,12 +489,13 @@ cli_mutex_lock()
active)
SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE=1
;;
suibase_daemon)
SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON=1
;;
*)
setup_error "Internal error. cli_mutex_lock called with an unknown workdir $_WORKDIR"
;;
esac

# echo "Lock acquired for $_WORKDIR"
}
export -f cli_mutex_lock

Expand Down Expand Up @@ -506,8 +529,11 @@ cli_mutex_release()
active)
_IS_ACQUIRED=$SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE
;;
suibase_daemon)
_IS_ACQUIRED=$SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON
;;
*)
setup_error "Internal error. cli_mutex_lock called with an unknown workdir $_WORKDIR"
setup_error "Internal error. cli_mutex_release called with an unknown workdir $_WORKDIR"
;;
esac
if [ "$_IS_ACQUIRED" == "0" ]; then
Expand Down Expand Up @@ -537,6 +563,9 @@ cli_mutex_release()
active)
SUIBASE_CLI_LOCK_ACQUIRED_ACTIVE=0
;;
suibase_daemon)
SUIBASE_CLI_LOCK_ACQUIRED_SUIBASE_DAEMON=0
;;
esac

#echo "Lock released for $_WORKDIR"
Expand Down Expand Up @@ -3327,9 +3356,9 @@ has_param() {
}
export -f has_param

export SUIBASE_DAEMON_UPGRADING=0
export SUIBASE_DAEMON_UPGRADING=false
progress_suibase_daemon_upgrading() {
SUIBASE_DAEMON_UPGRADING=1
SUIBASE_DAEMON_UPGRADING=true
mkdir -p "$SUIBASE_TMP_DIR"
touch "$SUIBASE_TMP_DIR/suibase-daemon-upgrading"
}
Expand Down
18 changes: 17 additions & 1 deletion scripts/common/__sui-exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ sui_exec() {
# does not specify path (and default to current dir).
local _OPT_DEFAULT_PATH=""
local _OPT_DEFAULT_INSTALLDIR=""
local _OPT_URL_PARAM=""

if [[ $SUI_SUBCOMMAND == "client" ]]; then
case $1 in
publish | verify-source | verify-bytecode-meter | upgrade)
Expand All @@ -158,6 +160,20 @@ sui_exec() {
_OPT_DEFAULT_INSTALLDIR="--install-dir $USER_CWD"
fi
;;
faucet)
if ! has_param "" "--url" "$@"; then
if [ "$WORKDIR" = "localnet" ]; then
if [ "${CFG_sui_faucet_enabled:?}" != "true" ]; then
error_exit "suibase faucet not enabled for localnet. Check suibase.yaml config."
fi
_OPT_URL_PARAM="--url http://${CFG_sui_faucet_host_ip:?}:${CFG_sui_faucet_port:?}/gas"
elif [ "$WORKDIR" = "devnet" ] || [ "$WORKDIR" = "testnet" ]; then
_OPT_URL_PARAM="--url https://faucet.${WORKDIR}.sui.io/gas"
else
error_exit "faucet command not applicable to $WORKDIR"
fi
fi
;;
*) ;; # Do nothing
esac
fi
Expand All @@ -166,7 +182,7 @@ sui_exec() {
update_CANONICAL_ARGS_var "$@"

# shellcheck disable=SC2086,SC2068
$SUI_BIN "$SUI_SUBCOMMAND" --client.config "$CLIENT_CONFIG" ${CANONICAL_ARGS[@]} $_OPT_DEFAULT_INSTALLDIR $_OPT_DEFAULT_PATH
$SUI_BIN "$SUI_SUBCOMMAND" --client.config "$CLIENT_CONFIG" ${CANONICAL_ARGS[@]} $_OPT_DEFAULT_INSTALLDIR $_OPT_URL_PARAM $_OPT_DEFAULT_PATH

if [ "$WORKDIR" = "localnet" ]; then
# Print a friendly warning if localnet sui process found not running.
Expand Down
Loading

0 comments on commit cc9c883

Please sign in to comment.