Skip to content

Commit

Permalink
Merge branch 'multisource'
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Feb 2, 2013
2 parents 4c04dca + 19c6199 commit ad642b9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
18 changes: 18 additions & 0 deletions config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ TemplateChecks = (
},
)

# JSON-RPC servers to submit found blocks to (when they meet the full target)
# The specific TemplateSource that the block was based on will always be sent
# the block first.
# If setting is not specified, or None, full TemplateSources list will be used.
# If an empty list, no extra submissions will be attempted.
# If an empty list, and the block was found on a "clear" merkle root (not based
# on any TemplateSource), the full TemplateSources list will be used.
BlockSubmissions = (
{
'name': 'primary',
'uri': 'http://user:pass@localhost:8332',
},
{
'name': 'secondary',
'uri': 'http://user:pass@localhost:18332',
}
)

# Templates will not be used unless they have an acceptance ratio above this
# Range: 0.00 - 1.00
MinimumTemplateAcceptanceRatio = 0
Expand Down
11 changes: 10 additions & 1 deletion eloipool.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,23 @@ def getExistingStratumJob(jobid):
import bitcoin.txn
from merklemaker import assembleBlock

if not hasattr(config, 'BlockSubmissions'):
config.BlockSubmissions = None

RBFs = []
def blockSubmissionThread(payload, blkhash, share):
servers = list(a for b in MM.TemplateSources for a in b)
if config.BlockSubmissions is None:
servers = list(a for b in MM.TemplateSources for a in b)
else:
servers = list(config.BlockSubmissions)

if hasattr(share['merkletree'], 'source_uri'):
servers.insert(0, {
'access': jsonrpc.ServiceProxy(share['merkletree'].source_uri),
'name': share['merkletree'].source,
})
elif not servers:
servers = list(a for b in MM.TemplateSources for a in b)

myblock = (blkhash, payload[4:36])
payload = b2a_hex(payload).decode('ascii')
Expand Down
23 changes: 19 additions & 4 deletions merklemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,25 @@ def __init__(self, *a, **k):
def _prepare(self):
self.TemplateSources = list(getattr(self, 'TemplateSources', ()))
self.TemplateChecks = list(getattr(self, 'TemplateChecks', ()))
if getattr(self, 'BlockSubmissions', None) is None:
self.BlockSubmissions = ()
if hasattr(self, 'UpstreamURI'):
self.TemplateSources.append({
'name': 'UpstreamURI',
'uri': self.UpstreamURI,
})
URI2Name = {}
Name2URI = {}
for a in (self.TemplateSources + self.TemplateChecks + list(self.BlockSubmissions)):
if not ('name' in a and 'uri' in a):
continue
URI2Name.setdefault(a['uri'], a['name'])
Name2URI.setdefault(a['name'], a['uri'])
def URINamePair(a, defname):
if 'name' not in a:
a['name'] = URI2Name.get(a['uri'], defname)
elif 'uri' not in a:
a['uri'] = Name2URI[a['name']]
_URI2Access = {}
def URI2Access(uri):
if uri not in _URI2Access:
Expand All @@ -99,8 +112,7 @@ def URI2Access(uri):
LeveledTS = {}
for i in range(len(self.TemplateSources)):
TS = self.TemplateSources[i]
TS.setdefault('name', 'TemplateSources[%u]' % (i,))
URI2Name[TS['uri']] = TS['name']
URINamePair(TS, 'TemplateSources[%u]' % (i,))
TS.setdefault('priority', 0)
TS.setdefault('weight', 1)
TS['access'] = URI2Access(TS['uri'])
Expand All @@ -109,11 +121,14 @@ def URI2Access(uri):
self.TemplateSources = LeveledTS
for i in range(len(self.TemplateChecks)):
TC = self.TemplateChecks[i]
if 'name' not in TC:
TC['name'] = URI2Name.get(TC['uri'], 'TemplateChecks[%u]' % (i,))
URINamePair(TC, 'TemplateChecks[%u]' % (i,))
TC.setdefault('unanimous', False)
TC.setdefault('weight', 1)
TC['access'] = URI2Access(TC['uri'])
for i in range(len(getattr(self, 'BlockSubmissions', ()))):
BS = self.BlockSubmissions[i]
URINamePair(BS, 'BlockSubmissions[%u]' % (i,))
BS['access'] = URI2Access(BS['uri'])

self.ready = False
self.readyCV = threading.Condition()
Expand Down

0 comments on commit ad642b9

Please sign in to comment.