Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lbry
lbrycrd
Commits
0830074e
Commit
0830074e
authored
Oct 24, 2018
by
Brannon King
Browse files
fixed issue with invalid usage of trie's root node in cache
parent
bed577d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/claimtrie.cpp
View file @
0830074e
...
...
@@ -1229,11 +1229,8 @@ uint256 CClaimTrieCache::getMerkleHash() const
}
if
(
dirty
())
{
nodeCacheType
::
iterator
cachedNode
=
cache
.
find
(
""
);
if
(
cachedNode
!=
cache
.
end
())
recursiveComputeMerkleHash
(
cachedNode
->
second
,
""
);
else
recursiveComputeMerkleHash
(
&
(
base
->
root
),
""
);
CClaimTrieNode
*
root
=
getRoot
();
recursiveComputeMerkleHash
(
root
,
""
);
}
hashMapType
::
iterator
ithash
=
cacheHashes
.
find
(
""
);
if
(
ithash
!=
cacheHashes
.
end
())
...
...
@@ -1285,11 +1282,8 @@ bool CClaimTrieCache::getOriginalInfoForName(const std::string& name, CClaimValu
bool
CClaimTrieCache
::
insertClaimIntoTrie
(
const
std
::
string
&
name
,
CClaimValue
claim
,
bool
fCheckTakeover
)
const
{
assert
(
base
);
CClaimTrieNode
*
currentNode
=
&
(
base
->
r
oot
);
CClaimTrieNode
*
currentNode
=
getR
oot
(
);
nodeCacheType
::
iterator
cachedNode
;
cachedNode
=
cache
.
find
(
""
);
if
(
cachedNode
!=
cache
.
end
())
currentNode
=
cachedNode
->
second
;
for
(
std
::
string
::
const_iterator
itCur
=
name
.
begin
();
itCur
!=
name
.
end
();
++
itCur
)
{
std
::
string
sCurrentSubstring
(
name
.
begin
(),
itCur
);
...
...
@@ -1374,11 +1368,8 @@ bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue c
bool
CClaimTrieCache
::
removeClaimFromTrie
(
const
std
::
string
&
name
,
const
COutPoint
&
outPoint
,
CClaimValue
&
claim
,
bool
fCheckTakeover
)
const
{
assert
(
base
);
CClaimTrieNode
*
currentNode
=
&
(
base
->
r
oot
);
CClaimTrieNode
*
currentNode
=
getR
oot
(
);
nodeCacheType
::
iterator
cachedNode
;
cachedNode
=
cache
.
find
(
""
);
if
(
cachedNode
!=
cache
.
end
())
currentNode
=
cachedNode
->
second
;
assert
(
currentNode
!=
NULL
);
// If there is no root in either the trie or the cache, how can there be any names to remove?
for
(
std
::
string
::
const_iterator
itCur
=
name
.
begin
();
itCur
!=
name
.
end
();
++
itCur
)
{
...
...
@@ -1448,10 +1439,7 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoi
if
(
fCheckTakeover
)
namesToCheckForTakeover
.
insert
(
name
);
}
CClaimTrieNode
*
rootNode
=
&
(
base
->
root
);
cachedNode
=
cache
.
find
(
""
);
if
(
cachedNode
!=
cache
.
end
())
rootNode
=
cachedNode
->
second
;
CClaimTrieNode
*
rootNode
=
getRoot
();
return
recursivePruneName
(
rootNode
,
0
,
name
);
}
...
...
@@ -1752,12 +1740,7 @@ bool CClaimTrieCache::reorderTrieNode(const std::string& name, bool fCheckTakeov
cachedNode
=
cache
.
find
(
name
);
if
(
cachedNode
==
cache
.
end
())
{
CClaimTrieNode
*
currentNode
;
cachedNode
=
cache
.
find
(
""
);
if
(
cachedNode
==
cache
.
end
())
currentNode
=
&
(
base
->
root
);
else
currentNode
=
cachedNode
->
second
;
CClaimTrieNode
*
currentNode
=
getRoot
();
for
(
std
::
string
::
const_iterator
itCur
=
name
.
begin
();
itCur
!=
name
.
end
();
++
itCur
)
{
std
::
string
sCurrentSubstring
(
name
.
begin
(),
itCur
);
...
...
@@ -2575,7 +2558,7 @@ void CClaimTrieCache::recursiveFlattenTrie(const std::string& name, const CClaim
std
::
vector
<
namedNodeType
>
CClaimTrieCache
::
flattenTrie
()
const
{
std
::
vector
<
namedNodeType
>
nodes
;
recursiveFlattenTrie
(
""
,
&
(
base
->
r
oot
),
nodes
);
recursiveFlattenTrie
(
""
,
getR
oot
(
),
nodes
);
return
nodes
;
}
...
...
@@ -2652,7 +2635,7 @@ bool CClaimTrieCache::getInfoForName(const std::string& name, CClaimValue& claim
if
(
dirty
())
getMerkleHash
();
CClaimTrieNode
*
current
=
&
(
base
->
r
oot
);
CClaimTrieNode
*
current
=
getR
oot
(
);
nodeCacheType
::
const_iterator
cachedNode
;
for
(
std
::
string
::
const_iterator
itName
=
name
.
begin
();
current
;
++
itName
)
{
...
...
@@ -2678,7 +2661,7 @@ bool CClaimTrieCache::getProofForName(const std::string& name, CClaimTrieProof&
getMerkleHash
();
std
::
vector
<
CClaimTrieProofNode
>
nodes
;
CClaimTrieNode
*
current
=
&
(
base
->
r
oot
);
CClaimTrieNode
*
current
=
getR
oot
(
);
nodeCacheType
::
const_iterator
cachedNode
;
bool
fNameHasValue
=
false
;
COutPoint
outPoint
;
...
...
src/claimtrie.h
View file @
0830074e
...
...
@@ -476,6 +476,12 @@ public:
bool
flush
();
bool
dirty
()
const
{
return
!
dirtyHashes
.
empty
();
}
CClaimTrieNode
*
getRoot
()
const
{
nodeCacheType
::
iterator
iter
=
cache
.
find
(
""
);
return
iter
==
cache
.
end
()
?
&
(
base
->
root
)
:
iter
->
second
;
}
bool
addClaim
(
const
std
::
string
&
name
,
const
COutPoint
&
outPoint
,
uint160
claimId
,
CAmount
nAmount
,
int
nHeight
)
const
;
bool
undoAddClaim
(
const
std
::
string
&
name
,
const
COutPoint
&
outPoint
,
...
...
src/rpc/claimtrie.cpp
View file @
0830074e
...
...
@@ -36,7 +36,7 @@ static CBlockIndex* BlockHashIndex(const uint256& blockHash)
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Block not in main chain"
);
if
(
chainActive
.
Tip
()
->
nHeight
>
(
pblockIndex
->
nHeight
+
MAX_RPC_BLOCK_DECREMENTS
))
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Block too deep
to regenerate it
"
);
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Block
is
too deep"
);
return
pblockIndex
;
}
...
...
src/test/claimtriebranching_tests.cpp
View file @
0830074e
...
...
@@ -3165,6 +3165,32 @@ BOOST_AUTO_TEST_CASE(getclaimsintrie_test)
BOOST_CHECK
(
results
[
0
][
"name"
].
get_str
()
==
sName1
);
}
BOOST_AUTO_TEST_CASE
(
getclaimsintrie_test2
)
{
ClaimTrieChainFixture
fixture
;
std
::
string
sName1
(
"test"
);
std
::
string
sValue1
(
"test"
);
uint256
blockHash
=
chainActive
.
Tip
()
->
GetBlockHash
();
rpcfn_type
getclaimsintrie
=
tableRPC
[
"getclaimsintrie"
]
->
actor
;
rpcfn_type
getclaimtrie
=
tableRPC
[
"getclaimtrie"
]
->
actor
;
UniValue
params
(
UniValue
::
VARR
);
params
.
push_back
(
blockHash
.
GetHex
());
UniValue
results
=
getclaimsintrie
(
params
,
false
);
BOOST_CHECK
(
results
.
size
()
==
0U
);
results
=
getclaimtrie
(
params
,
false
);
BOOST_CHECK
(
results
.
size
()
==
1U
);
fixture
.
IncrementBlocks
(
10
);
fixture
.
MakeClaim
(
fixture
.
GetCoinbase
(),
sName1
,
sValue1
,
42
);
fixture
.
IncrementBlocks
(
10
);
results
=
getclaimsintrie
(
params
,
false
);
BOOST_CHECK
(
results
.
size
()
==
0U
);
results
=
getclaimtrie
(
params
,
false
);
BOOST_CHECK
(
results
.
size
()
==
1U
);
}
BOOST_AUTO_TEST_CASE
(
getclaimtrie_test
)
{
ClaimTrieChainFixture
fixture
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment