Merge pull request #244 from instagibbs/parentchaindepth

Implement hidden arg to set parent confirmation depth requirements
This commit is contained in:
Gregory Sanders 2017-08-28 18:38:28 -04:00 committed by GitHub
commit 49d58e3ade
5 changed files with 31 additions and 11 deletions

View file

@ -88,15 +88,19 @@ with open(os.path.join(sidechain2_datadir, "elements.conf"), 'w') as f:
try:
# Default is 8, meaning 8+2 confirms for mempool acceptance normally
# this will require 10+2.
sidechain_args = " -peginconfirmationdepth=10 "
# Start daemons
print("Starting daemons at "+bitcoin_datadir+", "+sidechain_datadir+" and "+sidechain2_datadir)
bitcoindstart = sys.argv[1]+"/bitcoind -datadir="+bitcoin_datadir
subprocess.Popen(bitcoindstart.split(), stdout=subprocess.PIPE)
sidechainstart = sys.argv[2]+"/elementsd -datadir="+sidechain_datadir
sidechainstart = sys.argv[2]+"/elementsd -datadir="+sidechain_datadir + sidechain_args
subprocess.Popen(sidechainstart.split(), stdout=subprocess.PIPE)
sidechain2start = sys.argv[2]+"/elementsd -datadir="+sidechain2_datadir
sidechain2start = sys.argv[2]+"/elementsd -datadir="+sidechain2_datadir + sidechain_args
subprocess.Popen(sidechain2start.split(), stdout=subprocess.PIPE)
print("Daemons started")
@ -122,19 +126,31 @@ try:
addrs = sidechain.getpeginaddress()
txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24)
txid2 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24)
bitcoin.generate(10)
# 10+2 confirms required to get into mempool and confirm
bitcoin.generate(11)
time.sleep(2)
proof = bitcoin.gettxoutproof([txid1])
raw = bitcoin.getrawtransaction(txid1)
print("Attempting peg-in")
try:
pegtxid = sidechain.claimpegin(raw, proof)
raise Exception("Peg-in should not mature enough yet, need another block.")
except JSONRPCException as e:
assert("Withdraw proof validation failed" in e.error["message"])
pass
# Should fail due to non-matching address
# Should fail due to non-matching wallet address
try:
pegtxid = sidechain.claimpegin(raw, proof, sidechain.getnewaddress())
raise Exception("Peg-in with non-matching address should fail.")
except JSONRPCException:
except JSONRPCException as e:
assert("Failed to find output in bitcoinTx to the mainchain_address" in e.error["message"])
pass
# 12 confirms allows in mempool
bitcoin.generate(1)
timeout = 20
# Both should succeed via wallet lookup for address match, and when given
pegtxid1 = sidechain.claimpegin(raw, proof)
@ -179,7 +195,7 @@ try:
for i in range(n_claims):
addrs = sidechain.getpeginaddress()
txid = bitcoin.sendtoaddress(addrs["mainchain_address"], 1)
bitcoin.generate(10)
bitcoin.generate(12)
proof = bitcoin.gettxoutproof([txid])
raw = bitcoin.getrawtransaction(txid)
pegtxs += [sidechain.claimpegin(raw, proof)]

View file

@ -513,6 +513,7 @@ std::string HelpMessage(HelpMessageMode mode)
if (showDebug) {
strUsage += HelpMessageOpt("-fedpegscript=<hex>", _("Change federated peg to use a different script.") +
" " + _("This creates a new chain with a different genesis block."));
strUsage += HelpMessageOpt("-peginconfirmationdepth", strprintf(_("Pegin claims must be this deep to be considered valid. (default: %d)"), DEFAULT_PEGIN_CONFIRMATION_DEPTH));
}
strUsage += HelpMessageOpt("-validatepegin", strprintf(_("Validate pegin claims. All functionaries must run this. (default: %u)"), DEFAULT_VALIDATE_PEGIN));

View file

@ -1580,7 +1580,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_OUTPUT_SCRIPT);
#ifndef BITCOIN_SCRIPT_NO_CALLRPC
if (GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN) && !checker.IsConfirmedBitcoinBlock(genesishash, merkleBlock.header.GetHash(), flags & SCRIPT_VERIFY_INCREASE_CONFIRMATIONS_REQUIRED))
if (GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN) && !checker.IsConfirmedBitcoinBlock(genesishash, merkleBlock.header.GetHash(), flags & SCRIPT_VERIFY_INCREASE_CONFIRMATIONS_REQUIRED, GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH)))
return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_BLOCKCONFIRMED);
#endif
} catch (std::exception& e) {
@ -1975,10 +1975,10 @@ CConfidentialValue TransactionSignatureChecker::GetValueInPrevIn() const
return amountPreviousInput;
}
bool TransactionSignatureChecker::IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements) const
bool TransactionSignatureChecker::IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const
{
#ifndef BITCOIN_SCRIPT_NO_CALLRPC
return ::IsConfirmedBitcoinBlock(genesishash, hash, fConservativeConfirmationRequirements ? 10 : 8);
return ::IsConfirmedBitcoinBlock(genesishash, hash, nConfirmationsRequired + (fConservativeConfirmationRequirements ? 2 : 0));
#else
return true;
#endif

View file

@ -171,7 +171,7 @@ public:
return -1;
}
virtual bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements) const
virtual bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const
{
return false;
}
@ -219,7 +219,7 @@ public:
COutPoint GetPrevOut() const;
CConfidentialValue GetValueIn() const;
CConfidentialValue GetValueInPrevIn() const;
bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements) const;
bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const;
virtual CScript GetFedpegScript() const
{
return fedpegScript;

View file

@ -31,6 +31,9 @@ static const int MAX_PUBKEYS_PER_MULTISIG = 20;
// mainchain.
static const bool DEFAULT_VALIDATE_PEGIN = false;
// Number of confirms on parent chain required to confirm on sidechain
static const unsigned int DEFAULT_PEGIN_CONFIRMATION_DEPTH = 8;
// Maximum script length in bytes
static const int MAX_SCRIPT_SIZE = 10000;
class uint256;