Skip to content

Commit

Permalink
Merge branch 'master' into fix/getmasternodeblocks-depth
Browse files Browse the repository at this point in the history
  • Loading branch information
dcorral authored Dec 7, 2021
2 parents 334ee3b + 639e8db commit 23a66e8
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 29 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/hotfix-builds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Hotfix Build

on:
push:
branches:
- hotfix

jobs:

linux:
runs-on: ubuntu-18.04
env:
BUILD_VERSION: latest # Computed

steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f

- name: Build and package
run: ./make.sh docker-release-git

- name: Publish artifacts
uses: actions/upload-artifact@e448a9b857ee2131e752b06002bf0e093c65e571
with:
name: defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu
path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu.tar.gz

# Linux build additionally pushes the docker images to docker hub on successful build
- name: Tag dockerhub build
if: ${{ github.repository == 'DeFiCh/ain' }}
run: >
docker tag defichain-x86_64-pc-linux-gnu:${{ env.BUILD_VERSION }}
defichain-x86_64-pc-linux-gnu:dockerhub-latest
- uses: docker/build-push-action@3e7a4f6646880c6f63758d73ac32392d323eaf8f
# Make sure to only build on ain repo. Also add in additional restrictions here if needed to
# make sure we don't push unnecessary images to docker
if: ${{ github.repository == 'DeFiCh/ain' }}
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
path: ./contrib/dockerfiles/dockerhub
dockerfile: ./contrib/dockerfiles/dockerhub/x86_64-pc-linux-gnu.dockerfile
repository: defi/defichain
tags: ${{ env.BUILD_VERSION }}

windows:
runs-on: ubuntu-18.04
env:
BUILD_VERSION: latest # Computed

steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f

- name: Build and package
run: TARGETS="x86_64-w64-mingw32" ./make.sh docker-release-git

- name: Publish artifact - x86_64-w64-mingw32
uses: actions/upload-artifact@e448a9b857ee2131e752b06002bf0e093c65e571
with:
name: defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32
path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.tar.gz

macos:
runs-on: ubuntu-18.04
env:
BUILD_VERSION: latest # Computed

steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f

- name: Build and package
run: TARGETS="x86_64-apple-darwin11" ./make.sh docker-release-git

- name: Publish artifact - x86_64-apple-darwin11
uses: actions/upload-artifact@e448a9b857ee2131e752b06002bf0e093c65e571
with:
name: defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11
path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11.tar.gz
2 changes: 1 addition & 1 deletion contrib/dockerfiles/arm-linux-gnueabihf.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt update && apt dist-upgrade -y
# Setup DeFiChain build dependencies. Refer to depends/README.md and doc/build-unix.md
# from the source root for info on the builder setup

RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
RUN apt install -y software-properties-common build-essential git libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev \
Expand Down
2 changes: 1 addition & 1 deletion contrib/dockerfiles/x86_64-apple-darwin11.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt update && apt dist-upgrade -y
# Setup DeFiChain build dependencies. Refer to depends/README.md and doc/build-unix.md
# from the source root for info on the builder setup

RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
RUN apt install -y software-properties-common build-essential git libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev \
Expand Down
2 changes: 1 addition & 1 deletion contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apt update && apt dist-upgrade -y

RUN apt-get install -y apt-transport-https

RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
RUN apt install -y software-properties-common build-essential git libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev wget \
Expand Down
2 changes: 1 addition & 1 deletion contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt update && apt dist-upgrade -y
# Setup DeFiChain build dependencies. Refer to depends/README.md and doc/build-unix.md
# from the source root for info on the builder setup

RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
RUN apt install -y software-properties-common build-essential git libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev \
Expand Down
21 changes: 19 additions & 2 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ build_prepare() {
popd >/dev/null
./autogen.sh
# XREF: #make-configure
# ./configure CC=clang-11 CXX=clang++-11 --prefix="$(pwd)/depends/x86_64-pc-linux-gnu"
./configure CC=clang-11 CXX=clang++-11 --prefix="$(pwd)/depends/${target}" ${extra_conf_opts}
}

