Skip to content

Commit

Permalink
Prevent automatic replay protection from activating.
Browse files Browse the repository at this point in the history
Only apply to alpha release!

This is a quick fix because we've run out of time. This must be
implemented properly in the future.
  • Loading branch information
Danconnolly committed Aug 29, 2018
1 parent 41b7c11 commit 55c9938
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ bool IsMagneticEnabled(const Config &config, const CBlockIndex *pindexPrev) {

static bool IsReplayProtectionEnabled(const Config &config,
int64_t nMedianTimePast) {
return nMedianTimePast >= gArgs.GetArg("-replayprotectionactivationtime",
config.GetChainParams()
.GetConsensus()
.magneticAnomalyActivationTime);
// this is a quick fix to disable this capability, it ensures that
// replay protection will not be enabled
// TODO: remove replay protection properly
return false;
}

static bool IsReplayProtectionEnabled(const Config &config,
Expand Down
37 changes: 17 additions & 20 deletions test/functional/abc-replay-protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,51 +230,48 @@ def send_transaction_to_mempool(tx):
send_transaction_to_mempool(txns[0])
tx_id = send_transaction_to_mempool(txns[1])

# Activate the replay protection
# Activate the replay protection - it shoudn't take effect
block(5556)
yield accepted()

# Non replay protected transactions are not valid anymore,
# so they should be removed from the mempool.
assert(tx_id not in set(node.getrawmempool()))
# Non replay protected transactions should still be valid,
# they should be in the mempool.
assert(tx_id in set(node.getrawmempool()))

# Good old transactions are now invalid.
# Good old transactions are still valid.
send_transaction_to_mempool(txns[0])
assert_raises_rpc_error(-26, RPC_INVALID_SIGNATURE_ERROR,
node.sendrawtransaction, ToHex(txns[1]))
normal_txid = node.sendrawtransaction(ToHex(txns[1]))

# They also cannot be mined
# They can be mined
block(4)
update_block(4, txns)
yield rejected(RejectResult(16, b'blk-bad-inputs'))

# Rewind bad block
tip(5556)
yield accepted()

# The replay protected transaction is now valid
# The replay protected transaction are still invalid
send_transaction_to_mempool(replay_txns[0])
replay_tx_id = send_transaction_to_mempool(replay_txns[1])
assert_raises_rpc_error(-26, RPC_INVALID_SIGNATURE_ERROR,
node.sendrawtransaction, ToHex(replay_txns[1]))

# They also can also be mined
# They can't be mined
b5 = block(5)
update_block(5, replay_txns)
yield accepted()
yield rejected(RejectResult(16, b'blk-bad-inputs'))

# Ok, now we check if a reorg work properly accross the activation.
# Ok, now we check That a reorg work doesnt affect anything.
postforkblockid = node.getbestblockhash()
node.invalidateblock(postforkblockid)
assert(replay_tx_id in set(node.getrawmempool()))
assert(normal_txid in set(node.getrawmempool()))

# Deactivating replay protection.
forkblockid = node.getbestblockhash()
node.invalidateblock(forkblockid)
assert(replay_tx_id not in set(node.getrawmempool()))
assert(normal_txid in set(node.getrawmempool()))

# Check that we also do it properly on deeper reorg.
node.reconsiderblock(forkblockid)
node.reconsiderblock(postforkblockid)
node.invalidateblock(forkblockid)
assert(replay_tx_id not in set(node.getrawmempool()))
assert(normal_txid in set(node.getrawmempool()))


if __name__ == '__main__':
Expand Down

0 comments on commit 55c9938

Please sign in to comment.