add better reject reason for immature peg-in, with test

This commit is contained in:
Gregory Sanders 2018-03-26 18:11:38 -04:00
parent e93a6fb502
commit 248eb9157b
2 changed files with 16 additions and 2 deletions

View file

@ -169,12 +169,22 @@ try:
addrs = sidechain.getpeginaddress()
txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24)
# 10+2 confirms required to get into mempool and confirm
bitcoin.generate(11)
bitcoin.generate(1)
time.sleep(2)
proof = bitcoin.gettxoutproof([txid1])
raw = bitcoin.getrawtransaction(txid1)
print("Attempting peg-in")
# First attempt fails the consensus check but gives useful result
try:
pegtxid = sidechain.claimpegin(raw, proof)
raise Exception("Peg-in should not mature enough yet, need another block.")
except JSONRPCException as e:
assert("Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"])
pass
# Second attempt simply doesn't hit mempool bar
bitcoin.generate(10)
try:
pegtxid = sidechain.claimpegin(raw, proof)
raise Exception("Peg-in should not mature enough yet, need another block.")

View file

@ -3660,7 +3660,11 @@ UniValue createrawpegin(const JSONRPCRequest& request)
stack.push_back(txData);
stack.push_back(txOutProofData);
if (!IsValidPeginWitness(pegin_witness, mtx.vin[0].prevout)) {
// Peg-in witness isn't valid, even though the block header is(without depth check)
// We re-check depth before returning with more descriptive result
if (GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN) &&
!IsConfirmedBitcoinBlock(merkleBlock.header.GetHash(), 0) &&
!IsValidPeginWitness(pegin_witness, mtx.vin[0].prevout)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Constructed peg-in witness is invalid.");
}