Expand Down Expand Up @@ -312,9 +313,20 @@ git_version() {
current_commit=$(git rev-parse --short HEAD)
current_branch=$(git rev-parse --abbrev-ref HEAD)

if [[ -z $current_tag ]]; then
if [[ -z $current_tag || "${current_branch}" == "hotfix" ]]; then
# Replace `/` in branch names with `-` as / is trouble
IMAGE_VERSION="${current_branch//\//-}-${current_commit}"
if [[ "${current_branch}" == "hotfix" ]]; then
# If the current branch is hotfix branch,
# prefix it with the last available tag.
git fetch --tags
local last_tag
last_tag="$(git describe --tags $(git rev-list --tags --max-count=1))"
echo "> last tag: ${last_tag}"
if [[ -n "${last_tag}" ]]; then
IMAGE_VERSION="${last_tag}-${IMAGE_VERSION}"
fi
fi
else
IMAGE_VERSION="${current_tag}"
# strip the 'v' infront of version tags
Expand All @@ -323,8 +335,13 @@ git_version() {
fi
fi

echo "> git branch: ${current_branch}"
echo "> version: ${IMAGE_VERSION}"
echo "BUILD_VERSION=${IMAGE_VERSION}" >> $GITHUB_ENV # GitHub Actions

if [[ -n "${GITHUB_ACTIONS-}" ]]; then
# GitHub Actions
echo "BUILD_VERSION=${IMAGE_VERSION}" >> $GITHUB_ENV
fi
}

pkg_install_deps() {
Expand Down
21 changes: 19 additions & 2 deletions share/genbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ git_check_in_repo() {

DESC=""
SUFFIX=""
CURRENT_BRANCH=""
if [ "${BITCOIN_GENBUILD_NO_GIT}" != "1" ] && [ -e "$(command -v git)" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] && git_check_in_repo share/genbuild.sh; then
# clean 'dirty' status of touched files that haven't been modified
git diff >/dev/null 2>/dev/null
Expand All @@ -34,11 +35,27 @@ if [ "${BITCOIN_GENBUILD_NO_GIT}" != "1" ] && [ -e "$(command -v git)" ] && [ "$
git diff-index --quiet HEAD -- && DESC=$RAWDESC
fi

# otherwise generate suffix from git, i.e. string like "59887e8-dirty"
SUFFIX=$(git rev-parse --short HEAD)
git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
# Move to this after git upgrade from base images
# CURRENT_BRANCH="$(git branch --show-current)"

if [ -n "$CURRENT_BRANCH" ]; then
# Make sure to replace `/` with `-`. Since this is
# executed with posix shell, cannot do bashisms.
SUFFIX="$(echo $CURRENT_BRANCH | sed 's/\//-/g')-$SUFFIX"
fi

if [ "$CURRENT_BRANCH" != "hotfix" ]; then
# if it's hotfix branch, don't mark dirty.
# otherwise generate suffix from git, i.e. string like "59887e8-dirty".
git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
fi
fi

echo "BUILD_GIT_BRANCH: $CURRENT_BRANCH"
echo "BUILD_SUFFIX: $SUFFIX"

if [ -n "$DESC" ]; then
NEWINFO="#define BUILD_DESC \"$DESC\""
elif [ -n "$SUFFIX" ]; then
Expand Down
4 changes: 0 additions & 4 deletions src/test/blockencodings_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
CBlock block(BuildBlockTestCase());

LOCK2(cs_main, pool.cs);
block.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash();
pool.addUnchecked(entry.FromTx(block.vtx[2]));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);

Expand Down Expand Up @@ -145,7 +144,6 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
BOOST_CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated));

CBlock block3;
block3.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash();
BOOST_CHECK(partialBlock.FillBlock(block3, {block.vtx[1]}) == READ_STATUS_OK);
BOOST_CHECK_EQUAL(block.GetHash().ToString(), block3.GetHash().ToString());
BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block3, &mutated).ToString());
Expand Down Expand Up @@ -274,7 +272,6 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
CBlock block(BuildBlockTestCase());

LOCK2(cs_main, pool.cs);
block.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash();
pool.addUnchecked(entry.FromTx(block.vtx[1]));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);

Expand Down Expand Up @@ -304,7 +301,6 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);

CBlock block2;
block2.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash();
PartiallyDownloadedBlock partialBlockCopy = partialBlock;
BOOST_CHECK(partialBlock.FillBlock(block2, {}) == READ_STATUS_OK);
BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString());
Expand Down
25 changes: 8 additions & 17 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4526,24 +4526,15 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
if (block.fChecked)
return true;

