Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
a055f5de
Commit
a055f5de
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fix crash when nodes are mining for the wrong currency
parent
06d5e365
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cutecoin/core/net/api/bma/access.py
+17
-7
17 additions, 7 deletions
src/cutecoin/core/net/api/bma/access.py
src/cutecoin/core/net/network.py
+8
-4
8 additions, 4 deletions
src/cutecoin/core/net/network.py
with
25 additions
and
11 deletions
src/cutecoin/core/net/api/bma/access.py
+
17
−
7
View file @
a055f5de
from
PyQt5.QtCore
import
QObject
,
pyqtSlot
from
PyQt5.QtCore
import
QObject
,
pyqtSlot
from
PyQt5.QtNetwork
import
QNetworkReply
from
PyQt5.QtNetwork
import
QNetworkReply
from
ucoinpy.api
.bma
import
b
lockchain
from
ucoinpy.api
import
b
ma
from
ucoinpy.documents
import
Block
,
BlockId
from
ucoinpy.documents
import
Block
,
BlockId
from
.....tools.exceptions
import
NoPeerAvailable
from
.....tools.exceptions
import
NoPeerAvailable
from
.....
import
__version__
from
.....
import
__version__
...
@@ -15,7 +15,7 @@ class BmaAccess(QObject):
...
@@ -15,7 +15,7 @@ class BmaAccess(QObject):
This class is used to access BMA API.
This class is used to access BMA API.
"""
"""
__saved_requests
=
[
str
(
blockchain
.
Block
),
str
(
blockchain
.
Parameters
)]
__saved_requests
=
[
str
(
bma
.
blockchain
.
Block
),
str
(
bma
.
blockchain
.
Parameters
)]
def
__init__
(
self
,
data
,
network
):
def
__init__
(
self
,
data
,
network
):
"""
"""
...
@@ -112,10 +112,10 @@ class BmaAccess(QObject):
...
@@ -112,10 +112,10 @@ class BmaAccess(QObject):
# If we detected a rollback
# If we detected a rollback
# We reload if we don't know if this block changed or not
# We reload if we don't know if this block changed or not
if
self
.
_rollback_to
:
if
self
.
_rollback_to
:
if
request
is
blockchain
.
Block
:
if
request
is
bma
.
blockchain
.
Block
:
if
get_args
[
"
number
"
]
>=
self
.
_rollback_to
:
if
get_args
[
"
number
"
]
>=
self
.
_rollback_to
:
need_reload
=
True
need_reload
=
True
if
request
is
blockchain
.
Parameters
and
self
.
_rollback_to
==
0
:
if
request
is
bma
.
blockchain
.
Parameters
and
self
.
_rollback_to
==
0
:
need_reload
=
True
need_reload
=
True
elif
str
(
request
)
in
BmaAccess
.
__saved_requests
\
elif
str
(
request
)
in
BmaAccess
.
__saved_requests
\
or
cached_data
[
'
metadata
'
][
'
block_hash
'
]
==
self
.
_network
.
current_blockid
.
sha_hash
:
or
cached_data
[
'
metadata
'
][
'
block_hash
'
]
==
self
.
_network
.
current_blockid
.
sha_hash
:
...
@@ -134,7 +134,7 @@ class BmaAccess(QObject):
...
@@ -134,7 +134,7 @@ class BmaAccess(QObject):
:param dict get_args: Arguments to pass to the request __get__ method
:param dict get_args: Arguments to pass to the request __get__ method
:param dict data: Json data got from the blockchain
:param dict data: Json data got from the blockchain
"""
"""
if
self
.
_rollback_to
and
request
is
blockchain
.
Block
:
if
self
.
_rollback_to
and
request
is
bma
.
blockchain
.
Block
:
if
get_args
[
'
number
'
]
>=
self
.
_rollback_to
:
if
get_args
[
'
number
'
]
>=
self
.
_rollback_to
:
cache_key
=
BmaAccess
.
_gen_cache_key
(
request
,
req_args
,
get_args
)
cache_key
=
BmaAccess
.
_gen_cache_key
(
request
,
req_args
,
get_args
)
if
cache_key
in
self
.
_data
and
self
.
_data
[
cache_key
][
'
value
'
][
'
hash
'
]
==
data
[
'
hash
'
]:
if
cache_key
in
self
.
_data
and
self
.
_data
[
cache_key
][
'
value
'
][
'
hash
'
]
==
data
[
'
hash
'
]:
...
@@ -171,6 +171,16 @@ class BmaAccess(QObject):
...
@@ -171,6 +171,16 @@ class BmaAccess(QObject):
"""
"""
self
.
_rollback_to
=
0
self
.
_rollback_to
=
0
def
filter_nodes
(
self
,
request
,
nodes
):
filters
=
{
bma
.
ud
.
History
:
lambda
n
:
int
(
n
.
version
.
split
(
"
.
"
)[
1
])
>
11
,
bma
.
tx
.
History
:
lambda
n
:
int
(
n
.
version
.
split
(
"
.
"
)[
1
])
>
11
}
if
request
in
filters
:
return
[
n
for
n
in
nodes
if
filters
[
request
](
n
)]
else
:
return
nodes
@asyncio.coroutine
@asyncio.coroutine
def
future_request
(
self
,
request
,
req_args
=
{},
get_args
=
{}):
def
future_request
(
self
,
request
,
req_args
=
{},
get_args
=
{}):
"""
"""
...
@@ -186,7 +196,7 @@ class BmaAccess(QObject):
...
@@ -186,7 +196,7 @@ class BmaAccess(QObject):
need_reload
=
data
[
0
]
need_reload
=
data
[
0
]
json_data
=
data
[
1
]
json_data
=
data
[
1
]
nodes
=
self
.
_network
.
synced_nodes
nodes
=
self
.
filter_nodes
(
request
,
self
.
_network
.
synced_nodes
)
if
need_reload
and
len
(
nodes
)
>
0
:
if
need_reload
and
len
(
nodes
)
>
0
:
tries
=
0
tries
=
0
while
tries
<
3
:
while
tries
<
3
:
...
@@ -219,7 +229,7 @@ class BmaAccess(QObject):
...
@@ -219,7 +229,7 @@ class BmaAccess(QObject):
:param dict get_args: Arguments to pass to the request __get__ method
:param dict get_args: Arguments to pass to the request __get__ method
:return: The returned data if cached = True else return the QNetworkReply
:return: The returned data if cached = True else return the QNetworkReply
"""
"""
nodes
=
self
.
_network
.
synced_nodes
nodes
=
self
.
filter_nodes
(
request
,
self
.
_network
.
synced_nodes
)
if
len
(
nodes
)
>
0
:
if
len
(
nodes
)
>
0
:
node
=
random
.
choice
(
nodes
)
node
=
random
.
choice
(
nodes
)
req
=
request
(
node
.
endpoint
.
conn_handler
(),
**
req_args
)
req
=
request
(
node
.
endpoint
.
conn_handler
(),
**
req_args
)
...
...
This diff is collapsed.
Click to expand it.
src/cutecoin/core/net/network.py
+
8
−
4
View file @
a055f5de
...
@@ -3,7 +3,8 @@ Created on 24 févr. 2015
...
@@ -3,7 +3,8 @@ Created on 24 févr. 2015
@author: inso
@author: inso
"""
"""
from
cutecoin.core.net.node
import
Node
from
.node
import
Node
from
...tools.exceptions
import
InvalidNodeCurrency
import
logging
import
logging
import
statistics
import
statistics
...
@@ -306,9 +307,12 @@ class Network(QObject):
...
@@ -306,9 +307,12 @@ class Network(QObject):
pubkeys
=
[
n
.
pubkey
for
n
in
self
.
nodes
]
pubkeys
=
[
n
.
pubkey
for
n
in
self
.
nodes
]
if
peer
.
pubkey
not
in
pubkeys
:
if
peer
.
pubkey
not
in
pubkeys
:
logging
.
debug
(
"
New node found : {0}
"
.
format
(
peer
.
pubkey
[:
5
]))
logging
.
debug
(
"
New node found : {0}
"
.
format
(
peer
.
pubkey
[:
5
]))
node
=
Node
.
from_peer
(
self
.
currency
,
peer
,
pubkey
)
try
:
self
.
add_node
(
node
)
node
=
Node
.
from_peer
(
self
.
currency
,
peer
,
pubkey
)
self
.
nodes_changed
.
emit
()
self
.
add_node
(
node
)
self
.
nodes_changed
.
emit
()
except
InvalidNodeCurrency
as
e
:
logging
.
debug
(
str
(
e
))
@pyqtSlot
()
@pyqtSlot
()
def
handle_change
(
self
):
def
handle_change
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment