Skip to content

Commit

Permalink
Merge branch 'master' into 1.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Aug 7, 2021
2 parents e88ca8a + e23fb88 commit ead30df
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions contrib/dockerfiles/arm-linux-gnueabihf.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LABEL org.defichain.arch=${TARGET}
WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)

# -----------
FROM builder-base as builder
Expand All @@ -53,7 +53,7 @@ RUN ./configure --prefix=`pwd`/depends/${TARGET} \

ARG BUILD_VERSION=

RUN make
RUN make -j $(nproc)
RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.

# -----------
Expand Down
4 changes: 2 additions & 2 deletions contrib/dockerfiles/x86_64-apple-darwin11.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LABEL org.defichain.arch=${TARGET}
WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)

# -----------
FROM builder-base as builder
Expand All @@ -50,7 +50,7 @@ RUN ./configure --prefix=`pwd`/depends/${TARGET}

ARG BUILD_VERSION=

RUN make
RUN make -j $(nproc)
RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.

# -----------
Expand Down
4 changes: 2 additions & 2 deletions contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LABEL org.defichain.arch=${TARGET}
WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)

# -----------
FROM builder-base as builder
Expand All @@ -56,7 +56,7 @@ RUN ./configure CC=clang-11 CXX=clang++-11 --prefix=`pwd`/depends/${TARGET}

ARG BUILD_VERSION=

RUN make
RUN make -j $(nproc)
RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.

# -----------
Expand Down
4 changes: 2 additions & 2 deletions contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LABEL org.defichain.arch=${TARGET}
WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)

# -----------
FROM builder-base as builder
Expand All @@ -53,7 +53,7 @@ RUN CONFIG_SITE=`pwd`/depends/x86_64-w64-mingw32/share/config.site ./configure -

ARG BUILD_VERSION=

RUN make
RUN make -j $(nproc)
RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.

# -----------
Expand Down
8 changes: 8 additions & 0 deletions src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,11 @@ bool IsValidDestinationString(const std::string& str)
{
return IsValidDestinationString(str, Params());
}

CKeyID getCKeyIDFromDestination(const CTxDestination& dest) {
switch (dest.which()) {
case PKHashType : return CKeyID(*boost::get<PKHash>(&dest));
case WitV0KeyHashType : return CKeyID(*boost::get<WitnessV0KeyHash>(&dest));
default : return CKeyID();
}
}
2 changes: 2 additions & 0 deletions src/key_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
bool IsValidDestinationString(const std::string& str);
bool IsValidDestinationString(const std::string& str, const CChainParams& params);

CKeyID getCKeyIDFromDestination(const CTxDestination& dest);

#endif // DEFI_KEY_IO_H
22 changes: 16 additions & 6 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,23 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
}

auto myIDs = pcustomcsview->AmIOperator();
if (!myIDs) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: I am not masternode operator");
CKeyID passedID = getCKeyIDFromDestination(destination);

auto myAllMNs = pcustomcsview->GetOperatorsMulti();
if (myAllMNs.empty()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: I am not masternode operator");
}

CScript coinbase_script = GetScriptForDestination(destination);
CKeyID operatorID;
auto mnForPassedID = pcustomcsview->GetMasternodeIdByOperator(passedID);
// check mnForPassedID is in myAllMNs
if (mnForPassedID && myAllMNs.count(std::make_pair(passedID, *mnForPassedID))) {
operatorID = passedID;
} else {
operatorID = myAllMNs.begin()->first;
}

CScript coinbase_script = GetScriptForDestination(destination);
CKey minterKey;
{
std::vector<std::shared_ptr<CWallet>> wallets = GetWallets();
Expand All @@ -205,7 +215,7 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)

bool found =false;
for (auto&& wallet : wallets) {
if (wallet->GetKey(myIDs->first, minterKey)) {
if (wallet->GetKey(operatorID, minterKey)) {
found = true;
break;
}
Expand All @@ -214,7 +224,7 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: masternode operator private key not found");

}
return generateBlocks(coinbase_script, minterKey, myIDs->first, nGenerate, nMaxTries);
return generateBlocks(coinbase_script, minterKey, operatorID, nGenerate, nMaxTries);
}

// Returns the mining information of all local masternodes
Expand Down
12 changes: 9 additions & 3 deletions test/functional/rpc_getmininginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from test_framework.test_framework import DefiTestFramework
from test_framework.util import (
assert_equal,
assert_greater_than,
connect_nodes_bi,
)

Expand All @@ -32,16 +33,17 @@ def run_test(self):
operators = [node0_keys.operatorAuthAddress, node1_keys.operatorAuthAddress]

self.log.info("Restart nodes...")
self.restart_node(0, ['-gen', '-masternode_operator=' + operators[0]])
self.restart_node(1, ['-gen', '-rewardaddress=' + operators[1]] +
self.restart_node(0, ['-gen', '-dummypos=0', '-masternode_operator=' + operators[0]])
self.restart_node(1, ['-gen', '-dummypos=0', '-rewardaddress=' + operators[1]] +
['-masternode_operator=' + x for x in operators])

connect_nodes_bi(self.nodes, 0, 1)

self.log.info("Mining blocks ...")
self.nodes[0].generate(10)
self.sync_all()
self.nodes[1].generate(50)
self.nodes[1].generate(25)
self.nodes[1].generatetoaddress(25, node0_keys.operatorAuthAddress)
self.sync_all()

# getmininginfo() on node[0], should only return one master node in the response array
Expand All @@ -50,17 +52,21 @@ def run_test(self):
assert_equal(resp0['masternodes'][0]['state'], "ENABLED")
assert_equal(resp0['masternodes'][0]['generate'], True)
assert_equal(resp0['masternodes'][0]['lastblockcreationattempt'] != "0", True)
assert_greater_than(resp0['masternodes'][0]['mintedblocks'], 0)

# getmininginfo() on node[1], should return two master nodes in the response array
resp1 = self.nodes[1].getmininginfo()
assert_equal(len(resp1['masternodes']), 2)
assert_equal(resp1['masternodes'][0]['state'], "ENABLED")
assert_equal(resp1['masternodes'][0]['generate'], True)
assert_equal(resp1['masternodes'][0]['lastblockcreationattempt'] != "0", True)
assert_greater_than(resp1['masternodes'][0]['mintedblocks'], 0)


assert_equal(resp1['masternodes'][1]['state'], "ENABLED")
assert_equal(resp1['masternodes'][1]['generate'], True)
assert_equal(resp1['masternodes'][1]['lastblockcreationattempt'] != "0", True)
assert_greater_than(resp1['masternodes'][1]['mintedblocks'], 0)

if __name__ == '__main__':
GetMiningInfoRPCTest().main()

0 comments on commit ead30df

Please sign in to comment.