// Create block copy with height based on hashPrevBlock
auto newBlock = block;
const auto pindexPrev = LookupBlockIndex(block.hashPrevBlock);
if (!pindexPrev && block.GetHash() != consensusParams.hashGenesisBlock) {
return state.Invalid(ValidationInvalidReason::BLOCK_MISSING_PREV, error("%s: prev block not found", __func__), 0, "prev-blk-not-found");
}
const int height = pindexPrev ? pindexPrev->nHeight + 1 : 0;
newBlock.height = height;

// Check that the header is valid (particularly PoW). This is mostly
// redundant with the call in AcceptBlockHeader.
if (!fIsFakeNet && fCheckPOS && !pos::ContextualCheckProofOfStake(newBlock, consensusParams, pcustomcsview.get(), ctxState))
if (!fIsFakeNet && fCheckPOS && !pos::ContextualCheckProofOfStake(block, consensusParams, pcustomcsview.get(), ctxState))
return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, false, REJECT_INVALID, "high-hash", "proof of stake failed");

// Check the merkle root.
// block merkle root is delayed to ConnectBlock to ensure account changes
if (fCheckMerkleRoot && (height < consensusParams.EunosHeight
|| height >= consensusParams.EunosKampungHeight)) {
if (fCheckMerkleRoot && (block.height < consensusParams.EunosHeight
|| block.height >= consensusParams.EunosKampungHeight)) {
bool mutated;
uint256 hashMerkleRoot2 = BlockMerkleRoot(block, &mutated);
if (block.hashMerkleRoot != hashMerkleRoot2)
Expand Down Expand Up @@ -4575,8 +4566,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
TBytes dummy;
for (unsigned int i = 1; i < block.vtx.size(); i++) {
if (block.vtx[i]->IsCoinBase() &&
!IsAnchorRewardTx(*block.vtx[i], dummy, height >= consensusParams.FortCanningHeight) &&
!IsAnchorRewardTxPlus(*block.vtx[i], dummy, height >= consensusParams.FortCanningHeight))
!IsAnchorRewardTx(*block.vtx[i], dummy, block.height >= consensusParams.FortCanningHeight) &&
!IsAnchorRewardTxPlus(*block.vtx[i], dummy, block.height >= consensusParams.FortCanningHeight))
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-cb-multiple", "more than one coinbase");
}
}
Expand All @@ -4590,7 +4581,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage()));
}

if (!fIsFakeNet && fCheckPOS && height >= consensusParams.FortCanningHeight) {
if (!fIsFakeNet && fCheckPOS && block.height >= consensusParams.FortCanningHeight) {
CKeyID minter;
// this is safe cause pos::ContextualCheckProofOfStake checked
block.ExtractMinterKey(minter);
Expand Down Expand Up @@ -4715,15 +4706,15 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, false, REJECT_INVALID, "time-too-old", strprintf("block's timestamp is too early. Block time: %d Min time: %d", block.GetBlockTime(), pindexPrev->GetMedianTimePast()));

// Check timestamp
if (Params().NetworkIDString() != CBaseChainParams::REGTEST && nHeight >= static_cast<uint64_t>(consensusParams.EunosPayaHeight)) {
if (Params().NetworkIDString() != CBaseChainParams::REGTEST && block.height >= static_cast<uint64_t>(consensusParams.EunosPayaHeight)) {
if (block.GetBlockTime() > GetTime() + MAX_FUTURE_BLOCK_TIME_EUNOSPAYA)
return state.Invalid(ValidationInvalidReason::BLOCK_TIME_FUTURE, false, REJECT_INVALID, "time-too-new", strprintf("block timestamp too far in the future. Block time: %d Max time: %d", block.GetBlockTime(), GetTime() + MAX_FUTURE_BLOCK_TIME_EUNOSPAYA));
}

if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME)
return state.Invalid(ValidationInvalidReason::BLOCK_TIME_FUTURE, false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future");

if (nHeight >= static_cast<uint64_t>(consensusParams.DakotaCrescentHeight)) {
if (block.height >= static_cast<uint64_t>(consensusParams.DakotaCrescentHeight)) {
if (block.GetBlockTime() > GetTime() + MAX_FUTURE_BLOCK_TIME_DAKOTACRESCENT)
return state.Invalid(ValidationInvalidReason::BLOCK_TIME_FUTURE, false, REJECT_INVALID, "time-too-new", strprintf("block timestamp too far in the future. Block time: %d Max time: %d", block.GetBlockTime(), GetTime() + MAX_FUTURE_BLOCK_TIME_DAKOTACRESCENT));
}
Expand Down

0 comments on commit 23a66e8

Please sign in to comment.