swh:1:snp:9c27352633c4639a943e316050a7b904f57900e2
Raw File
Tip revision: ceec6c00f379b59b559e56013c90995ae74e3190 authored by Philippe Wang on 08 November 2019, 05:35:13 UTC
Merge branch 'patch-9' into 'master'
Tip revision: ceec6c0
activate_protocol.sh
#! /bin/bash

set -e

usage="Usage:
$ ./scripts/activate_protocol.sh src/proto_004_PtDPBVyN
Inserts the protocol in the right files of the build system to compile it
If in master activates in addition to alpha.
If in mainnet activates in addition to its predecessor, here proto_003_PsddFKi3."

script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
cd "$script_dir"/..

if [ ! -d "$1" ]; then
    echo "$usage"
    exit 1
fi

is_mainnet () {
    # need to check a real file because of phantom git directories
    if [ -f "src/proto_000_Ps9mPmXa/lib_protocol/TEZOS_PROTOCOL" ]
    then return 0; else return 1; fi
}

new_version=$(basename $1 | awk -F'_' '{print $2}')
new_hash=$(basename $1 | awk -F'_' '{print $3}')
full_hash=$(jq .hash < $1/lib_protocol/TEZOS_PROTOCOL)
replacement=${new_version}-${new_hash}
if [[ -z "${new_version}" || -z "${new_hash}" || -z "${full_hash}" ]] ; then
    echo "$usage"
    exit 1
fi

# The pattern to look for, "alpha" for master or "00X-<hash>" for mainnet.
# Once found it's either replaced or the line is duplicated and then replaced
if is_mainnet
then
    old_version=$( printf '%03d' $(($new_version -1)) )
    old_dir=$(ls -d src/proto_${old_version}_*)
    old_hash=$(basename $old_dir | awk -F'_' '{print $3}')
    pattern=${old_version}-${old_hash}
else
    pattern="alpha"
fi

# if a line matches PATTERN, a new line is printed where the pattern is replaced
duplicate_and_replace() {
    PATTERN=$1
    REPLACEMENT=$2
    shift 2

    awk -i inplace '{
        print
        if ($0 ~ PATTERN) {
           sub(PATTERN,REPLACEMENT)
           print
        }}' PATTERN=$PATTERN REPLACEMENT=$REPLACEMENT $*
}

# the minimum needed, although you can't bake
duplicate_and_replace ${pattern} ${replacement} active_protocol_versions

# activate in client to bake and use RPCs
duplicate_and_replace -${pattern} -${replacement} \
    src/bin_client/{dune,tezos-client.opam}

read -p "Link in the Node? (no if you want to test injection) (Y/n) " ans
if [[ "$ans" == "Y" || "$ans" == "y" || -z "$ans" ]]; then
    duplicate_and_replace -${pattern} -${replacement} \
                          src/bin_node/{dune,tezos-node.opam}
    duplicate_and_replace -${pattern} -${replacement} \
                          src/bin_validation/{dune,tezos-validator.opam}
fi

read -p "User-activated update? (Y/n) " ans
if [[ "$ans" == "Y" || "$ans" == "y" || -z "$ans" ]]; then

    read -p "At what level? (e.g. 3 for sandbox): " level

    if [[ $level < 28082 ]]; then
        # we are testing in sandbox so we clean existing lines
        awk -i inplace '
        BEGIN{found=0}{
        if (!found && $0 ~ "let forced_protocol_upgrades")
          {found=1; print}
          else {
            if (found && $0 ~ "^]")
            {found=0; print }
            else
            { if (!found){print}}
           }}' src/lib_base/block_header.ml
    fi

    sed -i.old '/let forced_protocol_upgrades/ a \ \ '${level}'l, Protocol_hash.of_b58check_exn '${full_hash}' ;' \
        src/lib_base/block_header.ml
    rm src/lib_base/block_header.ml.old

    patch -p1 < scripts/yes-node.patch

    if ! [ -d yes-wallet ]; then
        dune utop src/lib_crypto scripts/yes-wallet.ml
        echo 'Created `yes-wallet` directory.'
    fi
fi
back to top