Skip to content

Commit

Permalink
NodeList class added for better nodelist handling
Browse files Browse the repository at this point in the history
NodeList
* replaces get_node_list from utils.py
* is a list and contains all nodes as dict
* get_nodes() returns the url in a list
Utils
* get_node_list removed
Unit Tests and Examples adapted to the changes
  • Loading branch information
holgern committed May 25, 2018
1 parent f3f74a9 commit 223ac87
Show file tree
Hide file tree
Showing 35 changed files with 504 additions and 168 deletions.
3 changes: 2 additions & 1 deletion beem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"comment",
"discussions",
"witness",
"profile"
"profile",
"nodelist"
]
2 changes: 1 addition & 1 deletion beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def cli(node, offline, no_broadcast, no_wallet, unsigned, expires, verbose):
debug=debug,
num_retries=10,
num_retries_call=3,
timeout=10,
timeout=15,
autoconnect=False
)
set_shared_steem_instance(stm)
Expand Down
6 changes: 0 additions & 6 deletions beem/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@ class VestingBalanceDoesNotExistsException(Exception):
pass


class ObjectNotInProposalBuffer(Exception):
""" Object was not found in proposal
"""
pass


class InvalidMessageSignature(Exception):
""" The message signature does not fit the message
"""
Expand Down
247 changes: 247 additions & 0 deletions beem/nodelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
# This Python file uses the following encoding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import next
import re
import time
import math


class NodeList(list):
def __init__(self):
nodes = [
{
"url": "https://api.steemit.com",
"version": "0.19.4",
"type": "appbase",
"owner": "steemit",
"score": 100
},
{
"url": "wss://appbasetest.timcliff.com",
"version": "0.19.4",
"type": "appbase",
"owner": "timcliff",
"score": 20
},
{
"url": "https://appbasetest.timcliff.com",
"version": "0.19.4",
"type": "appbase",
"owner": "timcliff",
"score": 10
},
{
"url": "https://api.steem.house",
"version": "0.19.4",
"type": "appbase",
"owner": "gtg",
"score": 90
},
{
"url": "https://api.steemitdev.com",
"version": "0.19.4",
"type": "appbase-dev",
"owner": "steemit",
"score": 100
},
{
"url": "https://api.steemitstage.com",
"version": "0.19.4",
"type": "appbase-dev",
"owner": "steemit",
"score": 110
},
{
"url": "wss://rpc.steemviz.com",
"version": "0.19.3",
"type": "normal",
"owner": "ausbitbank",
"score": 175
},
{
"url": "https://rpc.steemviz.com",
"version": "0.19.3",
"type": "normal",
"owner": "ausbitbank",
"score": 80
},
{
"url": "wss://steemd.privex.io",
"version": "0.19.3",
"type": "normal",
"owner": "privex",
"score": 90
},
{
"url": "https://steemd.privex.io",
"version": "0.19.3",
"type": "normal",
"owner": "privex",
"score": 50
},
{
"url": "wss://rpc.buildteam.io",
"version": "0.19.3",
"type": "normal",
"owner": "themarkymark",
"score": 165
},
{
"url": "https://rpc.buildteam.io",
"version": "0.19.3",
"type": "normal",
"owner": "themarkymark",
"score": 120
},
{
"url": "wss://gtg.steem.house:8090",
"version": "0.19.3",
"type": "normal",
"owner": "gtg",
"score": 75
},
{
"url": "https://gtg.steem.house:8090",
"version": "0.19.3",
"type": "normal",
"owner": "gtg",
"score": 80
},
{
"url": "wss://steemd.pevo.science",
"version": "0.19.3",
"type": "normal",
"owner": "pharesim",
"score": 170
},
{
"url": "https://steemd.pevo.science",
"version": "0.19.3",
"type": "normal",
"owner": "pharesim",
"score": 30
},
{
"url": "wss://rpc.steemliberator.com",
"version": "0.19.3",
"type": "normal",
"owner": "netuoso",
"score": 20
},
{
"url": "https://rpc.steemliberator.com",
"version": "0.19.3",
"type": "normal",
"owner": "netuoso",
"score": 10
},
{
"url": "wss://seed.bitcoiner.me",
"version": "0.19.3",
"type": "normal",
"owner": "bitcoiner",
"score": 1
},
{
"url": "https://seed.bitcoiner.me",
"version": "0.19.3",
"type": "normal",
"owner": "bitcoiner",
"score": 1
},
{
"url": "wss://steemd.steemgigs.org",
"version": "0.19.3",
"type": "normal",
"owner": "steemgigs",
"score": 10
},
{
"url": "https://steemd.steemgigs.org",
"version": "0.19.3",
"type": "normal",
"owner": "steemgigs",
"score": 10
},
{
"url": "wss://steemd.minnowsupportproject.org",
"version": "0.19.3",
"type": "normal",
"owner": "followbtcnews",
"score": 10
},
{
"url": "https://steemd.minnowsupportproject.org",
"version": "0.19.3",
"type": "normal",
"owner": "followbtcnews",
"score": 10
},
{
"url": "https://rpc.curiesteem.com",
"version": "0.19.3",
"type": "normal",
"owner": "curie",
"score": 50
},
{
"url": "wss://testnet.steem.vc",
"version": "0.19.2",
"type": "testnet",
"owner": "almost-digital",
"score": 1
},
{
"url": "ws://testnet.steem.vc",
"version": "0.19.2",
"type": "testnet",
"owner": "almost-digital",
"score": 5
},
{
"url": "https://testnet.steem.vc",
"version": "0.19.2",
"type": "testnet",
"owner": "almost-digital",
"score": 1
},
{
"url": "http://testnet.steem.vc",
"version": "0.19.2",
"type": "testnet",
"owner": "almost-digital",
"score": 5
}
]
super(NodeList, self).__init__(nodes)

