Skip to content

Commit

Permalink
Fix #102 - Use different protocol version number for testnet
Browse files Browse the repository at this point in the history
In order to keep testnet shufflers from interfering with mainnet,
testnet shufflers get PROTOCOL_VERSION + 1 (currently would be 201)

Thanks to Josh Ellithorpe for remind me to do this. :)
  • Loading branch information
cculianu committed Mar 14, 2019
1 parent 6ee11d3 commit e1edfa5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 17 additions & 5 deletions plugins/shuffle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from electroncash.address import Address
from electroncash.util import PrintError, InvalidPassword
from electroncash.network import Network
from electroncash import networks
from electroncash.wallet import dust_threshold
from electroncash.simple_config import get_config

Expand Down Expand Up @@ -253,9 +254,21 @@ class BackgroundShufflingThread(threading.Thread, PrintErrorThread):
10000, # 0.0001 BCH →
)

# Protocol version. Must be an int. Clients on different versions
# never get assigned to the same pools and are completely segregated.
# Version=0 : Very old clients used this version (pre release beta)
# Version=100: Was for the new fee-270 (fee was 300 before this version).
# Version=200: Is for the new "shuffle amount gets raised to match lowest
# UTXO in shuffle" rules.
# Note that testnet instances should specify PROTOCOL_VERSION + 1 to keep
# keep themselves separated from mainnet shufflers.
# (In the future this version specifier may be a more dynamic quantity but
# for now it's always this value, or this value + 1 for testnet).
PROTOCOL_VERSION = 200
# Fee formula should be roughly 270 for first input + 200 for each additional
# input. Right now we support only 1 input per shuffler, so it's a static 270.
FEE = 270
# The below defaults control coin selection and which pools (scales) we use
PROTOCOL_VERSION = 200 # protocol version. old clients use 0. Must be an int. Version=100 is for the new fee-270. Version=200 is for new dynamic amounts. In the future this may be a dynamic quantity but for now it's always this value.
FEE = 270 # Fee formula should be roughly 270 for first input + 200 for each additional input. Right now we support only 1 input per shuffler.
SORTED_SCALES = sorted(scales)
SCALE_ARROWS = ('→','⇢','➟','➝','➡','➡','➡','➡') # if you add a scale above, add an arrow here, in reverse order from above
SCALE_ARROW_UNKNOWN = '⇒' # What the app uses when a scale it sees isn't on the list.
Expand All @@ -280,17 +293,16 @@ class BackgroundShufflingThread(threading.Thread, PrintErrorThread):
latest_shuffle_settings = ShuffleSettings(Messages.DEFAULT, Messages.TYPE_NAME_DICT[Messages.DEFAULT], PROTOCOL_VERSION, 0, 0, FEE)

def __init__(self, window, wallet, network_settings,
version=PROTOCOL_VERSION,
period = 10.0, logger = None, password=None, timeout=60.0,
typ=Messages.DEFAULT # NB: Only DEFAULT is currently supported
):
super().__init__()
cls = type(self)
self.daemon = True
self.timeout = timeout
self.version = version
self.version = cls.PROTOCOL_VERSION + (1 if networks.net.TESTNET else 0)
self.type = typ
assert self.type == Messages.DEFAULT, "BackgroundShufflingThread currently only supports DEFAULT shuffles"
cls = type(self)
cls.latest_shuffle_settings = cls.ShuffleSettings(self.type, Messages.TYPE_NAME_DICT[self.type], self.version, 0, 0, self.FEE)
# set UPPER_BOUND and LOWER_BOUND from config keys here. Note all instances will see these changes immediately.
cls.update_lower_and_upper_bound_from_config()
Expand Down
1 change: 0 additions & 1 deletion plugins/shuffle/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def start_background_shuffling(window, network_settings, period = 10.0, password
window.background_process = BackgroundShufflingThread(window,
window.wallet,
network_settings,
# version = whatever,
logger = logger,
period = period,
password = password,
Expand Down

0 comments on commit e1edfa5

Please sign in to comment.