def get_nodes(self, normal=True, appbase=True, dev=False, testnet=False):
""" Returns nodes as list
:param bool normal: when True, nodes with version 0.19.2 or 0.19.3 are included
:param bool appbase: when True, nodes with version 0.19.4 are included
:param bool dev: when True, dev nodes with version 0.19.4 are included
:param bool testnet: when True, testnet nodes are included
"""
node_list = []
node_type_list = []
if normal:
node_type_list.append("normal")
if appbase:
node_type_list.append("appbase")
if dev:
node_type_list.append("appbase-dev")
if testnet:
node_type_list.append("testnet")
for node in self:
if node["type"] in node_type_list:
node_list.append(node)
return [node["url"] for node in sorted(node_list, key=lambda self: self['score'], reverse=True)]

def get_testnet(self):
"""Returns testnet nodes"""
return self.get_nodes(normal=False, appbase=False, testnet=True)
5 changes: 3 additions & 2 deletions beem/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import random
import hashlib
from .exceptions import WrongMasterPasswordException, NoWriteAccess
from .utils import get_node_list
from .nodelist import NodeList
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler())
Expand Down Expand Up @@ -273,7 +273,8 @@ class Configuration(DataDir):
__tablename__ = "config"

#: Default configuration
nodes = get_node_list(appbase=False) + get_node_list(appbase=True)
nodelist = NodeList()
nodes = nodelist.get_nodes(normal=True, appbase=True, dev=False, testnet=False)
config_defaults = {
"node": nodes,
"password_storage": "environment",
Expand Down
21 changes: 0 additions & 21 deletions beem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from datetime import datetime, tzinfo, timedelta
import pytz
import difflib
from .exceptions import ObjectNotInProposalBuffer

timeFormat = '%Y-%m-%dT%H:%M:%S'
# https://github.com/matiasb/python-unidiff/blob/master/unidiff/constants.py#L37
Expand Down Expand Up @@ -257,23 +256,3 @@ def make_patch(a, b, n=3):

def findall_patch_hunks(body=None):
return RE_HUNK_HEADER.findall(body)


def get_node_list(appbase=False, testing=False):
"""Returns node list"""
if appbase:
node_list = ["https://api.steemit.com", "wss://appbasetest.timcliff.com", "https://api.steem.house"]
if testing:
node_list = ["https://api.steemitdev.com", "https://api.steemitstage.com"] + node_list
return node_list
else:
return ["wss://steemd.privex.io", "wss://rpc.buildteam.io", "https://steemd.privex.io", "https://rpc.buildteam.io", "wss://steemd.pevo.science",
"wss://rpc.steemliberator.com", "wss://gtg.steem.house:8090",
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://steemd.steemgigs.org", "wss://steemd.minnowsupportproject.org",
"https://steemd.minnowsupportproject.org", "https://steemd.pevo.science", "https://rpc.steemviz.com", "https://seed.bitcoiner.me",
"https://rpc.steemliberator.com", "https://gtg.steem.house:8090",
"https://rpc.curiesteem.com", "https://steemd.steemgigs.org"]


def get_test_node_list():
return ["wss://testnet.steem.vc", "ws://testnet.steem.vc", "https://testnet.steem.vc", "http://testnet.steem.vc"]
3 changes: 3 additions & 0 deletions beemapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
"steemnoderpc",
"exceptions",
"websocket",
"rpcutils",
"graphenerpc",
"node",
]
6 changes: 4 additions & 2 deletions examples/benchmark_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from beem.account import Account
from beem.block import Block
from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta, get_node_list
from beem.utils import parse_time, formatTimedelta
from beem.nodelist import NodeList
from beemapi.exceptions import NumRetriesReached
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
Expand All @@ -24,7 +25,8 @@
max_batch_size = None
threading = False
thread_num = 16
nodes = get_node_list(appbase=False) + get_node_list(appbase=True)
nodelist = NodeList()
nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True)
t = PrettyTable(["node", "10 blockchain minutes", "10000 virtual account op", "version"])
t.align = "l"
for node in nodes:
Expand Down

0 comments on commit 223ac87

Please sign in to comment.